0% found this document useful (0 votes)
2 views3 pages

Experiment 2

The experiment aimed to generate precise time delays using timers in a microcontroller, specifically demonstrating the configuration of timer registers. Required apparatus included a microcontroller development board and Keil µVision software, with a focus on Timer0 in the 8051 architecture. The experiment successfully achieved the desired delay by accurately counting clock pulses and configuring the timer in the correct mode.

Uploaded by

akshitapinjere
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Experiment 2

The experiment aimed to generate precise time delays using timers in a microcontroller, specifically demonstrating the configuration of timer registers. Required apparatus included a microcontroller development board and Keil µVision software, with a focus on Timer0 in the 8051 architecture. The experiment successfully achieved the desired delay by accurately counting clock pulses and configuring the timer in the correct mode.

Uploaded by

akshitapinjere
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment 2:

Aim: To generate a time delay using timers in a microcontroller and understand how timer
registers are configured to achieve precise delays.

Apparatus Required:

1. Keil µVision Software – For writing and compiling Embedded C programs.

2. Microcontroller Development Board – (e.g., 8051, PIC, AVR, ARM, STM32)

3. USB Programmer – To upload the program (e.g., STLink, USBasp, ULINK)

4. Power Supply – To run the microcontroller board.

5. LEDs, Switches (Optional) – For testing logical operations.

6. Serial Cable (Optional) – To observe results via UART communication.

Theory: Timers in microcontrollers are used to generate precise time delays and perform
various time-based operations. They work by counting clock pulses and generating an interrupt
or overflow when a predefined value is reached.

Working of a Timer:

1. Clock Source: The timer operates based on an internal or external clock.

2. Prescaler: Divides the clock frequency to slow down the timer counting rate.

3. Timer Mode:

- Timer Mode: The timer counts internal clock cycles to generate a delay.

- Counter Mode: The timer counts external events.

4. Overflow: When the timer register overflows, an interrupt is triggered or a flag is set.

Example: Timer0 in 8051 (16-bit Timer Mode)

- Crystal Frequency: 11.0592 MHz

- Machine Cycle: 11.0592 / 12 = 921.6 kHz


- Clock Period: 1 / 921.6 = 1.085 µs

- Initial Value Calculation (for 1ms delay):

- 1ms / 1.085u s = 922

- Initial Value = 65536 - 922 = 64614

- Hex Value: FC66 (TH0 = 0xFC, TL0 = 0x66)

Program:

include <reg51.h> // Header file for 8051

void delay_ms(unsigned int ms); // Function prototype

void main() {

while(1) {

P1 = 0xFF; // Turn ON all pins of Port 1

delay_ms(500); // 500ms delay

P1 = 0x00; // Turn OFF all pins of Port 1

delay_ms(500); // 500ms delay

// Delay function using Timer 0

void delay_ms(unsigned int ms) {

unsigned int i;

for(i = 0; i < ms; i++) {

TMOD = 0x01; // Timer 0, Mode 1 (16-bit)

TH0 = 0xFC; // Load high byte for 1ms delay

TL0 = 0x66; // Load low byte for 1ms delay

TR0 = 1; // Start Timer 0

while(TF0 == 0); // Wait until Timer Overflows


TR0 = 0; // Stop Timer

TF0 = 0; // Clear overflow flag

Result: The experiment to generate a time delay using timers in a microcontroller was successfully
performed. The timer was configured in the appropriate mode, and the expected delay was achieved. The
microcontroller counted clock pulses accurately and generated the required delay.

You might also like