I want to be able to receive a command and do the appropriate output bassed off it, but im not sure exactly how to get it to work for maore than a single character, heres what im trying to do, I commented out what i started with:
chip 12F683, 8 'mhz
config MCLRE=off, WDT=off, OSC=INTOSC, boden=off
dim temp as byte
dir gpio.0 in
dir gpio.1 out
define RecAHigh GPIO.0 off
define RecALow GPIO.0 on
InitSer 1,r9600,1,8,1,none,invert
temp = 0
dim temp as word
set gpio.1 on
main:
SerReceive 1, Temp
'if temp = 49 then
if temp = "on" then
set gpio.1 off
temp = 0
end if
'if temp = 48 then
if temp = "off" then
set gpio.1 on
temp = 0
end if
goto main
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The SerReceive would receive ascii characters from a terminal. I assume you are sending the commands from a terminal. It only receives one byte char at a time.
To receive a string like "on" you must save the chars ,one at a time, and wait for an ending char like a carriage return (CR). After you have the complete command, then you compare the received command to to programmed commands and excute the appropriate method. See example below.
Your first try, that you commented out, commands should work. A 48 is an ascii '0' which would be a one char command to shut off your I/O point. You receive a byte char and execute it.
One little error is that you "Dim"med temp differently twice.
If you look in the Great Cow Basic documentation >command references>serial communications>RS232(hardware)>HSerGetString you will find an example of turning I/O on and off with long commands. Your 12F683 can't do this because it don't have a hardware usart but if you look up the HSerGetString command in the Include directory GreatcowBasic>include>lowlevel>usart.h you will find the code that makes that command work. Actually it is a short routine that could be adated to Soft Serial.
subHSerGetString(OutHSerStringAsString,optionalIncomport=1)HSerIndex=0Docomport=comport'not really required but added for clarity HSerReceive ( HSerInByte )'Enter key? If HSerInByte = 13 Then Exit Sub End If'letters,numbers,punctuation If HSerInByte >= 32 and HSerInByte <= 126 Then HSerIndex++ HSerString(HSerIndex) = HSerInByte HSerString(0) = HSerIndex End If LoopEnd Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I want to be able to receive a command and do the appropriate output bassed off it, but im not sure exactly how to get it to work for maore than a single character, heres what im trying to do, I commented out what i started with:
chip 12F683, 8 'mhz
config MCLRE=off, WDT=off, OSC=INTOSC, boden=off
dim temp as byte
dir gpio.0 in
dir gpio.1 out
define RecAHigh GPIO.0 off
define RecALow GPIO.0 on
InitSer 1,r9600,1,8,1,none,invert
temp = 0
dim temp as word
set gpio.1 on
main:
SerReceive 1, Temp
'if temp = 49 then
if temp = "on" then
set gpio.1 off
temp = 0
end if
'if temp = 48 then
if temp = "off" then
set gpio.1 on
temp = 0
end if
goto main
The SerReceive would receive ascii characters from a terminal. I assume you are sending the commands from a terminal. It only receives one byte char at a time.
To receive a string like "on" you must save the chars ,one at a time, and wait for an ending char like a carriage return (CR). After you have the complete command, then you compare the received command to to programmed commands and excute the appropriate method. See example below.
Your first try, that you commented out, commands should work. A 48 is an ascii '0' which would be a one char command to shut off your I/O point. You receive a byte char and execute it.
One little error is that you "Dim"med temp differently twice.
If you look in the Great Cow Basic documentation >command references>serial communications>RS232(hardware)>HSerGetString you will find an example of turning I/O on and off with long commands. Your 12F683 can't do this because it don't have a hardware usart but if you look up the HSerGetString command in the Include directory GreatcowBasic>include>lowlevel>usart.h you will find the code that makes that command work. Actually it is a short routine that could be adated to Soft Serial.