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)2015KentSchafer,HughConsidine' This library is free software; you can redistribute it and/or'modifyitunderthetermsoftheGNULesserGeneralPublic' License as published by the Free Software Foundation; either'version2.1oftheLicense,or(atyouroption)anylaterversion.' This library is distributed in the hope that it will be useful,'butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU'LesserGeneralPublicLicenseformoredetails.' You should have received a copy of the GNU Lesser General Public'Licensealongwiththislibrary;ifnot,writetotheFreeSoftware' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA'Notes:' This is a bare bones code for software rs232 comms'terminalsetup-8(databits),none(parity),1(stopbit)' Kent Schafer Mar 13, 2015'************************************************************'SoftSerialX.h commands *'InitSerX*'SerPrintX byte, word, string *'SerSendXbyte'for non ascii characters *'SerReceiveXbyte*'************************************************************'baudratetable(testedforPICsmayneedadj.forAVRs*'************************************************************'baudrateof9600&19200needs8Mhzclockminimum*'************************************************************'BaudDelayfor19200baudrateis49andHalfBaudis25*'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 *'BaudDelayfor4800baudrateis206andHalfBaudis103*'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 *'#defineBaudDelaywaitXXus*'#define HalfBaudDelay wait XX us *'substituteGPIO.PinforPortX.Pinwhenappropriate*'#define SerTxHigh Set PortX.Pin On *'#defineSerTxLowSetPortX.PinOff*'#define SerRx PortX.Pin *'dirPortX.PinOut;Tx*'dir PortX.Pin in ;Rx *'CallInitSerX*'************************************************************Sub InitSERXSerTxHigh ;Initial RS232 idle stateend subSub SerReceiveX (RxByte)RxWait:'waitforstartbitIFSerRxOnThengotoSerReceiveX'do half bit time delayHalfBaudDelayIf SerRx On Then goto RxWaitRxByte = 0For RxBit = 1 to 8 BaudDelay Rotate RxByte Right If SerRx On then Set RxByte.7 1 If SerRx Off Then Set RxByte.7 0NextBaudDelayEnd subsub SerPrintX (PrintData$ as string)PrintLen = PrintData(0)if PrintLen = 0 then exit subfor SysPrintTemp = 1 to PrintLenSerSendX(PrintData(SysPrintTemp))nextend subSub SerSendX(Xmit_Byte)#NRSerTxLow'waitBaudDelayusBaudDelayForcntr=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