Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[51] How to interface ADC0808 with 8051 and LCD using assembly language

Status
Not open for further replies.

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. ;-)


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:

ijp

Banned
Joined
Dec 30, 2014
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
0
not really. At the moment I am not using an ADC, I am just putting a random value for example P0 has 11110001, and I converted this to ascii -241, stored this value in RAM location 42h,41h and 40h respectively and I am trying to display this taking from the RAM to the LCD screen, but it does not display anything on the screen,however the curser position is moving in the place where i want to display the digits. But no digit is displayed.
Can you please have a look at the code, i really need to get this solved as soon as possible :) thank you
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
You are making P2 input type. You should make it output type by clearing P2 or writing 0x00 to P2 initially as it is used for LCD data.


Code C - [expand]
1
MOV P2,#0FFH



P0 is used for LCD Control. Does the P0 has pull-up resistors ?

Strobing the LCD is making the EN pin high say for 100 us and then making it low. You are doing the reverse. You are making it low and then high.

Read the book "8051 Microcontroller and Embedded System using Assembly and C" by Muhammad Ali Mazidi. It has lcd 8 bit asm and c example codes.

LCD initialization routine is sending commands 0x38, 0x0E, 0x01, 0x06. Then you send row and coloum command like 0x80 and then send lcd data. You use RS bit to decide whether you are sending command or data. You place data or command on P2 and then make en pin high for 100 us and then low.
 
Last edited:
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating

Debasis Swain

Member level 2
Joined
Feb 2, 2013
Messages
52
Helped
10
Reputation
20
Reaction score
10
Trophy points
1,288
Activity points
1,606
Hi,Dear
You are just making some mistakes, so i am editing your code.
so, pls check the following


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

 

ijp

Banned
Joined
Dec 30, 2014
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
0
Thanks a lot for the code but when i run the code, it gives me- 000 on the LCD screen whereas i should be getting 241 on the screem as P0 has 11110001 on it. Please can you post the correct code for me? thank you :)

- - - Updated - - -

Here is a code i wrote again but I still get 000 in the LCD screen instead of 241 :( can you please help fix it?



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

 
Last edited by a moderator:

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
185
Reputation
370
Reaction score
180
Trophy points
1,323
Activity points
6,138
Code:
repeat:   clr a
          
         dec r0
         mov a,@r0
         acall LCD_senddata
         djnz r7,repeat
STAY:    SJMP STAY

I guess you are storing the ASCII value in R1 and reading the data from R0 and displaying it on LCD
 
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating

Debasis Swain

Member level 2
Joined
Feb 2, 2013
Messages
52
Helped
10
Reputation
20
Reaction score
10
Trophy points
1,288
Activity points
1,606
You are just making some error in place of displayed the ascii value, you are using R0 in place of R1 so, check it, also remember that clear the accumulator in place of using the A at pointer. I'm giving the code in before reply so, try to using that code for output
 
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating

ijp

Banned
Joined
Dec 30, 2014
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
0
Hi everyone,
i have fixed the code by clearing the accumulator before using it as a pointer and also using R1 to read the data from and displaying it, but i am getting 000 in the LCD display instead of 241, i have also debugged the code and checked that R1 HAS, 2 4 1 in it when i use
this code part, i dnt know why i am still not getting it:( I need more help..
CODE:

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

 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
185
Reputation
370
Reaction score
180
Trophy points
1,323
Activity points
6,138
Code:
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

as answered earlier
 
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating

ijp

Banned
Joined
Dec 30, 2014
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
0
Yes, I did the same thing as you wrote on the code above, but I am still not getting the right result. If you look at my full code in my previous post, you can see that I have already done the correction but i am still not getting the result. :(
 

ijp

Banned
Joined
Dec 30, 2014
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
0
Here is my full code, it just displays 000 in the lcd. Please compile it and help me out in finding the mistake.
CODE:

Code:
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
 
Last edited by a moderator:

Debasis Swain

Member level 2
Joined
Feb 2, 2013
Messages
52
Helped
10
Reputation
20
Reaction score
10
Trophy points
1,288
Activity points
1,606
I have already test the code which that i have post before. So, test your code which is edited my me and reply

- - - Updated - - -

just test reply-5, and reply
 

ijp

Banned
Joined
Dec 30, 2014
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
0
I have tested the code you edited for me in the reply 5, but that code does not work. It is also giving me 000 on the LCD screen:(
Can you please have a look and test the code again, because it actually does not work for me. I am really tensed.
Thank you.
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
185
Reputation
370
Reaction score
180
Trophy points
1,323
Activity points
6,138

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



Hello i have tested your code and got same result 000 as u mentioned in your early post and after debugging I think your ram read value is wrong or your code not storing the value in RAM i guess due to less time i just build the code display random value in lcd attached here you can see and add your new RAM value logic and test this.I will update on RAM value soon when i will back.
 
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating

Debasis Swain

Member level 2
Joined
Feb 2, 2013
Messages
52
Helped
10
Reputation
20
Reaction score
10
Trophy points
1,288
Activity points
1,606
I have already test the code with hardware and getting the output.So, pls check the hardware connection what you are use.
 
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating

ijp

Banned
Joined
Dec 30, 2014
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
0
So are you saying that my code that i posted in my previous post 15, is correct? Because I think my ram address is correct and R1 is storing the right values. Please confirm me again if my code posted in post 15 is working? I still get 000 on lcd
 
Last edited by a moderator:

Debasis Swain

Member level 2
Joined
Feb 2, 2013
Messages
52
Helped
10
Reputation
20
Reaction score
10
Trophy points
1,288
Activity points
1,606
just one thing do that,just copy my reply-5 code don't change any thing and according to that code connect your rs,rw,and en pins with lcd without your adc interface, and reply
 
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top