this code sometimes works:
#chip 12F683, 20 'mhz
#config XT, MCLRE=off, WDT=off',OSC=INTOSC
dim temp as byte
dir gpio.0 in
dir gpio.1 out
#define RecAHigh GPIO.0 off
#define RecALow GPIO.0 on
InitSer 1,r1200,1,8,1,none,invert
dim temp1 as byte
dim loc as byte
loc = 0
set gpio.1 on
wait 2 s
set gpio.1 off
main:
if loc = 0 then
SerReceive 1, Temp
if temp <> 36 then loc = 1
end if
if loc = 1 then
SerReceive 1, Temp1
if temp1 = 36 then
if temp = 115 then
set gpio.1 on
wait 250 ms
set gpio.1 off
end if
if temp = 123 then set gpio.1 on
if temp = 125 then set gpio.1 off
loc = 2
end if
end if
if loc = 2 then loc = 0
goto main
but when i use this it does ot work:
#chip 12F683, 20 'mhz
#config XT, MCLRE=off, WDT=off',OSC=INTOSC
Ser_Init
dim temp as byte
dir gpio.1 out
dim temp1 as byte
dim loc as byte
loc = 0
set gpio.1 on
wait 2 s
set gpio.1 off
main:
RCV_RS232
if loc = 0 then
temp = rxbyte
if temp <> 36 then loc = 1
end if
if loc = 1 then
Temp1=rxbyte
if temp1 = 36 then
if temp = 115 then
set gpio.1 on
wait 250 ms
set gpio.1 off
end if
if temp = 123 then set gpio.1 on
if temp = 125 then set gpio.1 off
loc = 2
end if
end if
if loc = 2 then loc = 0
goto main
Sub Ser_Init
#define baud 832
#define halfbaud 416 ;place Read of SerRx in middle of bit
#define SerRx gpio.0
dir gpio.0 in ;Rx
end sub
Sub RCV_RS232
RxWait:
IF SerRx Off Then goto RCV_RS232 ;wait for start bit
wait halfbaud us ;do half bit time delay
If SerRx Off Then goto RxWait
RxByte = 0
For RxBit = 1 to 8 ;set up to read 8 bits
wait baud us
Rotate RxByte Right
If SerRx On then Set RxByte.7 0
If SerRx Off Then Set RxByte.7 1
Next
wait baud us
End sub
why?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
this code sometimes works:
#chip 12F683, 20 'mhz
#config XT, MCLRE=off, WDT=off',OSC=INTOSC
dim temp as byte
dir gpio.0 in
dir gpio.1 out
#define RecAHigh GPIO.0 off
#define RecALow GPIO.0 on
InitSer 1,r1200,1,8,1,none,invert
dim temp1 as byte
dim loc as byte
loc = 0
set gpio.1 on
wait 2 s
set gpio.1 off
main:
if loc = 0 then
SerReceive 1, Temp
if temp <> 36 then loc = 1
end if
if loc = 1 then
SerReceive 1, Temp1
if temp1 = 36 then
if temp = 115 then
set gpio.1 on
wait 250 ms
set gpio.1 off
end if
if temp = 123 then set gpio.1 on
if temp = 125 then set gpio.1 off
loc = 2
end if
end if
if loc = 2 then loc = 0
goto main
but when i use this it does ot work:
#chip 12F683, 20 'mhz
#config XT, MCLRE=off, WDT=off',OSC=INTOSC
Ser_Init
dim temp as byte
dir gpio.1 out
dim temp1 as byte
dim loc as byte
loc = 0
set gpio.1 on
wait 2 s
set gpio.1 off
main:
RCV_RS232
if loc = 0 then
temp = rxbyte
if temp <> 36 then loc = 1
end if
if loc = 1 then
Temp1=rxbyte
if temp1 = 36 then
if temp = 115 then
set gpio.1 on
wait 250 ms
set gpio.1 off
end if
if temp = 123 then set gpio.1 on
if temp = 125 then set gpio.1 off
loc = 2
end if
end if
if loc = 2 then loc = 0
goto main
Sub Ser_Init
#define baud 832
#define halfbaud 416 ;place Read of SerRx in middle of bit
#define SerRx gpio.0
dir gpio.0 in ;Rx
end sub
Sub RCV_RS232
RxWait:
IF SerRx Off Then goto RCV_RS232 ;wait for start bit
wait halfbaud us ;do half bit time delay
If SerRx Off Then goto RxWait
RxByte = 0
For RxBit = 1 to 8 ;set up to read 8 bits
wait baud us
Rotate RxByte Right
If SerRx On then Set RxByte.7 0
If SerRx Off Then Set RxByte.7 1
Next
wait baud us
End sub
why?