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'overloaded subs. kent_twt4#chip 12F683, 8 'mhz#config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=offdimnumaswordSer_Initstart:;Picwaitsforsignalfromterminal/computerRCV_RS232;Waitsforterminalinput,andreturnvalueisRxByteXmit_RS232RxByte;echobackreceivedasciivalueIfRxByte=49Then;ascii49(Decimal1fromterminal)XMIT_PRINT(" hello")Fornum=0to500Bin2asciinum;sendoutbinaryvalueasasciiXMIT_Print(" ")nextendifXmit_RS23210:Xmit_RS23213;linefeed,carriagereturngotostartSubSer_Init;slightadjustmentwasrequiredfor9600bpsdelayvalue#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.1dirGPIO.0out;TxdirGPIO.1in;RxSerTxHigh;InitialRS232idlestateendsubSubRCV_RS232RxWait:IFSerRxOnThengotoRCV_RS232;waitforstartbitwaithalfbaudus;dohalfbittimedelayIfSerRxOnThengotoRxWaitRxByte=0ForRxBit=1to8;setuptoread8bitswaitbaudusRotateRxByteRightIfSerRxOnthenSetRxByte.71IfSerRxOffThenSetRxByte.70NextwaitbaudusEndsubsubXMIT_PRINT(PrintData$)PrintLen=PrintData(0)ifPrintLen=0thenexitsub'Write DataforSysPrintTemp=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'overloaded subs. kent_twt4#chip 12F683, 8 'mhz#config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=offdimnumaswordSer_Initstart:;Picwaitsforsignalfromterminal/computerRCV_RS232;Waitsforterminalinput,andreturnvalueisRxByteXmit_RS232RxByte;echobackreceivedasciivalueIfRxByte=49Then;ascii49(Decimal1fromterminal)XMIT_PRINT(" hello")Fornum=0to500Bin2asciinum;sendoutbinaryvalueasasciiXMIT_Print(" ")nextendifXmit_RS23210:Xmit_RS23213;linefeed,carriagereturngotostartSubSer_Init;slightadjustmentwasrequiredfor9600bpsdelayvalue#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.1dirGPIO.0out;TxdirGPIO.1in;RxSerTxHigh;InitialRS232idlestateendsubSubRCV_RS232RxWait:IFSerRxOnThengotoRCV_RS232;waitforstartbitwaithalfbaudus;dohalfbittimedelayIfSerRxOnThengotoRxWaitRxByte=0ForRxBit=1to8;setuptoread8bitswaitbaudusRotateRxByteRightIfSerRxOnthenSetRxByte.71IfSerRxOffThenSetRxByte.70NextwaitbaudusEndsubsubXMIT_PRINT(PrintData$)PrintLen=PrintData(0)ifPrintLen=0thenexitsub'Write DataforSysPrintTemp=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