scgoo
Newbie level 4
hi, im using PIC16f628 for my design. the program will receive signal in the form of character as shown in the code below. PC and PIC will communicate via serial port(rs232).
but when i send a "A" to the PIC, it didnt go to the "TurnLeft" subroutine, but it go to the "Confuse". it is same happen when i send "B", "C" , D, E to the PIC. it will go to the "Confuse". but when i send a character "W" ,it will take it as "D" and go to the Sad , and send "Y" it will take it as "C", and send "u" it will take it as "E".
why will this happen??
i'm confusing...
any suggestion? pointer?
thanks!
''''''''''''initialization'''''''''''
success = 0: i = 0 : bell_on = 0
init:
INTCON = %11000000
PIE1.5 = 1
ON INTERRUPT GoTo handler
main:
if success = 1 then
bell_on = 1
confirm = 0
i = 200
while (i != 0)
i = i - 1
pause 5
wend
if (store = "A" ) then
gosub TurnLeft
confirm = 1
endif
if ( store = "B" and confirm <> 0 ) then
gosub TurnRight
confirm = 1
endif
if (store = "C" and confirm <> 1) then
gosub Happy
confirm = 1
endif
if (store = "D" and confirm <> 1) then
gosub Sad
confirm = 1
ENdif
if (store ="E" and confirm <> 1) then
gosub Angry
confirm = 1
endif
if (confirm <> 1) then
gosub Confuse
ENdif
confirm = 0
success = 0
bell_on = 0
endif
goto main
Happy:
LED = 1
PORTA = %00000111
PAUSE 500
LED = 0
PAUSE 500
return
Sad:
PORTA = %00000010
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return
Angry:
PORTA = %00000011
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return
Confuse:
PORTA = %00000100
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return
TurnLeft:
PORTA = %00000101
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return
TurnRight:
PORTA = %00000110
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return
'''''''''''''''interrupt'''''''''''
disable
handler:
hserin 10,error,[store]
success = 1
ERROR:
resume
enable
but when i send a "A" to the PIC, it didnt go to the "TurnLeft" subroutine, but it go to the "Confuse". it is same happen when i send "B", "C" , D, E to the PIC. it will go to the "Confuse". but when i send a character "W" ,it will take it as "D" and go to the Sad , and send "Y" it will take it as "C", and send "u" it will take it as "E".
why will this happen??
i'm confusing...
any suggestion? pointer?
thanks!
''''''''''''initialization'''''''''''
success = 0: i = 0 : bell_on = 0
init:
INTCON = %11000000
PIE1.5 = 1
ON INTERRUPT GoTo handler
main:
if success = 1 then
bell_on = 1
confirm = 0
i = 200
while (i != 0)
i = i - 1
pause 5
wend
if (store = "A" ) then
gosub TurnLeft
confirm = 1
endif
if ( store = "B" and confirm <> 0 ) then
gosub TurnRight
confirm = 1
endif
if (store = "C" and confirm <> 1) then
gosub Happy
confirm = 1
endif
if (store = "D" and confirm <> 1) then
gosub Sad
confirm = 1
ENdif
if (store ="E" and confirm <> 1) then
gosub Angry
confirm = 1
endif
if (confirm <> 1) then
gosub Confuse
ENdif
confirm = 0
success = 0
bell_on = 0
endif
goto main
Happy:
LED = 1
PORTA = %00000111
PAUSE 500
LED = 0
PAUSE 500
return
Sad:
PORTA = %00000010
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return
Angry:
PORTA = %00000011
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return
Confuse:
PORTA = %00000100
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return
TurnLeft:
PORTA = %00000101
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return
TurnRight:
PORTA = %00000110
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return
'''''''''''''''interrupt'''''''''''
disable
handler:
hserin 10,error,[store]
success = 1
ERROR:
resume
enable