We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hello,
I need to implement a software USART in FX2 using Port E.I have program for UART. I wanted to include a clock to it . I have sync problem. More over Iam not able to assign port E for FX2 in KEIL . It has port 0,1,2,3 only.Iam using assembler program. Iam posting the code .Any help will be appricated
PUBLIC _putc txd_pin EQU P3.7 ;Transmit on this pin CS EQU P3.3 ;CHIP SELECT clk EQU P3.0 ;CLK //;Formula to calculate the bit time delay constant ;This constant is calculated as: (((crystal/baud)/12) - 5) / 2 ;crystal is the frequency of crystal in Hz ;baud is required baudrate ;Please try to keep baudrate below 9600 ;to get best results :-) BITTIM EQU 45; (((11059200/9600)/12) - 5) / 2 LOOkUp: DB 03H,05H _main: MOV DPTR,#0000 ;load address from lable CLR CLK CLR CS MOV R2,#1 lcall _putc _putc: CLR A ;clear A MOVC A,@A+DPTR ;load data from address pointed by A+DPTR MOV R1,#8 ;Send 8 bits putc1: RRC A MOV txd_pin,C ;write next bit SETB CLK MOV R0,#BITTIM ;Wait full bit-time DJNZ R0,$ ;For DATA bit CLR CLK MOV R0,#BITTIM ;Wait full bit-time DJNZ R0,$ ;For DATA bit DJNZ R1,putc1 ;write 8 bits INC DPTR DJNZ R2,_putc SETB CS ;Set chip select line high ;CLR A MOV DPTR,#0000 ;load address from lable RET ;For STOP bit END
Punitha
_main: MOV DPTR,#0000 ;load address from lable CLR CLK CLR CS MOV R2,#1 *1 lcall _putc *2_putc:CLR A ;clear A MOVC A,@A+DPTR ;load data from address pointed by A+DPTR
*1 why the lcall, the program will go to _putc: anyhow *1, *2 that is NOT a comments, it is "instruction explanations" anyone needing "instruction explanations' has no buiness reading '51 asm code.
Erik
"*1 why the lcall, the program will go to _putc: anyhow"
Not quite. It will call _putc, return and then fall through to putc.
That's not an uncommon situation for (for example) sending high then low nibbles to an output routine.
for example:
OpAsTwoBytes: ... MOV A,B PUSH B SWAP A ANL A,#0Fh ORL A,#'0' LCALL OpNibble POP ACC ANL A,#0Fh ORL A,#'0' OpNibble: ... RET
(Please imagine comments exist in that snippet!)
However ... I don't think that can be what is intended here and it will finally RET from _main, which is none too smart.