why does this not work?
#chip 12F683, 8 'mhz
#config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off
#define RecAHigh GPIO.1 off
#define RecALow GPIO.1 on
InitSer 1,r9600,1,8,1,none,normal
dir gpio.0 out
dir gpio.1 in
Ser_Init
main:
serreceive 1, temp
if temp = 49 then
xmit_print ("works")
wait 2 s
end if
goto main
Sub Ser_Init
#define baud 104 ;the us delay for 9600 baud rate
#define SerTxHigh Set gpio.0 on
#define SerTxLow Set gpio.0 off
SerTxhigh ;Initial RS232 idle state
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unfortunately the syntax for the built in software uart and the alternate rs232 functions have been intermingled. Try the help file from the GCBasic folder and follow the clear examples.
If you wish to explore the alternate soft uart routine, then look at the below example code with all supporting subs. The NEW bin2ascii routines are just a different name for Hugh's GCBasics Print() subs from lcd.h. But if we used that sub name here, the compiler would get confused. All the setup for I/O and baud rate is in the Ser_Init sub.
'Updated Alternate Soft RS232 routine example with new bin2ascii'overloadedsubs.kent_twt4#chip12F683,8'mhz#config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=offdim num as wordSer_Initstart:;Pic waits for signal from terminal/computerRCV_RS232 ;Waits for terminal input, and return value is RxByteXmit_RS232 RxByte ;echo back received ascii valueIf RxByte = 49 Then ;ascii 49 (Decimal 1 from terminal) XMIT_PRINT (" hello") For num = 0 to 500 Bin2ascii num ;send out binary value as ascii XMIT_Print (" ") nextend ifXmit_RS232 10:Xmit_RS232 13 ;line feed, carriage returngoto startSub Ser_Init;slight adjustment was required for 9600bps delay value#define baud 103 ;expressed as frequency in us#define halfbaud 52 ;place Read of SerRx in middle of bit#define SerTxHigh Set GPIO.0 On#define SerTxLow Set GPIO.0 Off#define SerRx GPIO.1dir GPIO.0 out ;Txdir GPIO.1 in ;RxSerTxHigh ;Initial RS232 idle stateend subSub RCV_RS232 RxWait:IF SerRx On Then goto RCV_RS232 ;wait for start bitwait halfbaud us ;do half bit time delayIf SerRx On Then goto RxWaitRxByte = 0For RxBit = 1 to 8 ;set up to read 8 bitswait baud usRotate RxByte RightIf SerRx On then Set RxByte.7 1If SerRx Off Then Set RxByte.7 0Nextwait baud usEnd subsub XMIT_PRINT (PrintData$)PrintLen = PrintData(0)if PrintLen = 0 then exit sub'WriteDataforSysPrintTemp=1toPrintLenXMIT_RS232(PrintData(SysPrintTemp))nextendsubSubXMIT_RS232(Xmit_Byte)#NRSerTxLowwaitbaudusForcntr=1to8RotateXmit_ByteRightIfStatus.CONThenSerTxHighIfStatus.COffThenSerTxLowwaitbaudusNextSerTxHighwaitbaudusendsubsubbin2ascii(LCDValue)#NRLCDValueTemp=0LCDShowChar=0SERCEN=0SERDEC=0SERUN=0IfLCDValue>=100thenLCDValueTemp=LCDValue/100LCDValue=SysCalcTempXSERCEN=LCDValueTemp+48Xmit_RS232(SERCEN)LCDShowChar=TRUEEndIfIfLCDShowChar>0orLCDValue>=10thenLCDValueTemp=LCDValue/10LCDValue=SysCalcTempXSERDEC=LCDValueTemp+48Xmit_RS232(SERDEC)EndIfSERUN=LCDValue+48Xmit_RS232(SERUN)EndSubsubbin2ascii(LCDValueasword)#NRDimSysCalcTempXAsWordLCDValueTemp=0LCDShowChar=0SERDECMIL=0SERMIL=0SERCEN=0SERDEC=0SERUN=0IfLCDValue>=10000thenLCDValueTemp=LCDValue/10000[word]LCDValue=SysCalcTempXSERDECMIL=LCDValueTemp+48Xmit_RS232(SERDECMIL)LCDShowChar=TRUEEndIfIfLCDShowChar>0orLCDValue>=1000thenLCDValueTemp=LCDValue/1000[word]LCDValue=SysCalcTempXSERMIL=LCDValueTemp+48Xmit_RS232(SERMIL)LCDShowChar=TRUEEndIfIfLCDShowChar>0orLCDValue>=100thenLCDValueTemp=LCDValue/100[word]LCDValue=SysCalcTempXSERCEN=LCDValueTemp+48Xmit_RS232(SERCEN)LCDShowChar=TRUEEndIfIfLCDShowChar>0orLCDValue>=10thenLCDValueTemp=LCDValue/10[word]LCDValue=SysCalcTempXSERDEC=LCDValueTemp+48Xmit_RS232(SERDEC)EndIfSERUN=LCDValue+48Xmit_RS232(SERUN)EndSub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well that is a bummer, code tags on the blink again, or I just can't figure it out. Even dumped it in BBCode playground to check it first. About to give up on this, will try again.
'Updated Alternate Soft RS232 routine example with new bin2ascii'overloadedsubs.kent_twt4#chip12F683,8'mhz#config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=offdim num as wordSer_Initstart:;Pic waits for signal from terminal/computerRCV_RS232 ;Waits for terminal input, and return value is RxByteXmit_RS232 RxByte ;echo back received ascii valueIf RxByte = 49 Then ;ascii 49 (Decimal 1 from terminal) XMIT_PRINT (" hello") For num = 0 to 500 Bin2ascii num ;send out binary value as ascii XMIT_Print (" ") nextend ifXmit_RS232 10:Xmit_RS232 13 ;line feed, carriage returngoto startSub Ser_Init;slight adjustment was required for 9600bps delay value#define baud 103#define halfbaud 52 ;place Read of SerRx in middle of bit#define SerTxHigh Set GPIO.0 On#define SerTxLow Set GPIO.0 Off#define SerRx GPIO.1dir GPIO.0 out ;Txdir GPIO.1 in ;RxSerTxHigh ;Initial RS232 idle stateend subSub RCV_RS232 RxWait:IF SerRx On Then goto RCV_RS232 ;wait for start bitwait halfbaud us ;do half bit time delayIf SerRx On Then goto RxWaitRxByte = 0For RxBit = 1 to 8 ;set up to read 8 bitswait baud usRotate RxByte RightIf SerRx On then Set RxByte.7 1If SerRx Off Then Set RxByte.7 0Nextwait baud usEnd subsub XMIT_PRINT (PrintData$)PrintLen = PrintData(0)if PrintLen = 0 then exit sub'WriteDataforSysPrintTemp=1toPrintLenXMIT_RS232(PrintData(SysPrintTemp))nextendsubSubXMIT_RS232(Xmit_Byte)#NRSerTxLowwaitbaudusForcntr=1to8RotateXmit_ByteRightIfStatus.CONThenSerTxHighIfStatus.COffThenSerTxLowwaitbaudusNextSerTxHighwaitbaudusendsubsubbin2ascii(LCDValue)#NRLCDValueTemp=0LCDShowChar=0SERCEN=0SERDEC=0SERUN=0IfLCDValue>=100thenLCDValueTemp=LCDValue/100LCDValue=SysCalcTempXSERCEN=LCDValueTemp+48Xmit_RS232(SERCEN)LCDShowChar=TRUEEndIfIfLCDShowChar>0orLCDValue>=10thenLCDValueTemp=LCDValue/10LCDValue=SysCalcTempXSERDEC=LCDValueTemp+48Xmit_RS232(SERDEC)EndIfSERUN=LCDValue+48Xmit_RS232(SERUN)EndSubsubbin2ascii(LCDValueasword)#NRDimSysCalcTempXAsWordLCDValueTemp=0LCDShowChar=0SERDECMIL=0SERMIL=0SERCEN=0SERDEC=0SERUN=0IfLCDValue>=10000thenLCDValueTemp=LCDValue/10000[word]LCDValue=SysCalcTempXSERDECMIL=LCDValueTemp+48Xmit_RS232(SERDECMIL)LCDShowChar=TRUEEndIfIfLCDShowChar>0orLCDValue>=1000thenLCDValueTemp=LCDValue/1000[word]LCDValue=SysCalcTempXSERMIL=LCDValueTemp+48Xmit_RS232(SERMIL)LCDShowChar=TRUEEndIfIfLCDShowChar>0orLCDValue>=100thenLCDValueTemp=LCDValue/100[word]LCDValue=SysCalcTempXSERCEN=LCDValueTemp+48Xmit_RS232(SERCEN)LCDShowChar=TRUEEndIfIfLCDShowChar>0orLCDValue>=10thenLCDValueTemp=LCDValue/10[word]LCDValue=SysCalcTempXSERDEC=LCDValueTemp+48Xmit_RS232(SERDEC)EndIfSERUN=LCDValue+48Xmit_RS232(SERUN)EndSub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
why does this not work?
#chip 12F683, 8 'mhz
#config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off
#define RecAHigh GPIO.1 off
#define RecALow GPIO.1 on
InitSer 1,r9600,1,8,1,none,normal
dir gpio.0 out
dir gpio.1 in
Ser_Init
main:
serreceive 1, temp
if temp = 49 then
xmit_print ("works")
wait 2 s
end if
goto main
Sub Ser_Init
#define baud 104 ;the us delay for 9600 baud rate
#define SerTxHigh Set gpio.0 on
#define SerTxLow Set gpio.0 off
SerTxhigh ;Initial RS232 idle state
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
Unfortunately the syntax for the built in software uart and the alternate rs232 functions have been intermingled. Try the help file from the GCBasic folder and follow the clear examples.
If you wish to explore the alternate soft uart routine, then look at the below example code with all supporting subs. The NEW bin2ascii routines are just a different name for Hugh's GCBasics Print() subs from lcd.h. But if we used that sub name here, the compiler would get confused. All the setup for I/O and baud rate is in the Ser_Init sub.
Well that is a bummer, code tags on the blink again, or I just can't figure it out. Even dumped it in BBCode playground to check it first. About to give up on this, will try again.
That's it, I give, unless someone can explain it to me.
thanks,
that works great