ijp
Banned
- Joined
- Dec 30, 2014
- Messages
- 20
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 0
Hi I am really stuggling in displaying a random value,which i inputed manually in a port and then converted it to ASCII digit, on an LCD. The code doesn't give me any error when i simulate it, it just moves the cursor to the 3 positions i want to put the digits in, but does not show anything on the LCD. Here is my code:
Can anyone please tell me what am i missing?
Thank you. ;-)
Can anyone please tell me what am i missing?
Thank you. ;-)
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 LCD_data equ P2 ;LCD Data port LCD_rs equ P0.2 ;LCD Register Select LCD_rw equ P0.1 ;LCD Read/Write LCD_en equ P0.0 ;LCD Enable RAM_ADDR EQU 40H ASCI_RSULT EQU 50H COUNT EQU 3 ORG 0000h ; power up and reset vector AJMP START ORG 0060h START: CONVERSION: MOV P0,#0FFH MOV P2,#0FFH ;make the ports inputs by writing all 1's to it, PORT 2 IS USED FOR LCD ;DATA PINS CLR PSW.3 CLR PSW.4 ;select bank 0 MOV A,#00000000b MOV P2,A ;PORT 2 is used for the LCD data pins. MOV P0,#11110001b ;PUTTING A RANDOM BINARY VALUE IN PORT0 MOV R0,#RAM_ADDR ;save DEC digits in these RAM locations MOV A,P0 ;read data from port 0 MOV B,#10 ;B=0A hex(10dec) DIV AB ;divide by 10 MOV @R0,B ;save lower digit INC R0 MOV B,#10 DIV AB ;divide by 10 once more MOV @R0,B ;save the next digit INC R0 MOV @R0,A ;save the last digit ;Now we convert the DEC digit to displayable ASCII digits MOV R0,#RAM_ADDR ;address of DEC data MOV R1,#ASCI_RSULT ;address of ascii data MOV R2,#3 MOV R7,#3 BACK2: MOV A,@R0 ;get dec digit ORL A,#30H ;make it an ASCII digit MOV @R1,A INC R0 ;next digit INC R1 ;next DJNZ R2,BACK2 ;repeat until the last one ;conversion done INIT: clr LCD_rs ;Selected command register clr LCD_rw ;We are writing in instruction register setb LCD_en ;Enable H->L acall long_delay lcall LCD_init mov LCD_data,#80H ;position cursor clr LCD_rs ;Selected instruction register clr LCD_en acall delay setb LCD_en ;Enable H->L acall delay repeat: mov a,r0 dec a mov r0,a mov a,@r0 acall LCD_senddata djnz r7,repeat STAY: SJMP STAY LCD_senddata: mov LCD_data,A ;Move the command to LCD port setb LCD_rs ;Selected data register clr LCD_en acall delay setb LCD_en ;Enable H->L acall delay ret LCD_init: mov LCD_data,#0FH ;Display on, Curson blinking command clr LCD_rs ;Selected instruction register clr LCD_en acall delay setb LCD_en ;Enable H->L acall delay mov LCD_data,#38H ;Function Set 2-line mode (even for 16x1!) clr LCD_rs ;Selected instruction register clr LCD_en acall delay setb LCD_en ;Enable H->L acall delay ret delay: mov r2, #01h wait_0: mov r3, #0FFh ;reg2 and reg3 wait_1: djnz r3, wait_1 djnz r2, wait_0 ret long_delay: mov r2, #1fh ;initialise counters wait_2: mov r3, #0ffh ;reg2 and reg3 wait_3: mov r4, #0ffh ;reg2 and reg3 wait_4: djnz r4, wait_4 djnz r3, wait_3 djnz r2, wait_2 ret END
Last edited by a moderator: