EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
You are here: Home / Replies / This is the Code Romelthe

This is the Code Romelthe

|

Microcontroller › 8051 › Help with AT89C2051 › This is the Code Romelthe

April 21, 2011 at 5:55 pm #6013
Ahmed
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

RSS Recent Posts

  • 2nd pcb design program? August 10, 2022
  • My NE555 chips gone bad August 10, 2022
  • Nokia 5110 HW in Oshonsoft August 10, 2022
  • alternate of 80386/486 microprocessor August 10, 2022
  • Drill speed controller fault August 10, 2022

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools