Sounds like a cool project. The 12F683 is a really nifty part.
My wife thinks I'm a complete nerd, so she buys me all this odd stuff like RoboSapien robots and such. I got kind of bored with it after the first few minutes, and decided to have a go at controlling the thing from my PC with an 8-pin PIC.
I used the 12F683 since I hadn't played with this one yet 'note the date of the code'. Here's what I came up with. It's pretty simple stuff, but still fun. I have a VB interface if anyone's interested. You can connect the PIC to your PC serial port, and control your RoboSapien robot with it by clicking buttons on-screen.
Code:
'****************************************************************
'* Name : RoboSapien_IR.bas *
'* Author : Bruce Reynolds 11/11/2005 *
'* Notes : Serial IR controller for RoboSapien robot *
'* : Replace RoboSapien hand-held IR transmitter with *
'* : an 8-pin PIC & IR LED. Just goofin off one day. *
'****************************************************************
' Connections for a 12F683
' Pin #8 = gnd
' Pin #1 = Vcc
' GPIO.0 serial input from other controller or PC
' GPIO.1 IR LED drive ----/\/\/\---|>|----gnd (note: use a 940nm IRLED)
' 330 IR LED
' Need more range use a simple NPN or mosfet driver.
' Rest of I/O-pins available for whatever.
@ DEVICE PIC12F683, MCLR_OFF, INTRC_OSC_NOCLKOUT, WDT_OFF, BOD_ON, PWRT_ON
DEFINE OSC 4
DEFINE DEBUG_BAUD 2400
DEFINE DEBUGIN_REG GPIO
DEFINE DEBUGIN_BIT 0
DEFINE DEBUGIN_MODE 0 ' 0 = true mode (with a PC use a MAX232)
@ #DEFINE IRTX GPIO ; Define port to use for IR LED drive
@ #DEFINE PIN 1 ; Define port pin to use for IR LED
BotHdr CON 255 ' Pulse timing stuff
BotHdr2 CON 25
Bot1 CON 3400
Bot0 CON 800
BotInter CON 38
Bot CON "B" ' Used for synch byte
X VAR BYTE ' Bit index pointer
Cycles var BYTE ' Holds number of 40KHz carrier cycles
Device VAR BYTE ' Holds device select byte
KeyNum VAR BYTE ' Key pressed
OSCCON = %01100000 ' Internal 4MHz osc
ADCON0 = 0 ' A/D off
CMCON0 = 7 ' Comparators off
ANSEL = 0 ' Set all digital
WPU = 0 ' Internal pull-ups = off
OPTION_REG = %10000000 ' Pull-ups = off, GPIO.2 = I/O, prescaler to Timer1
GPIO = %00000000 ' All outputs = 0 on boot
TRISIO = %00111101 ' GPIO,0=data in, GPIO,1=IRLED out, GPIO,2,3,4,5 unused
Main:
DEBUGIN [Device,KeyNum] ' With MCS+ serial terminal program, sending B#135
IF Device = Bot THEN ' will move bot backwards. Full list of commands
GOTO SendCmd ' can be found in lower section.
ENDIF
GOTO Main
SendCmd:
Cycles = BotHdr ' 1st part of synch pulse
CALL Pulse
Cycles = BotHdr2 ' 2nd part of synch pulse
CALL Pulse
FOR X = 7 to 0 STEP - 1 ' 8-bits per button command
IF KeyNum.0[X] = 1 THEN
PAUSEUS Bot1 ' high for logic 1 bit period
ELSE
PAUSEUS Bot0 ' or low for logic 0 bit period
ENDIF
Cycles = BotInter ' Inter-bit period between data bits
Call Pulse ' During these periods the carier is on
NEXT X
GOTO Main
Pulse: ' Generate "Cycles" number of 40kHz pulses
ASM
bsf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
goto $+1 ; + 2uS = 11uS
goto $+1 ; + 2uS = 13uS
bcf IRTX,PIN ; 1uS, LED=off
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
decfsz _Cycles,f ; + 1uS = 10S
goto _Pulse ; + 2uS = 12uS
return ; Add 2uS for return to caller
ENDASM
END
' Send ASCII character B followed by key commands below to
' control your RoboSapien from a PC or another PIC.
' A simple VB example to move RoboSapien forward would be;
' Private Sub Cmd_Forward_Click()
' MSComm1.Output = "B" & Chr$(134)
' End Sub
' Upper red commands
' Right arm up = 129
' Right arm down = 132
' Right arm in = 133
' Right arm out = 130
' Left arm up = 137
' Left arm down = 140
' Left arm in = 141
' Left arm out = 138
' Tilt body right = 131
' Tilt body left = 139
' Red commands - middle & lower controller
' Walk forward = 134
' Walk backward = 135
' Turn left = 136
' Turn right = 128
' Stop = 142
' Rht sensor pgm = 146
' Master command program = 144
' Program / play = 145
' Left sensor program = 147
' Sonic sens pgm = 148
' Green commands - upper controller
' Right hand thump = 161
' Right hand pickup = 164
' Lean backward = 165
' Rht hand throw = 162
' Sleep = 163
' Listen = 171
' Left hand throw = 170
' Lean forward = 173
' Left hand pickup = 172
' Green commands - middle & lower controller
' Right turn step = 160
' Backward step = 167
' Forward step = 166
' Reset = 174
' Left turn step = 178
' Right sensor program execute = 178
' Master command program execute = 176
' Wake up = 177
' Sonic sensor program execute = 180
' Left sensor program execute = 179
' Orange commands - upper controller
' Right hand sweep = 193
' High 5 = 196
' Right hand strike = 197
' Burp = 194
' Right hand strike 2 = 195
' Left hand strike 2 = 203
' Whistle = 202
' Left hand strike = 205
' Talk back = 204
' Left hand sweep = 201
' Orange commands - middle & lower controller
' Right hand strike 3 = 192
' Oops = 199
' Left hand strike 3 = 200
' Roar = 206
' Demo 1 = 210
' All demo = 208
' Power off = 209
' Dance demo = 212
' Demo 2 = 211
Here's a pic of the VB app;

I ended up with an 8-pin PIC controlling my RCA TV, Motorolla cable box, DVD, stereo, RoboSapien 'when I could afford batteries every few minutes', etc. from my PC. Maybe my wife was right...;o}
Bookmarks