Monday, December 13, 2010

Assembly language Programm for Interfacing LM35 with 8051controller using ADC0808

Temperature of surrounding is sensed by temperature sensor and it send it's o/p as DC voltage to Analog to digital Converter 0808 through which we give 8 bit value of that voltage to microcontrller 8051.After it's processing it is displayed in LCD ...

ASSEMBLY   LANGUAGE     PROGRAM FOR

                        WEATHER   MONITORING  SYSTEM


                   USING:: 1. MICROCONTROLLER  89C61X2
                                   2.ADC 0808
                               3. TEMPERATURE SENSOR LM35D
;================================================= ==============;

org 0000h
BEGIN:
mov A,#38h                                                ;initialie 2 line LCD
ACALL command
mov A,#0ch                                                  ;LCD on cursor off
ACALL command
mov A,#01h                                                 ;clear LCD
ACALL command
mov A,#06h                                                 ;Shift cursor right
ACALL command
mov A,#'T'
ACALL DISPLY
mov A,#'E'
ACALL DISPLY
mov A,#'M'
ACALL DISPLY
mov A,#'P'            

ACALL DISPLY
mov A,#'='
ACALL DISPLY
 ACALL ADC
ACALL BINTOASC
;;;;;;;;;;;;;;;;;;;;;DISPLAY ASCII NUMBERS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov A,#06h                                                         ;Shift cursor right
ACALL command
mov A,34h                                                        ;Disply MSb of ASCII
ACALL DISPLY
mov A,#06h                                                      ;Shift cursor right
ACALL command
mov A,33h                                                       ;Display middle ASCII
ACALL DISPLY
mov A,#06h                                                     ;Shift cursor right
ACALL command
mov A,32h                                                       ;DISPLAY LSb ASCII
ACALL DISPLY
mov A,#'d'
ACALL DISPLY
mov A,#'C'
ACALL DISPLY
acall delay
acall delay
acall dac                                    ;for analog conversion;;;;
acall delay
sjmp BEGIN                               ;Jump to the top repeat the whole process
;;;;;;;;;;;;;;;;;;;TO INITIALIZE LCD BY;;;;;;;;;;;;;;;;;;;

command:
ACALL READY                                   ;Is LCD ready
mov p0,A                                             ;Issu command
clr p2.7                                           ;RS=0 for comand instruction
clr p2.6                                          ;R/W=0 to write LCD
setb p2.5                                        ;H->L for to latch information in at data lines
clr p2.5
ret
;;;;;;;;;;;;;;;;;;TO DISPLAY USER DATA;;;;;;;;;;;;;;;;;;;;;
DISPLY:
ACALL READY
mov p0,A                                      ;Issu data
setb p2.7                                       ;RS=1 for data
clr p2.6                                         ;R/W=0 to write LCD
setb p2.5                                     ;H->L for to latch information in at data lines
clr p2.5
ret
;;;;;;;;;;;;;;;;;TO CHECK LCD READY TO RECIEVE DATA TO SHOW;;;;;;;;;;;;;;;;;;;;;;;;;
READY:
setb p0.7
clr p2.7                                                ;RS=0 for command register
setb p2.6                                             ;R/W=1 to read command register
BACK:
clr p2.5                                              ;H->L to latch the data
setb p2.5
jb p0.7,BACK                                 ;Busy flag(P1.7)=1 indicates LCD is not ready to recieve data
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;READS ADC DATA;;;;;;;;;;;;;;;;;;;;;;
ADC:
mov p1,#0ffh                                  ; taking port p1 As data input port
clr p3.2                                                    ;L->H for ALE enable
clr p3.5                                                    ;clr sc
setb p3.3                                                     ; for eoc
setb p3.2                                                     ; for ale
clr p3.4                                                         ;oe pin
clr p3..2
setb p3.5                                                          ;SC=1->0
nop
clr p3.5                                                  ;H->L to start conversion
WAIT:
JB p3.3,WAIT                                         ;Wait for end of conversion EOC
 setb p3.4                                              ;OE 1->0 to enable output from ADC
acall delay
mov A,p1                                                       ;Read data
MOV 35H,A
setb p3.4                                                  ;To disable read to start next conversion
setb p3.3                                                    ;eoc
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;BINARY TO ASCII CONVERSION;;;;;;;;;;;;;;;
BINTOASC:
mov A,35h                                                          ;Input from ADC
mov B,#10                                                           ;Divide by 10
div AB
mov r0,B                                                              ;Move remainder into R0
mov B,#10
div AB                                                                   ;Divide quatient by 10
mov r1,b                                                              ;Move remainder in R1
mov r2,A                                                              ;Move quatient in R2
mov A,r1                                                              ;Move second BBCD in A
swap A
orl A,r0                                            ;OR 3rd & 2nd BCD to form compact BCD
mov 30h,A                                       ;Saves 2nd&3rd BCD at RAM location 30h
mov 31h,r2                                         ;Saves 1st BCD at RAM location 31
;;;;;;;;;;;;;;;;;;;;;;;;;;CONVERTION FROM BCD TO ASCII;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov A,30h                                     ;Takes 2nd&3rd BCD from RAM location 30h
ANL A,#0fh                                           ;Mask the upper NIBBLE
orl A,#30h                                              ;Convert lower nibble in ASCII
mov 32h,A                                       ;Save MSb ASCII at RAM location 32H
mov A,30h                                       ;Move BCD into A from RAM location 30H
anl A,#0f0h                                         ;Mask lower NIBBLE of BCD
swap A                                            ;Interchange lower and higher NIBBLE
orl A,#30h                                            ;Convert it in ASCII
mov 33h,A                                          ;Save 2nd ASCII at RAM location 33H
mov A,31h                                        ;Takes 1st BCD from RAM location 31H
anl A,#0fh                                           ;Masks upper nibble
orl A,#30h                                           ;COnvert into ASCII
mov 34h,A                                        ;Saves MSb ASCII at RAM location 34H
ret
;;;;;;;converting data into analog form again;;;;;;;;;;;;;
dac:
    mov a,35h
                mov p1,#00h                                   ;port p1 as o/p port
                setb p3.7                                             ;dac write pin
                acall delay
                mov p1,a
                acall delay
                 ;clr p3.7
                 ret
;;;;;;;dealay required for program;;;;;
DELAY:   mov r0,#255
  loop1:    mov r1,#255
                  LOOP:djnz r1,loop
            djnz r0,loop1
  ret

end



4 comments: