Microcontroller › 8051 › Help with AT89C2051 › This is the Code Romelthe
April 21, 2011 at 5:55 pm
#6013
Participant
This is the Code Romel
the delay function can i calculate the time delay by using ((1/11.0592*10^6)*80000)??
or ther is another way to calculate???
/* *********************************************************************************************
Project: Traffic Project (COM1)
File: Traffic.txt
Data: 8/4/2011
Processor: AT89C2051
Program to Controll Traffic with PC with provment of LED
********************************************************************************************* */
#include<reg51.h>
unsigned char temp;
sbit trR3=P3^2;
sbit trY3=P3^3;
sbit trG3=P3^4;
sbit trR4=P3^5;
sbit trG4=P3^7;
sbit trY4=P1^7; // Port Of LED’s
void ini() // Initialize Timer 1 for serial communication
{
TMOD=0x20; //Timer1, baud rate 9600 bps
SCON=0x50; // 8-Bit
TH1=0XFD; //Load the timer high with initial value for serial connection
TR1=1; //Start Timer 1
}
void delay() //simple Delay
{
int k,l;
for(k=0;k<1000;k++)
for(l=0;l<80;l++);
}
void recieve() //Function to receive serial data for controlling
{
while(RI==0);
temp=SBUF;
switch(temp) // Sequence Of LED of traffic.
{
case(‘1’):
P1=0x0c;
trR3=1;
trY3=0;
trG3=0;
trR4=1;
trY4=0;
trG4=0;
break;
case(‘2’):
P1=0x12;
trR3=1;
trY3=0;
trG3=0;
trR4=1;
trY4=0;
trG4=0;
break;
case(‘3’):
P1=0x21;
trR3=1;
trY3=0;
trG3=0;
trR4=1;
trY4=0;
trG4=0;
break;
case(‘4’):
P1=0x11;
trR3=0;
trY3=1;
trG3=0;
trR4=1;
trY4=0;
trG4=0;
break;
case(‘5’):
P1=0x09;
trR3=0;
trY3=0;
trG3=1;
trR4=1;
trY4=0;
trG4=0;
break;
case(‘6’):
P1=0x09;
trR3=0;
trY3=1;
trG3=0;
trR4=0;
trY4=1;
trG4=0;
break;
case(‘7’):
P1=0x09;
trR3=1;
trY3=0;
trG3=0;
trR4=0;
trY4=0;
trG4=1;
break;
case(‘8’):
P1=0x0a;
trR3=1;
trY3=0;
trG3=0;
trR4=0;
trY4=1;
trG4=0;
break;
case(‘0’):
P1=0;
P1=0x12;
trR3=0;
trY3=1;
trG3=0;
trR4=0;
trY4=1;
trG4=0;
delay();
P1=0;
trR3=0;
trY3=0;
trG3=0;
trR4=0;
trY4=0;
trG4=0;
}
RI=0;
}
void main() //main Program.
{
ini(); //initialize the microcontroller
while(1) // infinit loop
{
recieve();
}
} //End of Program