Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C-language program that runs on the AT89C51CC03 board. Add four LEDs to

ID: 2085942 • Letter: W

Question

Write a C-language program that runs on the AT89C51CC03 board. Add four LEDs to your board to P1.0, P1.1, P1.2, and P1.3 and add a push button switch to the board on P3.4. All resistors are 1K. For this problem you are going to multiplex the LEDs so that they appear to be all on when the switch is pushed but your program will only turn on one LED at a time. The blink rate of the eye is about a thirtieth of a second-that is, you can see something blinking if it is blinking at a rate slower than about 30 times s second-but this is brightness dependent. For this problem we will take the blink rate to be about 50 times second. Since we have four LEDs you will have to turn on the first, then turn it off and turn on the second, turn that off and turn on the third, turn that off and turn on the fourth all in a 50th of a second (20 msec). Since there are four LEDs each LED will be on for just 5 milliseconds. When the switch is pushed you will run a loop that turns on the next LED every 5 msec. Your program should use a function which accepts an unsigned character argument named x and does a software delay of x msec.

Explanation / Answer

#define LED_1 P1_0

#define LED_2 P1_1

#define LED_3 P1_2

#define LED_4 P1_3

#define SWITCH P3_4

#define ON 0

#define OFF 1

void DelayUsingTimer_0(unsigned char DelayTime);

void LEDPattern(unsigned char x);

void DelayUsingTimer_0(unsigned char DelayTime)

{

unsigned char dCnt;

for(dCnt=0;dCnt<DelayTime;dCnt++)

{

TH0 = 0xFC;

TL0 = 0x17; // Delay Count for 1 msec.

TF0=0; TR0=1;

while(!TF0){}TR0=0;

}

}

void LEDPattern(unsigned char x)

{

if(x==1) {LED_1 = ON; LED_2 = OFF; LED_3 = OFF; LED_4 = OFF; DelayUsingTimer_0(5); x= 2;}

if(x==2) {LED_1 = OFF; LED_2 = ON; LED_3 = OFF; LED_4 = OFF; DelayUsingTimer_0(5); x= 3;}

if(x==3) {LED_1 = OFF; LED_2 = OFF; LED_3 = ON; LED_4 = OFF; DelayUsingTimer_0(5); x= 4;}

if(x==4) {LED_1 = OFF; LED_2 = OFF; LED_3 = OFF; LED_4 = ON; DelayUsingTimer_0(5); x= 1;}

}

void main(void)

{

TMOD= 0x11; // Timer-0 and Timer-1 in Mode-1

TF0=0;

TR0=0;

while(1)

{

if(!SWITCH) LEDPattern(x); // x is the LED No. The function LEDPattern will start LED blinking

// from LED numbered x.

else

{

LED_1 = OFF; LED_2 = OFF; LED_3 = OFF; LED_4 = OFF;

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote