' Casio Remote Control Receiver ' http://www.scss.com.au/family/andrew/camera/remote/ ' by Andrew Gregory (andrew@scss.com.au) ' v1.0.0 27 May 2001 Initial version ' v1.0.1 28 May 2001 Fixed so the preview button can be held down ' v1.1.0 4 Jun 2001 Modified to use valid data output of decoder chip ' ' NOTE: Designed using an LED display with two decimal points. Most ' displays have a single decimal point - if that's the case for you ' then you will have to use a separate (extra) LED. ' ' Pin Usage: ' ' P0 : LED segment a a ' P1 : LED segment b f b ' P2 : LED segment c g ' P3 : LED segment d e c ' P4 : LED segment e dp2 d dp1 ' P5 : LED segment f ' P6 : LED segment g ' P7 : LED segment dp1 - used to indicate remote button pressed ' P8 : Button in - valid data ' P9 : TTL serial data out to camera ' P10 : not used ' P11 : LED segment dp2 - blinked to indicate receiver is 'alive' ' P12 : Button 4 in \ ' P13 : Button 3 in \__ buttons are numbered 1..4 on the key fob ' P14 : Button 1 in / starting from the one closest to the LED ' P15 : Button 2 in / '------------------------------------------------------------------ '* '* Button inputs '* buttonValid var in8 ' button data valid buttonValidPin con 8 buttonNib var ind ' button input nibble button1Bit con 2 ' bit positions in the nibble for each button button2Bit con 3 button3Bit con 1 button4Bit con 0 button1Mask con 1 << button1Bit ' bit masks for each button button2Mask con 1 << button2Bit button3Mask con 1 << button3Bit button4Mask con 1 << button4Bit '* '* LED control '* commonCathode con %00000000 commonAnode con %11111111 ledType con commonAnode ' <-- change to match the type of LED display runLedDuty con 16 ' out of 256 (6.25%) runLed var out11 buttonLed var out7 ledByte var outl ledOff con 0 ^ ledType & 1 ledOn con 1 ^ ledType & 1 ' display patterns 1gfedcba led_ con %00000000 ^ ledType led_S con %01101101 ^ ledType led_t con %01111000 ^ ledType led_P con %01110011 ^ ledType led_n con %01010100 ^ ledType led_d con %01011110 ^ ledType led_L con %00111000 ^ ledType led_F con %01110001 ^ ledType led_AllOn con %11111111 ^ ledType '* '* Serial port control '* serialOutPin con 9 serialOutMode con 84 ' 9600 baud, 8 data bits, no parity, non-inverted, both driven serialOutPace con 50 ' delay after each byte in milliseconds '* '* Command mode table '* ' Modes - All command characters are specified in uppercase, the ' program obtains the lowercase by logical-OR-ing with 32. A zero ' command means that button is ignored. Setting bit 7 of the command ' code means that the camera button will be 'held down' for so long ' as the remote button is held down. Otherwise, the camera button ' is only 'held down' briefly no matter how long the remote button ' is held down. This is to counter a 'bug' in the UHF receiver/decoder ' chip that keeps sending a 'button pressed' signal after the remote ' button has been released. ' Entry layout: ' Offset | Size | Description ' --------+------+----------------------------- ' 0 | byte | LED display ' 1 | byte | camera command for button 1 ' 2 | byte | camera command for button 2 ' 3 | byte | camera command for button 3 numberOfModes con 7 modeEntrySize con 4 ' in bytes modeData data led_S, "B" , "A" , 0 ' S - shutter,focus lock data led_t, "P" , "D" | 128, "C" | 128 ' t - timer,tele,wide data led_P, "N" , "H" , "I" ' P - mode,right,set data led_n, "E" , "J" , "I" ' n - menu,down,set data led_d, "Q" | 128, "O" , 0 ' d - preview,display data led_L, "K" , "F" , "J" ' L - flash,up,down data led_F, "L" , "G" , "H" ' F - focus,left,right modeDataEnd con numberOfModes * modeEntrySize + modeData '* '* LED display blanking '* modeBlankTimeout con 40 ' ~60sec '* '* Variables '* counter var byte ' general counter to blink 'run' LED modeBlankCountdown var byte ' mode display blanking countdown currentMode var byte ' current camera control mode buttonWork var byte ' PBASIC button workspace buttonId var buttonWork ' button number just pressed cameraCmd var buttonWork ' camera command '* '* Initialize '* ' Setup I/O pins dirs = %0000111011111111 ' Turn all the LEDs on for testing ledByte = led_AllOn runLed = ledOn pause 500 ' Initialize the mode currentMode = modeData goto modeOk '* '* Main loop '* mainLoop: gosub idle ' Handle mode display blanking if ((counter <> 0) or (modeBlankCountdown = 0)) then skipBlank modeBlankCountdown = modeBlankCountdown - 1 if (modeBlankCountdown > 0) then skipBlank ledByte = led_ ' turn off mode display skipBlank: button buttonValidPin, 1, 255, 255, buttonWork, 1, handleButton goto mainLoop '* '* Button handling '* handleButton: buttonLed = ledOn ' multiple buttons held down will look like just btn 4 buttonId = 4 lookdown buttonNib, [0, button1Mask, button2Mask, button3Mask, button4Mask], buttonId ' if mode display blanked, ignore button and redisplay mode if (modeBlankCountdown = 0) then modeOk if (buttonId <> 4) then sendCommand ' change modes currentMode = currentMode + modeEntrySize if (currentMode <> modeDataEnd) then modeOk currentMode = modeData modeOk: modeBlankCountdown = modeBlankTimeout ' reset display blanker ' display current mode read currentMode, ledByte buttonLed = ledOn gosub waitForButtonRelease goto buttonDone sendCommand: modeBlankCountdown = modeBlankTimeout ' reset display blanker ' send the command, but wait for the button to be released ' before continuing read currentMode + buttonId, cameraCmd if (cameraCmd = 0) then skipSend serout serialOutPin, serialOutMode, serialOutPace, [cameraCmd & 127] if (cameraCmd.bit7 = 0) then skipWait skipSend: gosub waitForButtonRelease skipWait: if (cameraCmd = 0) then buttonDone serout serialOutPin, serialOutMode, serialOutPace, [cameraCmd | 32 & 127] if (cameraCmd.bit7 = 1) then buttonDone gosub waitForButtonRelease buttonDone: buttonLed = ledOff buttonWork = 0 goto mainLoop '* '* Wait for button release '* waitForButtonRelease: gosub idle pause 4 ' slow this fast loop to match main loop speed if (buttonValid <> 0) then waitForButtonRelease return '* '* Idle processing '* idle: ' flash the 'running' LED to indicate we haven't 'locked up' if ((counter >= 0) and (counter < runLedDuty)) then runOn runLed = ledOff goto skipOn runOn: runLed = ledOn skipOn: counter = counter + 1 if (modeBlankCountdown <> 0) then notBlank ' Display is blanked - nap for a bit to reduce power consumption ' even further, and count a bit faster to compensate nap 0 counter = counter + 4 notBlank: return