First Serial Communication Program! :D
I just finished writing this program in asm for talking to a computer with standard serial board settings - 9600,1n8.
I was pretty excited when I finally saw "1"'s come pouring out of the serial port haha
Any suggestions or comments are welcome
I was pretty excited when I finally saw "1"'s come pouring out of the serial port haha
org 0
serial_interface
mov dira,tx
mov n_data_bits,#8
waitpeq inp,inp 'wait until send button is pressed
mov outa,tx 'send start bit
mov time_t,cnt
add time_t,delay_t
waitcnt time_t,delay_t
:main_loop 'send data
ror data_t,#1 wc
muxc outa,tx
waitcnt time_t,delay_t
djnz n_data_bits,#:main_loop wz
or outa,tx 'send stop bit
waitcnt time_t,delay_t
xor outa,tx
waitcnt time_t,delay_t
mov n_data_bits,#8 'restart counter and start again
jmp #:main_loop
data_t long $0000_0031
inp long $0001_0000
tx long $4000_0000
rx long $8000_0000
delay_t long 8333
n_data_bits res 1
time_t res 1
fit
Any suggestions or comments are welcome
Comments
This may help for a reference:
http://en.wikipedia.org/wiki/File:Rs232_oscilloscope_trace.svg
Try something like this...
DAT org 0 serial_interface mov outa, tx 'preset tx pin HIGH mov dira, tx 'make tx pin an OUTPUT waitpeq inp, inp 'wait until send button is pressed mov time_t, delay_t add time_t, cnt :byte_start mov temp1, data_t or temp1, #%100000000 'Set Stop Bit shl temp1, #1 'Set Start Bit mov n_data_bits,#10 '8 data bits plus 1 Start and 1 Stop bit :main_loop 'send data ror temp1, #1 wc muxc outa, tx waitcnt time_t, delay_t djnz n_data_bits,#:main_loop waitcnt time_t, delay_t 'idle delay = 1 bit jmp #:byte_start 'restart ; send byte again data_t long $0000_0031 inp long $0001_0000 tx long $4000_0000 rx long $8000_0000 delay_t long 8333 n_data_bits res 1 time_t res 1 temp1 res 1 fit
I'm aware of the 3 empty bytes. I'm planning on revising this for receiving data from a device.
I think when the desired result is a low bit and not just a change of a bit's state, it makes more sense to use "andn" since it doesn't require the bit start high to end up low.