This is an update my previous software serial implementation. It has been updated to use commands similar to the internal rs232.h by adding an "X" (e.g. SerPrintX, and so forth). The SoftSerial.h. file should be placed in the GreatCowBasic/include folder (not lowlevel folder!!!) and be included like so in the program code.
#chip 12f1822, 4#include<SoftSerialX.h>
The table at the top of the header file explains the commands, syntax, and the constants required. The baudrates were established in a trial and error manner, and slight adjustments (up/down) to the BaudDelay's may be required in certain conditions.
See next post for the file, make sure the text file is saved with .h suffix.
Edit: included Hugh in credits of SoftSerialX.h as many routines derived (stolen) from GCB, thanks
Last edit: kent_twt4 2015-03-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
' Alternate software serial routines for the Great Cow BASIC compiler' Copyright (C) 2015 Kent Schafer, Hugh Considine' This library is free software; you can redistribute it and/or' modify it under the terms of the GNU Lesser General Public' License as published by the Free Software Foundation; either' version 2.1 of the License, or (at your option) any later version.' This library is distributed in the hope that it will be useful,' but WITHOUT ANY WARRANTY; without even the implied warranty of' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU' Lesser General Public License for more details.' You should have received a copy of the GNU Lesser General Public' License along with this library; if not, write to the Free Software' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA'Notes:' This is a bare bones code for software rs232 comms' terminal setup - 8 (data bits), none(parity), 1 (stop bit)' Kent Schafer Mar 13, 2015'************************************************************'SoftSerialX.h commands *'InitSerX *'SerPrintX byte, word, string *'SerSendX byte 'for non ascii characters *'SerReceiveX byte *'************************************************************'baudrate table (tested for PICs may need adj. for AVRs *'************************************************************'baudrate of 9600 & 19200 needs 8 Mhz clock minimum *'************************************************************'BaudDelay for 19200 baud rate is 49 and HalfBaud is 25 *'BaudDelay for 9600 baud rate is 103 and HalfBaud is 52 *'************************************************************'BaudDelay for 9600 at 4 Mhz clock is 98 and HalfBaud is 50 *'************************************************************'baudrate 2400 & 4800 work with 4 MhZ and up clock *'BaudDelay for 4800 baud rate is 206 and HalfBaud is 103 *'BaudDelay for 2400 baud rate is 408 and HalfBaud is 204 *'************************************************************'Mandatory syntax and constants for rs232X *'************************************************************'select baud and half baud delays from table values *'#define BaudDelay wait XX us *'#define HalfBaudDelay wait XX us *'substitute GPIO.Pin for PortX.Pin when appropriate *'#define SerTxHigh Set PortX.Pin On *'#define SerTxLow Set PortX.Pin Off *'#define SerRx PortX.Pin *'dir PortX.Pin Out ;Tx *'dir PortX.Pin in ;Rx *'Call InitSerX *'************************************************************SubInitSERXSerTxHigh;InitialRS232idlestateendsubSubSerReceiveX(RxByte)RxWait:'wait for start bitIFSerRxOnThengotoSerReceiveX'do half bit time delayHalfBaudDelayIfSerRxOnThengotoRxWaitRxByte=0ForRxBit=1to8BaudDelayRotateRxByteRightIfSerRxOnthenSetRxByte.71IfSerRxOffThenSetRxByte.70NextBaudDelayEndsubsubSerPrintX(PrintData$asstring)PrintLen=PrintData(0)ifPrintLen=0thenexitsubforSysPrintTemp=1toPrintLenSerSendX(PrintData(SysPrintTemp))nextendsubSubSerSendX(Xmit_Byte)#NRSerTxLow'wait BaudDelay usBaudDelayForcntr=1to8RotateXmit_ByteRight#IfDEFPICIfStatus.CONThen#endif#ifdefAVRIfSREG.0OnThen#endifSerTxHighElseSerTxLowEndifBaudDelayNextSerTxHighBaudDelayendsubsubSerPrintX(LCDValue)#NRLCDValueTemp=0LCDShowChar=0SERCEN=0SERDEC=0SERUN=0IfLCDValue>=100thenLCDValueTemp=LCDValue/100LCDValue=SysCalcTempXSERCEN=LCDValueTemp+48SerSendX(SERCEN)LCDShowChar=TRUEEndIfIfLCDShowChar>0orLCDValue>=10thenLCDValueTemp=LCDValue/10LCDValue=SysCalcTempXSERDEC=LCDValueTemp+48SerSendX(SERDEC)EndIfSERUN=LCDValue+48SerSendX(SERUN)EndSubsubSerPrintX(LCDValueasword)#NRDimSysCalcTempXAsWordLCDValueTemp=0LCDShowChar=0SERDECMIL=0SERMIL=0SERCEN=0SERDEC=0SERUN=0IfLCDValue>=10000thenLCDValueTemp=LCDValue/10000[word]LCDValue=SysCalcTempXSERDECMIL=LCDValueTemp+48SerSendX(SERDECMIL)LCDShowChar=TRUEEndIfIfLCDShowChar>0orLCDValue>=1000thenLCDValueTemp=LCDValue/1000[word]LCDValue=SysCalcTempXSERMIL=LCDValueTemp+48SerSendX(SERMIL)LCDShowChar=TRUEEndIfIfLCDShowChar>0orLCDValue>=100thenLCDValueTemp=LCDValue/100[word]LCDValue=SysCalcTempXSERCEN=LCDValueTemp+48SerSendX(SERCEN)LCDShowChar=TRUEEndIfIfLCDShowChar>0orLCDValue>=10thenLCDValueTemp=LCDValue/10[word]LCDValue=SysCalcTempXSERDEC=LCDValueTemp+48SerSendX(SERDEC)EndIfSERUN=LCDValue+48SerSendX(SERUN)EndSub
Last edit: kent_twt4 2015-03-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is an update my previous software serial implementation. It has been updated to use commands similar to the internal rs232.h by adding an "X" (e.g. SerPrintX, and so forth). The SoftSerial.h. file should be placed in the GreatCowBasic/include folder (not lowlevel folder!!!) and be included like so in the program code.
The table at the top of the header file explains the commands, syntax, and the constants required. The baudrates were established in a trial and error manner, and slight adjustments (up/down) to the BaudDelay's may be required in certain conditions.
See next post for the file, make sure the text file is saved with .h suffix.
Edit: included Hugh in credits of SoftSerialX.h as many routines derived (stolen) from GCB, thanks
Last edit: kent_twt4 2015-03-14
Last edit: kent_twt4 2015-03-15