Sei sulla pagina 1di 5

Microcontroller Timers

80c51 Intel Microcontroller has Two 16-bit timers/counters, Timer 0 and Timer
1. TMOD and TCON registers are used for setting and using these
timers/counters.
Both can be configured to operate either as timers or as event counters. In the
case of timers, register is incremented once every machine cycle. Hence timer is
considered as counter which counts machine cycles. One machine cycle has
about 12 oscillator periods. The count rate is about (1/12)Oscillator frequency.
In the case of Counter, register is incremented in response to a 1-0 transition to
its corresponding external input pin. In this function, the external input is sampled
during S5-P2 of the every machine cycle.
Microcontroller TMOD register(Not bit addressable)

M1 M0 Operating Mode

0 0 13 bit timer

0 1 16 bit timer/counter

1 0 8 bit auto-reload timer/counter

TL0 is an 8 bit timer/counter controlled by standard


timer 0 control bits, TH0 is an 8 bit timer controlled
1 1 by timer 1 control bits.

GATE- When GATE=1 and TRx(in TCON) is set, Timer/Counter-x will run while
INT-x pin is
set high(Hardware Control). When GATE=0, Timer/Counter-x will run only
while TRx=1(software control).
C/(T)- Set 0 for timer operation and Set 1 for counter operation
M1- Mode Selector bit
M0- Mode Selector bit
Microcontroller TCON register(Bit addressable)

TF1-TCON.7-Timer1 overflow flag


TR1-TCON.6-Timer1 run control bit
TF0-TCON.5-Timer0 overflow flag
TR0-TCON.4-Timer0 run control bit
IE1-TCON.3-External interrupt 1 edge flag
IT1-TCON.2-Interrupt 1 type control bit
IE0-TCON.1-External interrupt 0 edge flag
IT0-TCON.0-Interrupt 0 type control bit

Microcontroller Serial Communication


8051 has a serial port which is full duplex,hence it can transmit and receive
simultaneously. The port is a receive buffered, due to this port can start receiving
byte before the previous bytes has already been read from the register SBUF.
There will be collision if the byte arrives in SBUF before the previous byte is read
from it.

The serial port receive/transmit registers are both accessed at SBUF. The serial
port can operate in 4 modes as mentioned below.

SCON(Serial Control Register), BIT Addressable


The serial port control and status register is the Special Function Register SCON.
This register contains not only the mode selection bits, but also the 9th data bit
for transmit and receive (TB8 and RB8), and the serial ports interrupt bits (TI and
RI).

SM0-SCON.7- Serial port mode specifier(Table-1)


SM1-SCON.6- Serial port mode specifier(Table-1)
SM2-SCON.5- Enable multiprocessor communication in modes 2/3.
REN-SCON.4- Set/clear by software to enable/disable reception
TB8-SCON.3- The 9th bit that will be transmitted in mode2/3, set/clear by
software
RB8-SCON.2- In mode2/3, it is the 9th bit that was received. In mode 1, if
SM2=0, RB8
is the stop bit that was received, In mode 0, it is not used.
TI-SCON.1- Transmit Intterupt flag, set by hardware at the end of 8th bit time in
mode 0,
at the beginning of the stop bit in the other modes, it must be cleared by
software.
RI-SCON.0- receive Interrupt flag, set by hardware and must be cleared by
software.

Table-1
Based on SM0 and SM1 various baudrates are selected as shown in the table
below.
SM SM
0 1 Mode/Description/Baud rate

0 0 0,shift register,(Fosc./12)

0 1 1,8 bit UART,Variable

2,9 bit UART,(Fosc./64) OR


1 0 (Fosc./32)

1 1 3,9 bit UART, Variable

Microcontroller Serial Port Initialization C program

As shown in the C program, it initializes timer 0 for delay and timer 1 for baud
rate of 9600 bps.

Transmission via SBUF


SBUF='S'; while(!TI); TI=0; /* One character at a time/*

for(i=0;i<max;i++)
{
SBUF=transmit_array[i++]; /* Transmitting character array/*
while(!TI); TI=0;

Potrebbero piacerti anche