Continue to Site

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.
Yes i works fine now. Thank you so much for helping me out with this. Really appreciate a lot for this help everyone.:)
 

Hello everyone, now i am trying to use ADC0808 in my code which is working now. As shown before, I had a random value in Port 0 and was successful in displaying it to the LCD, now I wanted to use and adc to convert a random value generated from a variable voltage connectecd to INO pin of the adc0808. The code asssumes that address A, B and C is connected to ground as only INO is connected to the analoge voltage tested. Can you please have a look at my code and test it if it works? It does not work for me:(.Thank you so much
CODE:

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​

 
Last edited by a moderator:

you code givning error while compiling and put your code with syntax highlighter with asm so easy to read for others. You can just combine your adc0808 and lcd display code if both working fine separately.
 
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating
The LCD bit works. From the conversion bit to the end, the code works separately, but the beginning up till the conversion does not work. It compiles, I checked it. Can you please help me find the error, I am really struggling in this.
Thank you.
 

can you just attached your non working code in txt or zip file here.
 

Yeah sure. Here it is:
ASM CODE:

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
​

 
Last edited by a moderator:

I will try and update you till tomorrow.
code tag.jpgplease use this tag and pest your code in between them ok.
 
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating
Thank you a lot. i will be waiting for your reply:)
 

I have attached the working code.There are some bugs in your code like no clock pin is defined in the code.and I don't know your ADC hardware connection your ADC Vref+ and Vref- connection and output data pins LSB and MSB connection to your controller MSB,LSB connection.

View attachment lcd_adc.rarLCD_adc.jpgLcd_adc1.jpgLcd_adc2.jpg
 
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating
Thank you a lot for the code, but i cannot understand your code properly, for example, i did not understand why you used,'CLOCK EQU P3.4' as you connected P3.4 to ALE of ADC. And i did not understand why you used, '0RG 0BH' and 'LJMP INT_TO'.
Please can you fix my code rather than writing a new one as my code works from the CONVERSION subroutine till the end, just the ADC bit does not work. I am attaching the image of Proteus of my program here for you to understand better.
test.png

- - - Updated - - -

Can you please help me in this as soon as possible. I have used 4 flip flops for clock which is taken from the micro controller AT89S52 directly as you can see. I 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
 

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

If you read the book in detail then your adc connection is missing things like Vref+ has no reference voltage +5V.And as I mentioned your Data pins connections not looking correct.And for 8052 there is no external pull ups resistors there.

And about my code '0RG 0BH' used for timer interrupt vector location. 'LJMP INT_TO'. is for the jump to the timer ISR routine.I connect ADC clock pin to controller P3.4 for generating the clock signal which is done by flip flop in your hardware.

And as I said Your code giving the compilation error to my Proteus simulation .And do proper connection in Proteus Its looks messy use label tool to make connection.

And you can try your code with above changes in your simulation.I think it should work if you compile your code successfully.
 
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating
I have compiled my code in MCU 8051 IDE and it compiles. Also when i put the hex file in Proteus, it runs without any simulation error but i don't see anything in the LCD screen.
Can you please write the code again without using any timer. Can you use external crystal oscillator of 11.095 MHz as I need to use that. Please :)
Thank you so much. I am hoping you can give me the code soon.
 

have you checked with the changes as i suggested in the hardware (Proteus simulation) you code look ok to me but thing just i didn't compile it with my Proteus compiler.so you need change in your simulation.

1 give +5v ref to your adc Vref+ pin
2 add pull ups at P0 (data pins to adc)
3 make your data pins (adc) to mcu connection reverse like ADC out 1 pin to controller P0.7 pin

do this changes and check with your code hex file.It should work.
 
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating
Okay I will do it now and let u know. Thanks a lot.:)
 

Hi,
I have fixed my simulation errors in Proteus and when i click on 'Run' button on Proteus, it runs without any error but still I get nothing on the screen. Here is the diagram on Proteus, I am sorry its a bit messy but can you please check it and let me know what is wrong? I need to get this working this week. help_pic_new.png

- - - Updated - - -

Also here is my code which will help you to identify which ports and pin numbers correspond to what. Can you please check? Thank you:smile:


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​

 
Last edited by a moderator:

Please put all your files like your code,Proteus simulation etc in one folder and make it zip file and attached here.Please don't post code here with out #code or C syntax. this makes forum unreadable.
 
  • Like
Reactions: ijp

    ijp

    Points: 2
    Helpful Answer Positive Rating
I am sorry but I actually did not know how to upload a zip file here. View attachment Desktop.zip

- - - Updated - - -

I have attached a zip file here. Can you please let me know if thats okay. In the zip contains my assembly code, Proteus file, also the hex code for you to test. Thank you. And please let me know soon. I am really appreciating this:)
 

Hi ud23 i am still waiting for your reply. Can you please help me soon?
Thank you
 

hi sorry for late reply ,I was on holiday.Your file has so many changes in your simulation main problem is your clock source is not provided to adc and again your adc conversion and lcd routine looks messy to me any ways I attached the file with necessary changes in Proteus and code.
 

Attachments

  • desktop_updated.rar
    537.4 KB · Views: 56

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top