Hi Guys,
I thought it should be possible to save space if bit banging serial manually.
Maybe just if one speed, or one direction is needed, which is transmit only in this case,
and the byte value is destroyed by the send each time.
That’s what the code is. The delay of course depends on the baud rate you want, and the pic’s clock speed.
Now I’m thinking on the receive side, a fast enough pic should be able to determine the received baud rate
with the very first received byte, by measuring the duration of the start to stop bit,
rather then sending a known byte value and trying to receive at each baud rate until it’s interpreted properly.
Code:
‘ PBP software serial out 8N1
delay var word ‘ set baud rate delay
txbyte var byte ‘ byte to send
count var byte ‘ counter
delay = 0’ set serial delay here
main:
txbyte = “H"
GOSUB serialout
txbyte = “E"
GOSUB serialout
txbyte = “L"
GOSUB serialout
txbyte = “L"
GOSUB serialout
txbyte = “O"
GOSUB serialout
txbyte = $20 ‘ space
GOSUB serialout
goto main
serialout:
‘ start bit
PORTB.1 = 0’ tx clear
PAUSEUS delay ‘ start bit delay
‘ send byte
FOR count = 0 TO 7
IF txbyte.bit0 = 1 THEN
PORTB.1 = 1
ELSE
PORTB.1 = 0
ENDIF
txbyte = txbyte >> 1
PAUSEUS delay ‘ data bit delay
NEXT count
PORTB.1 = 1
PAUSEUS delay ‘ stop bit delay
RETURN
Bookmarks