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 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 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 ALE EQU P3.4 OE EQU P3.2 SC EQU P3.3 E EQU P1.7 MYDATA EQU P0 COUNT EQU 3 ORG 0000h ; power up and reset vector SJMP START ORG 0060h START: MOV P2,#0FFH ;make the ports inputs by writing all 1's to it, PORT 2 IS USED FOR LCD ;DATA PINS MOV MYDATA,#0FFH ;make P0 as input CLR PSW.3 CLR PSW.4 ;select bank 0 MOV A,#00000000b MOV P2,A ;PORT 2 is used for the LCD data pins. SETB E ;MAKE 'E' an input CLR ALE ;clear ALE to me it an output CLR SC CLR OE BACK: ACALL long_delay ;make sure the address is stable SETB ALE ;latch address ACALL delay SETB SC ;start conversion ACALL delay CLR ALE ACALL delay CLR SC HERE: JB E,HERE ;wait till done SETB OE ACALL delay MOV A,MYDATA CLR OE ACALL CONVERSION CONVERSION: ; 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 ;save the ascii 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 ;initialise the LCD before writing any data to it 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: dec r1 ;dec r1 so that it contains thr address of the ascii digit mov a,@r1 ;put the ascii digit in acc from address pointed by r1 acall LCD_senddata ;send data djnz r7,repeat ;repeat until the last digit STAY: SJMP STAY ;stay here when everything is done 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 ;increment cursor,shift cursor to right 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 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 ALE EQU P3.4 OE EQU P3.2 SC EQU P3.3 E EQU P1.7 MYDATA EQU P0 COUNT EQU 3 ORG 0000h ; power up and reset vector SJMP START ORG 0060h START: MOV P2,#0FFH ;make the ports inputs by writing all 1's to it, PORT 2 IS USED FOR LCD ;DATA PINS MOV MYDATA,#0FFH ;make P0 as input CLR PSW.3 CLR PSW.4 ;select bank 0 MOV A,#00000000b MOV P2,A ;PORT 2 is used for the LCD data pins. SETB E ;MAKE 'E' an input CLR ALE ;clear ALE to me it an output CLR SC CLR OE BACK: ACALL long_delay ;make sure the address is stable SETB ALE ;latch address ACALL delay SETB SC ;start conversion ACALL delay CLR ALE ACALL delay CLR SC HERE: JB E,HERE ;wait till done SETB OE ACALL delay MOV A,MYDATA CLR OE ACALL CONVERSION CONVERSION: 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 ;save the ascii 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 ;initialise the LCD before writing any data to it 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: dec r1 ;dec r1 so that it contains thr address of the ascii digit mov a,@r1 ;put the ascii digit in acc from address pointed by r1 acall LCD_senddata ;send data djnz r7,repeat ;repeat until the last digit STAY: SJMP STAY ;stay here when everything is done 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 ;increment cursor,shift cursor to right 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
took help from the book 'The 8051 Micro controller and Embedded Systems' by Muhammed Ali Mazidi'. The ADC interface chapter uses these D flip-flops. 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 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 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 ALE EQU P3.4 OE EQU P3.2 SC EQU P3.3 E EQU P1.7 MYDATA EQU P0 COUNT EQU 3 ORG 0000h ; power up and reset vector SJMP START ORG 0060h START: MOV P2,#0FFH ;make the ports inputs by writing all 1's to it, PORT 2 IS USED FOR LCD ;DATA PINS MOV MYDATA,#0FFH ;make P0 as input CLR PSW.3 CLR PSW.4 ;select bank 0 MOV A,#00000000b MOV P2,A ;PORT 2 is used for the LCD data pins. SETB E ;MAKE 'E' an input CLR ALE ;clear ALE to me it an output CLR SC CLR OE BACK: ACALL long_delay ;make sure the address is stable SETB ALE ;latch address ACALL delay SETB SC ;start conversion ACALL delay CLR ALE CLR SC HERE: JB E,HERE ;wait till done SETB OE ACALL delay MOV A,MYDATA CLR OE ; ACALL CONVERSION acall delay CONVERSION: ; MOV P0,#11110001b ;PUTTING A RANDOM BINARY VALUE IN PORT0 MOV R0,#RAM_ADDR ;save DEC digits in these RAM locations MOV A,MYDATA ;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 ;save the ascii 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 ;initialise the LCD before writing any data to it 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: dec r1 ;dec r1 so that it contains thr address of the ascii digit mov a,@r1 ;put the ascii digit in acc from address pointed by r1 acall LCD_senddata ;send data djnz r7,repeat ;repeat until the last digit STAY: SJMP STAY ;stay here when everything is done 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 ;increment cursor,shift cursor to right 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
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?