Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Coding of Microcontroller atmeil 89c51 using c language

Status
Not open for further replies.

zidanfadi

Newbie level 5
Newbie level 5
Joined
Nov 19, 2012
Messages
9
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Visit site
Activity points
1,354
can i be able to generate a total of 10 mins delay using 8051
i have to made 5 leds on,,,,
4 leds depends upon the no of times switch made on and off said to be as "counter".....

While the 5th one depend upon the remaing time left ........


if the switch have been made on and off for 3 time than the first led will be on while remaining off ,,, and if again 3 time ,, total of 6 times than the 2nd led will be on while other three off ... and so on

4th led will take a total 12 times swith on off and it will remain on ,,,,,,,,,


suppose this all takes 8 minutes then the fifth led wii be made on for 2 minutes and if 4 leds take a total of 6 min then the 5th led be made on for 4 minutes ..........!!! and the ckt reset.........

and if the four leds take a total of 10 minutes to glow then the fifth one remain off and the ckt reset.....................
can i do this project through the microcontroller 89c51 using c language ...!!!!
i have been able to achieve target upto 4th bulb .... i have not been able to achieve a time of 10 minutes and to made the 5th bulb on..!!! the code and design is provided...!!!
 

Attachments

  • attachment.rar
    16 KB · Views: 70
Last edited:

use timer interrupt !

increment a flag in timer interrupt when you desired number is reached make it again 0 when u have utilised the flag.
Code:
void ---T1_interrupt(void)
{
   flagnum++;
}

main()
{
  if(flagnum == 2000)
{
// do what ever u like
flagnum=0;
}
}
 

i have been able to achieve target upto 4th bulb .... i have not been able to achieve a time of 10 minutes and to made the 5th bulb on..!!! the code and design is provided...!!!

You can achieve any number of bulb with any amount of time............

start a 10 min timer(Its not possible but possible) in starting that has to run through interrupts...

after the time expires make the ALL LEDs OFF.....

add another case in while for the next LED ON (Then it will also turned OFF in the ISR)
 

this is my code :
Here i have not defined the fifth bulb as i was not able to set the code as defined above ........ i was able to make the four bulbs glow by counter but not able to make fifth bulb on by timer ...!!!
#include <reg51.h>
sbit a = P2^0;
sbit b = P2^1;
sbit c = P2^2;
sbit d = P2^3;
void delay(unsigned int v);
void main (void)
{
T0 = 1; //input
TMOD = 0x05;
TH0 = 0;
TL0 = 0;
P3=0x00;
P2=0XFF;
P2=0;
TR0=1;
while(1)
{
if(TL0==0x03)
{
a=1;
b=0;
c=0;
d=0;
}
else if (TL0==0x05)
{
a=0;
b=1;
c=0;
d=0;
}
else if (TL0==0x07)
{
a=0;
b=0;
c=1;
d=0;
}
else if (TL0==0x0A)
{
a=0;
b=0;
c=0;
d=1;
delay(120);
break;
}

}
}



void delay(unsigned int v)
{
int d;
for(d=0;d<=20*v;d++)
{
TMOD=0x10;
TL0=0xFD;
TH0=0x04B;
TR0=1; // start timer.
while(TF0==0); // run until TF turns to 1
TR0=0; // stop timer
TF0=0; // reset the flag
}

- - - Updated - - -

this is my code :
Here i have not defined the fifth bulb as i was not able to set the code as defined above ........ i was able to make the four bulbs glow by counter but not able to make fifth bulb on by timer ...!!!
#include <reg51.h>
sbit a = P2^0;
sbit b = P2^1;
sbit c = P2^2;
sbit d = P2^3;
void delay(unsigned int v);
void main (void)
{
T0 = 1; //input
TMOD = 0x05;
TH0 = 0;
TL0 = 0;
P3=0x00;
P2=0XFF;
P2=0;
TR0=1;
while(1)
{
if(TL0==0x03)
{
a=1;
b=0;
c=0;
d=0;
}
else if (TL0==0x05)
{
a=0;
b=1;
c=0;
d=0;
}
else if (TL0==0x07)
{
a=0;
b=0;
c=1;
d=0;
}
else if (TL0==0x0A)
{
a=0;
b=0;
c=0;
d=1;
delay(120);
break;
}

}
}



void delay(unsigned int v)
{
int d;
for(d=0;d<=20*v;d++)
{
TMOD=0x10;
TL0=0xFD;
TH0=0x04B;
TR0=1; // start timer.
while(TF0==0); // run until TF turns to 1
TR0=0; // stop timer
TF0=0; // reset the flag
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top