|
Product
Kit Trainer
Tutorial
MCS51
Tutorial
AVR
Tutorial
ARMSTM32
Link
Download Software
Galery
Pelatihan
Best Seller Trainer
Super
MCS51 Trainer
Standart
MCS51 Trainer
Super
AVR Trainer
Standart
AVR Trainer
Programmer
USBASP
Standart
ARM Trainer |
|
5.1.
Displaying data ADC 0804 in LCD Character as a Decimal
In this lesson will be learn how to display data ADC
on LCD Character, for a simple task that we assume ADC have input ranges
0 - 5 volt, and then will display data as desimal that must be 3 digit
0 - 255.
Figure 2.13.Display data ADC to LCD Character as decimal
Step 1st
Build the circuit as shown in figure 2.13. As you seen on figure 2.13.
P0.0 trough P0.7 is connected to DB0 - DB7 ADC0804, and P2.0- P2.7.
is connected to D0 - D7, and P3.0, P3.1. is connected to RS and EN each.
Remember, that all we want to do with this lesson is write data ADC,
in the first line of LCD Character
Step 2nd
In this step, you must tipe the assembly program to make your LCD Character
shown the data, we assume that you have already known the editor, we
used MIDE-51 to edit the program.
org 0h
call init_LCD start: call ADC call Bin2Dec call Write2LCD
sjmp start ;
;=================================================
;this subroutine is used to take data from ADC and ;keep to Accumulator
;================================================= ADC: mov A,P0 nop nop ret
;
;======================================================== ;this subroutine is used print out data decimal to LCD ;character 2 x16 on address DDRAM 0C9 0CA 0CB each for ;hundreds, tens, and ones ;========================================================
Write2LCD: mov r1,#0c9h call write_inst mov a,hundreds add a,#30h mov r1,a call write_data ; mov r1,#0cah call write_inst mov a,tens add a,#30h mov r1,a call write_data ; mov r1,#0cbh call write_inst mov a,ones add a,#30h mov r1,a call write_data ret
;
;======================================================== ;this subroutine is used to convert binary data from ADC ;become decimal 3 digit ;========================================================
Bin2Dec: mov b,#100d div ab mov hundreds,a mov a,b mov b,#10d div ab mov tens,a mov ones,b ret
;
write_char: mov dptr,#word1 ;DPTR = [ address word1 ] mov r3,#16 ;R3=16,number character to be display mov r1,#80h ;R1=80h,address DDRAM start position acall write_inst ;
write1:clr a ; A = 0 movc a,@a+dptr ; A = [A+ DPTR] mov r1,A ; R1 = A inc dptr ; DPTR = DPTR +1 acall write_data;
djnz r3,write1 ; R3 = R3-1, ret ;
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 ; 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
;
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: mov R0,#0 delay1:mov R2,#0fh djnz R2,$ djnz R0,delay1 ret
end
NEXT
|