ijp
Banned
- Joined
- Dec 30, 2014
- Messages
- 20
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 0
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
Code C - [expand] 1 MOV P2,#0FFH
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 108 109 110 111 112 113 114 115 116 117 118 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 SJMP 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: clr a 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 setb LCD_en acall delay clr LCD_en ;Enable H->L acall delay repeat: clr a dec r1 ;mov a,r1 ;dec a ;mov r0,a mov a,@r1 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 SETB LCD_en acall delay CLR LCD_en ;Enable H->L ;acall delay ret LCD_init: mov LCD_data,#0EH ;Display on, Curson blinking command clr LCD_rs ;Selected instruction register setb LCD_en acall delay clr 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 setb LCD_en acall delay clr LCD_en ;Enable H->L acall delay mov LCD_data,#06H ;Function Set 2-line mode (even for 16x1!) clr LCD_rs ;Selected instruction register setb LCD_en acall delay clr 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
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 108 109 110 111 112 113 LCD_data equ P2 ;LCD Data port LCD_rs equ P3.7 ;LCD Register Select LCD_rw equ P3.6 ;LCD Read/Write LCD_en equ P3.5 ;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_rw ;We are writing in instruction register acall long_delay lcall LCD_init mov LCD_data,#80H ;position cursor clr LCD_rs ;Selected instruction register setb LCD_en acall delay clr LCD_en ;Enable H->L acall delay repeat: clr a dec r0 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 setb LCD_en acall delay clr 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 setb LCD_en acall delay clr 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 setb LCD_en acall delay clr LCD_en ;Enable H->L acall delay mov LCD_data,#06H clr LCD_rs ;Selected instruction register setb LCD_en acall delay clr LCD_en ;Enable H->L acall delay ret delay: mov r2, #50 wait_0: mov r3, #0FFh ;reg2 and reg3 wait_1: djnz r3, wait_1 djnz r2, wait_0 ret long_delay: mov r2, #01h ;initialise counters wait_2: mov r3, #07fh ;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
repeat: clr a
dec r0
mov a,@r0
acall LCD_senddata
djnz r7,repeat
STAY: SJMP STAY
Code ASM - [expand] 1 2 3 4 5 6 7 repeat: clr a dec r1 mov a,@r1 acall LCD_senddata djnz r7,repeat STAY: SJMP STAY
repeat: clr a
dec r1
mov a,@r1
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
SETB LCD_en
acall delay
CLR LCD_en ;Enable H->L
acall delay
ret
LCD_data equ P2 ;LCD Data port
LCD_rs equ P3.7 ;LCD Register Select
LCD_rw equ P3.6 ;LCD Read/Write
LCD_en equ P3.5 ;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_rw ;We are writing in instruction register
acall long_delay
lcall LCD_init
mov LCD_data,#80H ;position cursor
clr LCD_rs ;Selected instruction register
setb LCD_en
acall delay
clr LCD_en ;Enable H->L
acall delay
repeat: clr a
dec r1
mov a,@r1
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
setb LCD_en
acall delay
clr 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
setb LCD_en
acall delay
clr 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
setb LCD_en
acall delay
clr LCD_en ;Enable H->L
acall delay
mov LCD_data,#06H
clr LCD_rs ;Selected instruction register
setb LCD_en
acall delay
clr LCD_en ;Enable H->L
acall delay
ret
delay:
mov r2, #50
wait_0:
mov r3, #0FFh ;reg2 and reg3
wait_1:
djnz r3, wait_1
djnz r2, wait_0
ret
long_delay:
mov r2, #01h ;initialise counters
wait_2:
mov r3, #07fh ;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
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 ;==================================================================== ; Main.asm file generated by New Project wizard ; ; Created: Sat Jan 3 2015 ; Processor: AT89C51 ; Compiler: ASEM-51 (Proteus) ;==================================================================== $NOMOD51 $INCLUDE (8051.MCU) RS EQU P3.7 EN EQU P3.6 ;WR EQU P2.5 ORG 0000H LJMP MAIN MSG1: DB 'lcd display',0H MSG2: DB 'assembly level programing',0H ;******************** DELAY_SET: ;******************** MOV R2,#5 L1: MOV TH1,# HIGH(-50000) MOV TL1,# LOW(-50000) SETB TR1 JNB TF1,$ CLR TF1 CLR TR1 DJNZ R2,L1 RET ;******************** DELAY: ;******************** MOV TH0,# HIGH(-50000) MOV TL0,# LOW(-50000) SETB TR0 JNB TF0,$ CLR TF0 CLR TR0 RET ;******************** WRITE_CMD: ;******************** CLR RS MOV P2,A SETB EN CLR EN LCALL DELAY RET ;******************** WRITE_CHAR: ;******************** SETB RS MOV P2,A SETB EN CLR EN LCALL DELAY RET ;******************** INITIALIZE_LCD: ;******************** MOV A,#38H ;FUNCTION SET LCALL WRITE_CMD MOV A,#0CH ;DISPLAY ON/OFF AND CURSOR LCALL WRITE_CMD MOV A,#06H ;CHARACTER ENTRY MODE LCALL WRITE_CMD RET ;******************** GOTO_ADDRESS: ;******************** ADD A,#80H LCALL WRITE_CMD RET ;******************** WRITE_STRING: ;******************** MOV R1,#0 RPT: MOV A,R1 MOVC A,@A+DPTR JZ EXIT LCALL WRITE_CHAR INC R1 LJMP RPT EXIT: RET ;******************** CLEAR_LCD: ;******************** MOV A,#01H LCALL WRITE_CMD RET ;******************** MAIN: ;******************** MOV TMOD,#11H LCALL INITIALIZE_LCD L2: mov a, #250 ; value to convert acall hextoascii ; convert value MOV A,#00H LCALL GOTO_ADDRESS MOV a,r0 LCALL WRITE_CHAR ;LCALL DELAY_SET MOV A,#01H LCALL GOTO_ADDRESS MOV a,r1 LCALL WRITE_CHAR ;LCALL DELAY_SET MOV A,#02H LCALL GOTO_ADDRESS MOV a,r2 LCALL WRITE_CHAR LCALL DELAY_SET LJMP L2 hextoascii: mov r0,#30h mov r1,#30h mov r2,#30h clr c mov b,#100 div ab orl a,r0 mov r0,a clr c mov a,b mov b,#10 div ab orl a,r1 mov r1,a mov a,b orl a,r2 mov r2,a ret END
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?