free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Go to page  [1] 2
Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
Freddy
Mon Jul 28 2008, 11:37PM

 User Offline
Registered Member #9399
Joined: Mon Jul 28 2008, 10:01PM

Posts: 37
Thanked 0 times in 0 posts
Hi everyone, I'm new in the forum. This is a good website.
Now, this my problem, the output of the ADC seems to give a weak output ( measured 1.1 V using multimeter). I would appreciate anyone helping

Problem Hints :
Hardware : AT89S51, ADC 0844 and 1x16 LCD
Case 1 : LCD displayed 00 when I include the line "acall clr_mux_add"
Case 2 : LCD displayed 05, 04, 00 (randomly )when I exclude the line "acall clr_mux_add"

Port 3.0 and 3.1 are connected to separated LEDs, so I can observed the program flow, that's all.

I programed the ADC based on the timing diagram given in the datasheet. (at the bottom of page)

From calculation, I should get 15 or 14 decimal displayed on my LCD, but I get 05 instead, I suspected this is because it displayed the MUX Address.
15 decimal = 0000 1111 b (but the 1's are measured to be 1.1 V)

Thanks for reading.

CODE:

WR_adc equ P3.5
RD_adc equ P3.7
DAT_ADC equ P2  ;ADC data pins P2

start :
acall clear_lcd        
                                          acall conv_adc
                                          acall read_adc
                                          acall byte_to_bcd
                                          acall write_text
                                          mov A, r0
                                          acall write_text
                                          setb P3.0
                                          acall delay_1sec         ;12
                                          clr P3.0             
                                          sjmp start

conv_adc :
           clr CS
           setb P3.1
           acall delay_500ms      ;1
           clr P3.1

           clr wr_adc
           setb P3.0
           acall delay_500ms     ;2
           clr P3.0

           nop
           acall mux_add ;set MA0-MA3 to 0101[using channel 2]
           setb P3.1
           acall delay_500ms      ;3
           clr P3.1

           nop
           setb wr_adc
           setb P3.0
           acall delay_500ms      ;4
           clr P3.0

           nop
           setb cs
           setb P3.1
           acall delay_500ms       ;5
           clr P3.1       
           
           acall clr_mux_add  

           acall delay_50us
           wait : jb intr_adc, wait

           setb P3.0
           acall delay_500ms             ;6
           clr P3.0

           ret

read_adc :
clr cs
                   setb P3.1
                   acall delay_500ms       ;7
                    clr P3.1

                   clr rd_adc
                   setb P3.0
                   acall delay_1sec        ;8
                   clr P3.0
                   
                   nop
                   mov A, DAT_ADC  ;move ADC 8 bit result to A
                   ;mov adc_val, A
                   setb P3.1
                   acall delay_500ms       ;9
                   clr P3.1              

                  setb rd_adc
                   setb P3.0
                   acall delay_500ms       ;10
                   clr P3.0
                   
                  nop
                  setb cs
                   setb P3.1
                   acall delay_500ms       ;11
                  clr P3.1
                   ret

mux_add :
 setb P2.0       ;this configuration is using channel 2 single ended
                  clr P2.1
                  setb p2.2
                  clr P2.3
                  ret

clr_mux_add :
clr P2.0
                          clr P2.1
                          clr P2.2
                          clr P2.3
                          ret











[ Edited Tue Jul 29 2008, 01:48AM ]


Build target 'Target 1''
linking...
Program Size: data=8.0 xdata=0 code=709
creating hex file from "Final Year Project"...
"Final Year Project" - 0 Error(s), 0 Warning(s).
Back to top


Ajay
Tue Jul 29 2008, 08:17AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3681
Thanked 684 times in 646 posts
try using interrupt..
you are wasting more time on making LEDs low high
so interrupt will solve your problem

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top



This post has been thanked 1 time
 Freddy 
Freddy
Tue Jul 29 2008, 10:07AM

 User Offline
Registered Member #9399
Joined: Mon Jul 28 2008, 10:01PM

Posts: 37
Thanked 0 times in 0 posts
aaa, thanks for idea.... is there any other way ?



Build target 'Target 1''
linking...
Program Size: data=8.0 xdata=0 code=709
creating hex file from "Final Year Project"...
"Final Year Project" - 0 Error(s), 0 Warning(s).
Back to top


Freddy
Tue Jul 29 2008, 12:32PM

 User Offline
Registered Member #9399
Joined: Mon Jul 28 2008, 10:01PM

Posts: 37
Thanked 0 times in 0 posts
Hi again, i've found the solution ( i think so) , all i did is add the highlighted line (compare with code above).




all thx to : http://www.8051projects.net/downloads84.html

because on page 59, i found this :




if it wasn't for Ajay, i wouldn't go hay-wire finding info about interrupts... hahaha , so thx Ajay.
now, the temperature displayed a more "make sense" value. Now i only use 0.5 sec of temperature sampling.


New problem :
The temperature reading is not so stable. It changes to different value too rapidly.
So, any engineering ideas are seriously welcomed !!



Build target 'Target 1''
linking...
Program Size: data=8.0 xdata=0 code=709
creating hex file from "Final Year Project"...
"Final Year Project" - 0 Error(s), 0 Warning(s).
Back to top


Arun Kumar V
Tue Jul 29 2008, 06:54PM

 User Offline
Registered Member #426
Joined: Sun Jan 28 2007, 11:50PM

Posts: 427
Thanked 178 times in 149 posts


hi freddy,

acall clear_lcd


why are you clearing the LCD every time in start loop ? if you are using two channels then one channel reading can be placed on line 1 and other channel data on line 2 of lcd.

if you are using only one ch, then you need not clear the LCD every time.





Arun
Back to top



This post has been thanked 1 time
 Freddy 
Freddy
Tue Jul 29 2008, 09:52PM

 User Offline
Registered Member #9399
Joined: Mon Jul 28 2008, 10:01PM

Posts: 37
Thanked 0 times in 0 posts
I only use 1 channel of the ADC.
When i remove the acall clear_lcd , the display would be continuous.
Something like this : 100F0F10




or maybe i understood u wrongly ??


Build target 'Target 1''
linking...
Program Size: data=8.0 xdata=0 code=709
creating hex file from "Final Year Project"...
"Final Year Project" - 0 Error(s), 0 Warning(s).
Back to top


Arun Kumar V
Tue Jul 29 2008, 11:56PM

 User Offline
Registered Member #426
Joined: Sun Jan 28 2007, 11:50PM

Posts: 427
Thanked 178 times in 149 posts


Hi Freddy,

you have posted only part of the code, pl.post full code so that we can analyze other subroutines and find the error.

since you are using 1 ch and not switching between channels, it is not required to clear the LCD after every cycle.


Arun
Back to top


Freddy
Wed Jul 30 2008, 03:09AM

 User Offline
Registered Member #9399
Joined: Mon Jul 28 2008, 10:01PM

Posts: 37
Thanked 0 times in 0 posts
owh okok, sorry about that. I'm just a beginner.

CODE:

;Information :
;the code is initilaise as 2x16 although it is 1x16
;because of the 8+8 configuration.
;the ninth position start at the address 40h
;[00 01 02 03 04 05 06 07 41 42 43 44 45 46 47]
;#07h --> shift display to the left
ORG 0000H

mov P0, #00h
mov P1, #00h
mov P2, #00h
mov P3, #00h

MOV TMOD, #0x01

RS_lcd EQU P1.2
RW_lcd EQU P1.1
EN_lcd EQU P1.0
DAT_lcd EQU P0          ;LCD PORT for DB0 to DB7

INTR_adc equ P3.4
WR_adc equ P3.5
CS_adc equ P3.6
RD_adc equ P3.7
DAT_ADC equ P2          ;ADC data pins P2
mux_add equ 30h

aCALL INIT_LCD

setb P3.5
clr P3.6
setb P3.7
mov mux_add, #00000101b ;channel 2, single-ended mode
;==============================================================
disp_str macro string           ;Macro for sending string to LCD
                 irpc char, <string>
                 if nul 'char'
                 exitm
                 endif
                 mov a,#'char'
                 lcall write_text
                 endm
                 endm

start :
acall clear_lcd
acall conv_adc
disp_str <Temp:>
mov dat_lcd, #85h       ;80h + 05h (instruction + lcd mapping address)
setb en_lcd
acall delay_2ms
clr en_lcd

mov P2, 0xFF            ;configure to read from port 2
acall read_adc
acall byte_to_bcd              
acall write_text   ;display upper nibble
mov A, r0            ;display lower nibble
acall write_text
acall delay_500ms       
sjmp start

conv_adc :
clr wr_adc
nop
mov dat_adc, mux_add ;load mux address into A
nop
setb wr_adc
wait : jb intr_adc, wait             
ret

read_adc :
clr rd_adc
nop
mov A, DAT_ADC  ;move ADC 8 bit result to A
nop
setb rd_adc
nop
ret
;==========================================================
;this subroutine converts 8-bit data to bcd
;both high nibble and low nibble are in hex value
;input is taken from A
;the output high nibble is A (hex value)
;the output low nibble is in r0 (also hex value)
byte_to_bcd:
    MOV     R0,A
    ANL     A,#0Fh
    ADD     A,#0F6h
    JNC     byte_to_bcd_2
    ADD     A,#07h
byte_to_bcd_2:
    ADD     A,#3Ah
    XCH     A,R0
    SWAP    A
    ANL     A,#0Fh
    ADD     A,#0F6h
    JNC     byte_to_bcd_3
    ADD     A,#07h
byte_to_bcd_3:
    ADD     A,#3Ah
    RET 
;===========================================================
WAIT_LCD :  
acall DELAY_2ms                
RET

INIT_LCD :  
clr en_lcd
CLR RS_lcd
clr rw_lcd
MOV DAT_lcd, #38h  ;initialize lcd as 2x16                       
SETB EN_lcd
acall DELAY_2ms
CLR EN_lcd
aCALL WAIT_LCD

clr en_lcd
CLR RS_lcd
clr rw_lcd
MOV DAT_lcd,#0Ch        ;no cursor, no blinking of cursor                
SETB EN_lcd
acall DELAY_2ms
CLR EN_lcd
aCALL WAIT_LCD

clr en_lcd
CLR RS_lcd
clr rw_lcd
MOV DAT_lcd,#06h                       
SETB EN_lcd
acall DELAY_2ms
CLR EN_lcd
aCALL WAIT_LCD

clr en_lcd
CLR RS_lcd
clr rw_lcd
MOV DAT_lcd,#14h
SETB EN_lcd
acall DELAY_2ms
CLR EN_lcd
aCALL WAIT_LCD
RET

CLEAR_LCD :     
clr en_lcd
CLR RS_lcd
clr rw_lcd
MOV DAT_lcd,#01h                       
SETB EN_lcd
acall DELAY_2ms
CLR EN_lcd
aCALL WAIT_LCD
RET

WRITE_TEXT :
clr en_lcd
SETB RS_lcd
clr rw_lcd
 MOV DAT_lcd, A                  
SETB EN_lcd
 acall DELAY_2ms
CLR EN_lcd
aCALL WAIT_LCD
RET
;===========================================================================
;Delay subroutines...
DELAY_50us: MOV R5, #1          ;this is a 50 micro second delay subroutine       
REPEAT_4:MOV TH0, #0xFF
                MOV TL0, #0xD2
                SETB TR0
BACK_4: JNB TF0, BACK_4
                CLR TR0
                CLR TF0
                DJNZ R5, REPEAT_4
                RET

DELAY_33ms: MOV R5, #100                ;this is a 33 mili second delay subroutine       
REPEAT_3:MOV TH0, #0xFE
                MOV TL0, #0xCF
                SETB TR0
BACK_3:  NB TF0, BACK_3
                 CLR TR0
                CLR TF0
                DJNZ R5, REPEAT_3
                RET

DELAY_2ms:  MOV R5, #100                ;this is a 2ms delay subroutine   
REPEATMOV TH0, #0xFF
                MOV TL0, #0xEE
                SETB TR0
BACK:   JNB TF0, BACK
                CLR TR0
                CLR TF0
                DJNZ R5, REPEAT
                RET

DELAY_500ms: MOV r5, #100               ;this is a 0.5 second delay subroutine   
REPEAT_2:MOV TH0, #0xEE
                MOV TL0, #0x00
                SETB TR0
BACK_2: JNB TF0, BACK_2
                CLR TR0
                CLR TF0
                DJNZ r5, REPEAT_2
                RET
                       
DELAY_1sec: MOV R5, #100                ;this is a 1 second delay subroutine     
REPEAT_1:MOV TH0, #0xD8
                MOV TL0, #0xF0
                SETB TR0
BACK_1: JNB TF0, BACK_1
                CLR TR0
                CLR TF0
                DJNZ R5, REPEAT_1
                RET                                                    
END
 



Build target 'Target 1''
linking...
Program Size: data=8.0 xdata=0 code=709
creating hex file from "Final Year Project"...
"Final Year Project" - 0 Error(s), 0 Warning(s).
Back to top


Arun Kumar V
Wed Jul 30 2008, 07:30AM

 User Offline
Registered Member #426
Joined: Sun Jan 28 2007, 11:50PM

Posts: 427
Thanked 178 times in 149 posts
Hi Freddy,

first things first :

mov P0, #00h
mov P1, #00h
mov P2, #00h
mov P3, #00h


this is a big No-No, on reset all the ports are 0FFh by default so lets keep it that way.

in subroutine byte_to_bcd:

ADD A,#3Ah


it should be #30H ( since you are converting into Ascii for sending it to LCD), also i doubt if this routine is right, bcoz to display FFh you need 3 digits in BCD i,e 255 but you are displaying only 2 digits ( A & R0)

you can use the following routine, which converts 1 byte Hex to 3 digit decimal ( you need to declare the variables - hundreds, tens & ones):

CODE:
Bin2Dec:
       mov b,#100d
       div ab
       mov hundreds,a
       mov a,b
       mov b,#10d
       div ab
       mov tens,a
       mov ones,b
       ret      


and when dispatching to LCD, just add or ORL #30h to hunds, tens & ones


in the DELAY_1sec rountine,
MOV TH0, #0xD8
MOV TL0, #0xF0


the timer reload values are wrong, you haven't mentioned the xtal Freq but i guess you are using 11.0592Mhz

it should be :
CODE:
MOV TH0,#0DCH  ;  10mSec X 100(R5)  = 1000mS
                      MOV TL0,#00H


make these changes and check if the LCD displays correctly

PS: i hope the interfacing sequence to the ADC is correct ( write/read ).

All the Best !


Arun
Back to top



This post has been thanked 1 time
 Freddy 
Freddy
Wed Jul 30 2008, 10:20PM

 User Offline
Registered Member #9399
Joined: Mon Jul 28 2008, 10:01PM

Posts: 37
Thanked 0 times in 0 posts
wow Arun, now I can display the results in decimal value instead of hex. Thanks
I recalculate the formula, I still think that my 1 second delay is correct. I'm using 11.0592 MHz

100 x (65536-55536) x 1.085 us = 1.085 sec ( approx. 1 sec)
(1/11.0592 Mhz) / 12 = 921,600 Hz
1 / 921,600 = 1.085 us
D8F0h = 55536

Now, my problem is :
The temperature reading is fluctuating from 14-18 at room temperature ( i set Vref of ADC to Vcc=4.9 V). From calculation, I should get 15 or 16.

I suspected this is because of I didn't have any signal conditioning circuit for the ADC analog input. Can this be the problem ??




Vin is from LM35 temp sensor = 0.29 V
stepsize for ADC = 4.90 V / 256 = 19 mV
Dout is in decimal
0.29 / 19mV = 15.263


CODE:

;Information :
;the code is initilaise as 2x16 although it is 1x16
;because of the 8+8 configuration.
;the ninth position start at the address 40h
;[00 01 02 03 04 05 06 07 41 42 43 44 45 46 47]
;#07h --> shift display to the left
ORG 0000H

MOV TMOD, #0x01

RS_lcd EQU P1.2
RW_lcd EQU P1.1
EN_lcd EQU P1.0
DAT_lcd EQU P0          ;LCD PORT for DB0 to DB7

INTR_adc equ P3.4
WR_adc equ P3.5
CS_adc equ P3.6
RD_adc equ P3.7
DAT_ADC equ P2          ;ADC data pins P2
mux_add equ 30h
hundreds equ 31h
tens equ 32h
ones equ 33h

aCALL INIT_LCD

setb P3.5  ;initialize wr_adc high
clr P3.6   ;set cs_adc always low
setb P3.7  ;initialize rd_adc high

clr P3.0 ;off LED connected to P3.0
clr P3.1  ;off LED connected to P3.1

mov mux_add, #00000101b ;MUX address for ADC0844
                                                ;channel 2, single-ended mode
;==============================================================
disp_str macro string           ;Macro for sending string to LCD
                 irpc char, <string>
                 if nul 'char'
                 exitm
                 endif
                 mov a,#'char'
                 lcall write_text
                 endm
                 endm

start : acall clear_lcd
                acall conv_adc
                disp_str <Temp:>
                mov P2, 0xFF            ;configure to read from port 2
                acall read_adc
                acall bin2dec
                acall ascii4lcd_tens           
                acall write_text   ;write tens to LCD
                acall ascii4lcd_ones     
                acall write_text   ;write ones to LCD

                clr en_lcd
                clr rs_lcd
                clr rw_lcd
                mov dat_lcd, #0C0h ;80h + 40h (instruction + lcd mapping address)
                setb en_lcd
                acall delay_2ms
                clr en_lcd
                acall wait_lcd
                disp_str <Celcius>

                acall delay_500ms       
                sjmp start
;====================================================
Bin2Dec:
       mov b,#100d ;1100 0100
       div ab
       mov hundreds,a
       mov a,b
       mov b,#10d
       div ab
       mov tens,a
       mov ones,b
       ret
;=============================================
ascii4lcd_tens :
add A, #30h     ;add 30h to tens value
ret

ascii4lcd_ones :
mov A, B
add A, #30h
ret
;=========================================================
conv_adc :
           clr wr_adc
           nop
           mov dat_adc, mux_add ;load mux address into A
           nop
           setb wr_adc
           wait : jb intr_adc, wait         
           ret

read_adc : clr rd_adc
                   nop             
                   mov A, DAT_ADC  ;move ADC 8 bit result to A
                   nop
               setb rd_adc
               nop
               ret
;==========================================================
;===========================================================
WAIT_LCD :  acall DELAY_2ms            
            RET

INIT_LCD :  clr en_lcd
                        CLR RS_lcd
                        clr rw_lcd
                MOV DAT_lcd, #38h  ;initialize lcd as 2x16                       
                SETB EN_lcd
                        acall DELAY_2ms
                        CLR EN_lcd
                aCALL WAIT_LCD

                        clr en_lcd
                CLR RS_lcd
                        clr rw_lcd
                MOV DAT_lcd,#0Ch        ;no cursor, no blinking of cursor                
                SETB EN_lcd
                        acall DELAY_2ms
                CLR EN_lcd
                aCALL WAIT_LCD

                        clr en_lcd
                CLR RS_lcd
                clr rw_lcd
                        MOV DAT_lcd,#06h                       
                SETB EN_lcd
                        acall DELAY_2ms
                CLR EN_lcd
                aCALL WAIT_LCD

                        clr en_lcd
                    CLR RS_lcd
                        clr rw_lcd
                MOV DAT_lcd,#14h
                        SETB EN_lcd
                        acall DELAY_2ms
                CLR EN_lcd
                aCALL WAIT_LCD
                        RET

CLEAR_LCD :     clr en_lcd
                        CLR RS_lcd
                        clr rw_lcd
                MOV DAT_lcd,#01h                       
                SETB EN_lcd
                        acall DELAY_2ms
                CLR EN_lcd
                aCALL WAIT_LCD
                RET

WRITE_TEXT : clr en_lcd
                         SETB RS_lcd
                 clr rw_lcd
                         MOV DAT_lcd, A                  
                 SETB EN_lcd
                         acall DELAY_2ms
                 CLR EN_lcd
                 aCALL WAIT_LCD
                 RET
;===========================================================================
;Delay subroutines...
DELAY_50us: MOV R5, #1          ;this is a 50 micro second delay subroutine       
REPEAT_4:       MOV TH0, #0xFF
                        MOV TL0, #0xD2
                        SETB TR0
BACK_4:         JNB TF0, BACK_4
                        CLR TR0
                        CLR TF0
                        DJNZ R5, REPEAT_4
                        RET

DELAY_33ms: MOV R5, #100                ;this is a 33 mili second delay subroutine       
REPEAT_3:       MOV TH0, #0xFE
                        MOV TL0, #0xCF
                        SETB TR0
BACK_3:         JNB TF0, BACK_3
                        CLR TR0
                        CLR TF0
                        DJNZ R5, REPEAT_3
                        RET

DELAY_2ms:  MOV R5, #100                ;this is a 2ms delay subroutine   
REPEAT:         MOV TH0, #0xFF
                        MOV TL0, #0xEE
                        SETB TR0
BACK:           JNB TF0, BACK
                        CLR TR0
                        CLR TF0
                        DJNZ R5, REPEAT
                        RET

DELAY_500ms: MOV r5, #100               ;this is a 0.5 second delay subroutine   
REPEAT_2:       MOV TH0, #0xEE
                        MOV TL0, #0x00
                        SETB TR0
BACK_2:         JNB TF0, BACK_2
                        CLR TR0
                        CLR TF0
                        DJNZ r5, REPEAT_2
                        RET
                       
DELAY_1sec: MOV R5, #100                ;this is a 1 second delay subroutine     
REPEAT_1:       MOV TH0, #0xD8
                        MOV TL0, #0xF0
                        SETB TR0
BACK_1:         JNB TF0, BACK_1
                        CLR TR0
                        CLR TF0
                        DJNZ R5, REPEAT_1
                        RET                                                    
END
 



Build target 'Target 1''
linking...
Program Size: data=8.0 xdata=0 code=709
creating hex file from "Final Year Project"...
"Final Year Project" - 0 Error(s), 0 Warning(s).
Back to top


Go to page  [1] 2  

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems