0% found this document useful (0 votes)
6 views1 page

Ex 1 B

The document is a C program for the C8051F340 microcontroller that controls a series of LEDs using Timer 0. It configures all pins of port 4 as outputs and creates a rolling LED effect by sequentially turning off each LED with delays in between. The Delay function uses Timer 0 to create a timed pause before the next LED state change.

Uploaded by

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

Ex 1 B

The document is a C program for the C8051F340 microcontroller that controls a series of LEDs using Timer 0. It configures all pins of port 4 as outputs and creates a rolling LED effect by sequentially turning off each LED with delays in between. The Delay function uses Timer 0 to create a timed pause before the next LED state change.

Uploaded by

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

//TIMERS WITH ROLLING LED'S

#include "c8051F340.h"
void Delay();
#define LED3 P4

void main()
{
P4MDOUT = 0xFF; /* All P4 pins configured as Output */
TMOD = 0x01; /* Timer 0 in mode 1 (16-bit) */
CKCON = 0x04; /* Timer 0 uses SYSCLK / 12 */

while(1)
{
LED3 = 0x00; /* LEDs ON */
Delay();
LED3 = 0xFE; /* 11111110 */
Delay();
LED3 = 0xFD; /* 11111101 */
Delay();
LED3 = 0xFB; /* 11111011 */
Delay();
LED3 = 0xF7; /* 11110111 */
Delay();
LED3 = 0xEF; /* 11101111 */
Delay();
LED3 = 0xDF; /* 11011111 */
Delay();
LED3 = 0xBF; /* 10111111 */
Delay();
LED3 = 0x7F; /* 01111111 */
Delay();
}
}

void Delay()
{
TH0 = 0x73; // Load Timer 0 High byte
TL0 = 0x5F; // Load Timer 0 Low byte
TR0 = 1; // Start Timer 0

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


TF0 = 0; // Clear Timer 0 overflow flag
TR0 = 0; // Stop Timer 0
}

You might also like