Vous êtes sur la page 1sur 7

On-Chip Peripherals

Advantages of Standard Single-Purpose Processor over


general-purpose processor
NRE Cost is Low : Since the Processor is predesigned and
mass produced
Better performance
Consumes less power
Smaller Size
Microcontrollers tightly integrate the peripherals on-chip
and assign peripheral registers to the CPUs own register
space.

Communicating bits serially at a


specific rate between devices

EX: 8051 Timer operation


TMOD REG: PROGRAMS THE TIMER/COUNTER 1,0.
GATE
C/T
M1
M2
GATE
C/T
M1
M2
TIMER1
TIMER0
M1 M2
OPERATION
C/T
GATE
0
0 13-Bit Timer (MCS-48 MODE)
0=
1 = HARDWARE
TIMER
TRIGEER
0
1 16-Bit Timer/Counter
1
0 8-bit Auto Reload Timer/Counter
1=
0 = SOFTWARE
COUNTER TRIGGER
1
1 Timer0 as two 8-bit timers
TCON REG: CONTOLLES TIMER OPERATION
TF1
TR1
TFO
TRO
IE1
IT1
IE0
IT1
TH1

TL1
TH0
TL0
TIMER1 COUNTER
TIMER0 COUNTER
IE REG: TO ENABLE DIFFERENT INTERRUPTS
EA
-ET2
ES
ET1
EX1
ET0
VECTOR
0023
001B
0013
000B
LOCATION

EX0
0003

STEPS FOR PROGRAMMING TIMER IN NORMAL MODE AND INTERRUPT MODE


1.
2.
3.
4.
5.
6.

Normal Mode
Program the Timer using TMOD
Load Required Count value in
THx-TLx
Start Timer
Monitor Timer by Checking TFx
Stop Timer
Reset TFx

1
2
3
4

1.

Interrupt Mode
Program the Timer using TMOD
Load Required Count value in
THx-TLx
Start Timer
Continue the Main Program
:
Timer ISR
Stop Timer
Continue ISR
:
Return from ISR

STUDY OF TIMER / COUNTERS OF 89C51


Problem statement:
To study the Timer & Counter operations of 89c51 in interrupted mode and
normal mode.
Program Timer0 as 16 bit timer for generating delay of 20msec
Repeat this delay for 50 times to get delay of 1 sec.
Program Timer1 as a counter for counting 10 external pulses in
interrupt mode
Main program display a binary counter on port1
Timer1 ISR resets the counter after counting 10 pulses.
Which SFR Registers are to be programmed?
TMOD
: To Program Timer0 and Timer1
TH0 & TL0 : To store count value for delay
TH1 & TL1 : To store the number of Ext. pulses to be counted
TCON
: To operate Timer0 and Counter1
IE
: To enable Timer1 interrupt

/*main*/
#define Ms_INIT 63535
void main (void)
int count_millsec = 0;
Configure Timer Mode
Set Cnt to Ms_INIT
Wait a random time
Turn on indicator light
start timer
while (user not pushed
reaction button)

{
if (top)
{
stop timer
reset top
count_millsec++;
set count to Ms_INIT
start timer
}
}
Turn off indicator light
printf (time: %i ms,
count_millsec);

OSC 12MHz; PRESCALE 12;


TIMER RESOLURION IS 2msec.

main()
{
wait until card inserted
call watchdog_reset routine
while(trans. In progress){
if(button pressed){
perform corresponding action
call watchdog_reset_ routine}
/* if watchdog_reset_routine not
Called every<2min,
int_service_routine is called*/
}
watchdog_reset_routine(){

SCALE REG. = 11-BIT :2048,

/* check reg. is set so we can load


value into time reg., zero is loaded
into scale reg. and 5535 is loaded
into time reg. */
check reg. = 1;
scale reg. = 0;
time reg. = 5535;
}
void int_service_routine()
{eject card
reset screen}