I'm doing a software serial routines for a 1Mhz 65xx device that needs to communicate at 57600 bit/s. But my receive code does not work.
57600 gives 17 cycles per bit.
Data comes in negated and it comes in on portb's D6. Protocol is
Startbit-Databits-Stopbit (8N1)
#cycle is a macro that inserts n cycles of code (not touching registers, flags may be touched) and .rept is a repeating macro.
Here's the code. Resulting byte should be in A. Bit sampling is always at 17 cycle interval (or so I believe)
Anyone can see where I've gone wrong?
Code: Select all
readbyte bit portb ; data comes in on portb.6
bvc readbyte ; startbit?
#cycle #25 ; wait ~ 1,5 bit time
.rept 8 ;read the bits
bit portb
bvc ?bt1
clc
ror @
bvs ?nx
?bt1 sec
ror @
#cycle #3
?nx
#cycle #4
.endr
rts
Cheers