Here's my situation.
I attempted to create my own RFID reader with the help of an RDM6300 reader module (with UART) with results sent to a computer via a serial cable.
I have already dedicated the 8051 hardware UART to the PC so my only option is to create a software UART to interface with the UART on the RDM6300 module.
I have borrowed ideas from here: https://webcache.googleusercontent.com/search?q=cache:CyacPmYhWY4J:https://www.8051projects.net/wiki/8051_Software_UART_Tutorial+8051+software+uart+asynchronous&num=50&client=opera&hs=ZUz&rls=en&channel=suggest&hl=en&ct=clnk
This is my code:
When I execute it, hex values do appear when the card is on the module but they don't match up with the numbers on the card. Also, I read somewhere that the card byte format must start with a "2" then several bytes then a value "3".
Is the equation (((crystal/baud)/12) - 5) / 2 incorrect for determining bit time? or is there something else I'm doing wrong?
I attempted to create my own RFID reader with the help of an RDM6300 reader module (with UART) with results sent to a computer via a serial cable.
I have already dedicated the 8051 hardware UART to the PC so my only option is to create a software UART to interface with the UART on the RDM6300 module.
I have borrowed ideas from here: https://webcache.googleusercontent.com/search?q=cache:CyacPmYhWY4J:https://www.8051projects.net/wiki/8051_Software_UART_Tutorial+8051+software+uart+asynchronous&num=50&client=opera&hs=ZUz&rls=en&channel=suggest&hl=en&ct=clnk
This is my code:
Code:
RX equ P3.3 ;pin on micro which RDM6300 TX pin connects to
;reset variables
clr TR1
mov P1,#0FFh
mov P3,#0FFh
;enable 9600bps to PC
mov PCON,#80h
mov TH1,#0F4h ;9.6kbps
mov SCON,#50h ;serial mode 1
mov TMOD,#22h ;auto reload for timers
setb TR1
;print init message
mov DPTR,#Minit
lcall lprint
main:
;call serial receive function
lcall surec
;load hex number table and convert received character (in accumulator) to hex
mov DPTR,#hex
mov B,#0Fh
div AB
;do 1st hex character
movc A,@A+DPTR
clr TI
mov SBUF,A
jnb TI,$
;then next character
mov A,B
movc A,@A+DPTR
clr TI
mov SBUF,A
jnb TI,$
;print space
clr TI
mov SBUF,#20h
jnb TI,$
;print anoter space (to make screen look nice)
clr TI
mov SBUF,#20h
jnb TI,$
sjmp main
;print string from memory until character code 0 reached
lprint:
clr A
movc A,@A+DPTR
inc DPTR
jz exitp
clr TI
mov SBUF,A
jnb TI,$
sjmp lprint
exitp:
ret
;calculate bit time based on (((crystal/baud)/12) - 5) / 2
;crystal = 22.1184Mhz, baud=9600
BITTIM equ 0BBh
;and pre-calculate 1/2 bit time
BITTIMH equ 5Dh
;Software Uart RECeive routine
surec:
;wait for start bit (bit=0)
jb RX,$
mov R0,#BITTIMH
djnz R0,$
;wait 1/2 time and if bit is 0, start over
jb RX,surec
;load 8 bits into accumulator waiting 1 bit time for each
mov R1,#8h
clr A
surecl:
mov R0,#BITTIM
djnz R0,$
mov C,RX
RRC A
djnz R1,surecl
clr C
ret
hex:
db '0123456789ABCDEF????',00h
Minit:
db 0Dh,0Ah,0Dh,0Ah,'RFID Card Reader V1.0',0Dh,0Ah,00h
When I execute it, hex values do appear when the card is on the module but they don't match up with the numbers on the card. Also, I read somewhere that the card byte format must start with a "2" then several bytes then a value "3".
Is the equation (((crystal/baud)/12) - 5) / 2 incorrect for determining bit time? or is there something else I'm doing wrong?