I have try to make car robot and have problem with my code need all friend to help.
Pls help to verify why did not work thank
'************************************************* ***************
'* Name : IR_car3.BAS *
'* Author : *
'* : *
'* Notice : Copyright (c) 2005 *
'* : ALL Rights Reserved *
'* Date : 10/3/2003 *
'* Version : 1.0 *
'* Notes : *
'* : *
''************************************************ ****************
@ DEVICE PIC16F84a, WDT_OFF,PWRT_ON, PROTECT_OFF
TRISA = %00011111
TRISB = %11111111
DEFINE OSC 4
IRpulse_length var word
xx var Byte
Command Var Byte
Device Var Byte
sw_l var PORTB.0
sw_r var PORTB.1
left var PORTA.0 'turn left
right var PORTA.1 'turn right
fwd var PORTA.2 'go
bkd var PORTA.3 'back
n var Byte
n = 0
'pause 150
enable INTERRUPT
START:
LOW BKD
HIGH FWD
PAUSE 150
If sw_l = 0 then
HIGH BKD
LOW FWD
PAUSE 800
LOW BKD
LOW FWD
else
iF SW_r = 0 THEN
HIGH BKD
LOW FWD
PAUSE 800
LOW BKD
LOW FWD
ENDIF
endif
'Ir decoder
PULSIN Portb.2,0,IRpulse_length(0)
IF IRpulse_length(0) = 0 THEN start
for xx =1 to 18
pulsin Portb.2,0,IRpulse_length(xx)
next xx
disable INTERRUPT
displaybits:
if IRpulse_length(1) < 100 then
Command.bit0 = 0
Else
Command.bit0 = 1
endif
if IRpulse_length(2) < 100 then
Command.bit1 = 0
Else
Command.bit1 = 1
endif
if IRpulse_length(3) < 100 then
Command.bit2 = 0
Else
Command.bit2 = 1
endif
if IRpulse_length(4) < 100 then
Command.bit3 = 0
Else
Command.bit3 = 1
endif
if IRpulse_length(5) < 100 then
Command.bit4 = 0
Else
Command.bit4 = 1
endif
if IRpulse_length(6) < 100 then
Command.bit5 = 0
Else
Command.bit5 = 1
endif
if IRpulse_length(7) < 100 then
Command.bit6 = 0
Else
Command.bit6 = 1
endif
Command.bit7 = 0
Command = Command + 1
If Command = 10 then
Command = 0
Endif
if IRpulse_length(8) < 100 then
Device.bit0 = 0
Else
Device.bit0 = 1
endif
if IRpulse_length(9) < 100 then
Device.bit1 = 0
Else
Device.bit1 = 1
endif
if IRpulse_length(10) < 100 then
Device.bit2 = 0
Else
Device.bit2 = 1
endif
if IRpulse_length(11) < 100 then
Device.bit3 = 0
Else
Device.bit3 = 1
endif
'Device.bit1 = 0
low portb.7
'SEROUT Porta.3,sbaud,[#Device," - ",#Command,13,10]
iF COMMAND = 13 THEN
high left
PAUSE 800
ENDIF
RESUME
ENABLE INTERRUPT
'pause 100
goto start
Bookmarks