$TITLE(ADC and LCD)
$MOD51
DSEG
ORG 0030H
hundreds equ 031h ;Buffer for hundreds for data adc
tens equ 032h
unit equ 033h
;
CSEG
org 0100h
start:
lcall init_lcd
lcall ADC
lcall Bin2Dec
mov r1,#80h
call Write_inst ; this means move cursor to line 1 lcd if you want to use line 2 lcd use C0H
mov r1,hundreds
call Write_data
mov r2,tens
call Write_data
mov r1,unit
call Write_data
sjmp start
;
;=================================================
;Subrutine ADC for get adc data(use free running ADC mode)
; ADC port using port 1
; WR ADC port 3.3
; RD ADC port 3.4
; CS ADC connect to ground
;=================================================
ADC:
clr P3.3
nop
nop
nop
setb P3.3
eoc:
jb P3.2,eoc
clr P3.4
mov A,P1
setb P3.4
ret
;
;==================================================
;Subrutin to convert Binary Data to Decimal Data
; example 254 ==> hundreds = 2, 5 = tens and 4 = unit
;==================================================
Bin2Dec:
mov b,#100d
div ab
mov hundreds,a
mov a,b
mov b,#10d
div ab
mov tens,a
mov unit,b
ret
;========================================
; Subroutine LCD initialization ( iuse lcd x x 16)
;========================================
Init_lcd:
mov r1,#00000001b ;Display clear
acall write_inst ;
mov r1,#00111000b ;Function set,
;Data 8 bit,2 line font 5x7
acall write_inst ;
mov r1,#00001100b ;Display on,
;cursor off,cursor blink off
acall write_inst
mov r1,#00000110b ;Entry mode, Set increment
acall write_inst
ret
;==========================================
; Subroutine Write command to LCD
;=========================================
Write_inst:
clr P2.0 ; RS = P2.0 = 0, write mode instruction
mov P0,R1 ; D7 s/d D0 = P0 = R1
setb P2.1 ; EN = 1 = P2.1
call delay; call delay time
clr P2.1 ; EN = 0 = P2.1
ret
;========================================
; Sub routine write data to lcd
;========================================
Write_data:
setb P2.0 ; RS = P2.0 = 1, write mode data
mov P0,R1 ; D7 s/d D0 = P0 = R1
setb P2.1 ; EN = 1 = P2.1
call delay; call delay time
clr p2.1 ; EN = 0 = P2.1
ret
;=============================
; Delay Subroutine
;============================
delay: mov R0,#0ffh
delay1:mov R7,#0ffh
djnz R7,$
djnz R0,delay1
ret
end