Kamikaze,
I think this will do what you wanted, without any external OR/AND gates.
There's so much more I could do with it.
But it's already more than you need, so I think I'll stop now.
This is an Include module, that sends Serial data using a Timer as the baud rate generator.
Currently, it will only work on 18F's, and it's only the Transmit side.
It can use any one of Timer 0, 1 or 3. But does not use interrupts.
Outputs on any digital I/O Pin.
Can send Bytes, Words, Strings from arrays, Strings from Flash and ASCII decimal values.
Runs up to 115200 with 32mhz(or higher) OSC.
You can use HSEROUT for the USART, and this as a second UART.
Setup is pretty simple.
Just tell it which Timer to use, the baud rate and the I/O Pin...
Code:
;----[Setup Timer based UART]-------------------------------------------------
DEFINE TX_TIMER 1 ; Timer used for serial UART (0,1 or 3)
DEFINE TX_BAUD 9600 ; Baud Rate
TX_Pin VAR PORTB.6 ; Output Pin
INCLUDE "TMR_TX-18.bas" ; Include the Timed Serial module
The TX_Pin is automatically set to output and idles high. (assuming there's no A/D etc. enabled on the pin)
Serial signal is 8N1 True. Same as the USART.
If all you are sending is Strings from Array's, then you just need 1 Command...
Code:
@ TX_STR?B _StrArray, _Length
Which is functionally the same as,
HSEROUT [STR StrArray\Length]
where Length is a BYTE variable.
A variation of the same thing uses a Constant Length (max 255)
Code:
@ TX_STR?C _StrArray, 16
Using just array's, the module will use about 250 bytes of program space.
Using the additional commands may add up to another 200 byes plus string data.
Relatively small, compared to HSEROUT.<hr>Additional commands that are available are...
Code:
@ TX?C Const ;- send a Char (constant 0-255)
@ TX?B _Value ;- Send a byte from a BYTE var
@ TX?W _Value ;- Send a binary Word var (LSB first)
@ TX_DEC?B _Value ;- Ascii Decimal Byte, no leading 0's
@ TX_DEC?W _Value ;- Ascii Decimal Word, no leading 0's
@ TX_DEC?CB Len, _Value ;- Ascii Decimal BYTE, Len is a constant
@ TX_DEC?CW Len, _Value ;- Ascii Decimal WORD, Len is a constant
@ TX_STR?C Str, Len ;- Send an Array, Len is a constant
@ TX_STR?B Str, _Len ;- Send an Array, Len is BYTE var
@ LoadStr _Array, Str, _Len ;- Load an Array from flash, Returns
; the length of the string in BYTE var
@ TX_FSTR Fstr ;- Send Fixed String from Flash
@ TX_DSTR Dstr ;- Send PreDefined String from Flash
Examples...
Code:
@ TX?C "A" ; same as HSEROUT ["A"]
@ TX?B _ByteVar ; same as HSEROUT [ByteVar]
@ TX?W _WordVar ; HSEROUT [WordVar.LowByte, WordVar.HighByte]
@ TX_DEC?B _ByteVar ; HSEROUT [DEC ByteVar]
@ TX_DEC?W _WordVar ; HSEROUT [DEC WordVar]
@ TX_DEC?CB 3, _ByteVar ; HSEROUT [DEC3 ByteVar]
@ TX_DEC?CW 4, _WordVar ; HSEROUT [DEC4 WordVar]
@ TX_STR?C _StrArray, 13 ; HSEROUT [STR StrArray\13]
@ TX_STR?B _StrArray, _ByteVar ; HSEROUT [STR StrArray\ByteVar]
@ TX_FSTR "Hello World\r\n" ; HSEROUT ["Hello World",13,10]
@ TX_DSTR Wassup ; no equivilent
@Wassup string "Hey dude, wasssssup!\r\n"
@ LoadStr _StrArray, "Put me in Array\r\n", _ByteVar
; returns length of string in ByteVar
; To send the array use ...
@ TX_STR?B _StrArray, _ByteVar
It's probably a bit confusing, so let me know if it doesn't make sense.
<br>
Bookmarks