Tutorial Microcontroller MCS-51 ATMEL ISP

Microcontroller Kits
Programmer and Target 89s51

Simple Mikrokontroller 89s51 Trainer


Standart
Mikrokontroller 89s51 Trainer


Super Mikrokontroller Trainer 89s51

+

All Item Include

Programmer
Via USB

 

 

BACK

3.4.2. Timer/ Counter acts as Counter Mode 3 with output LCD Char.



In this lesson will do, the experiment more complicated with LCD character to see number of pulse into timer 1.

Figure 3.4.2. Get data counter out to LED

Step 1st
Build the circuit as shown in figure 3.4.2. As you seen on figure 3.4.2. P0.0 trough P0.7 is connected to LCD Character . Remember, that all we want to do with this lesson is count the pulse and display to LCD Character 2 x 16

Step 2nd
In this step, you must tipe the assembly program to make your Timer get action, we assume that you have already known the editor, we used MIDE-51 to edit the program. ( Download File : exp342.zip )

 


Hundreds equ 70h
Tens equ 71h
ones equ 72h
;
Org 0h
setb p3.1
Start: Mov TMOD,#01110000b
setb tr1
call init_lcd
call printword
get: mov a,tl1

call Convert
call PrintChar
sjmp Get
;
Convert:
mov b,#100d
div ab
mov Hundreds,a
mov a,b
mov b,#10d
div ab
mov Tens,a
mov Ones,b
ret
;
PrintChar:
mov r1,#0c9h
acall write_inst
mov a,Hundreds
add a,#30h
mov r1,a
acall write_data
mov r1,#0cah
acall write_inst
mov a,Tens
add a,#30h
mov r1,a
acall write_data
mov r1,#0cbh
acall write_inst
mov a,Ones
add a,#30h
mov r1,a
acall write_data
ret
;
printword:
mov dptr,#myword
mov r3,#8
mov r1,#0c0h
call write_inst
CountW:clr a
movc a,@a+dptr
mov r1,A
inc dptr
acall write_data
djnz r3,CountW
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 R7,#0fh
djnz R7,$
djnz R0,delay1
ret
myWord:
DB 'Data counter :'
end



Step 3rd
Safe your assembly program above, and name it with timer4.asm (for example) Compile the program that you have been save by using MIDE-51, see the software instruction.

Step 4th
Download your hex file ( timer4.hex ) into the microcontroller by using Microcontroller ATMEL ISP software, see the instruction.After download this hex file you'll see the action of Timer( of course if your cable connection and your program are corrected ).

Comments, questions and discussion about this topic

BACK