Hello everyone,

I am working on a 4 way density based traffic light controlled by AT89C51 microcontroller. The problem is, I dont know whether this source code is correct or not. I found this code and placed it in proteus and there are many errors detected.

Please help me guys.

Mod edit: added code tags

I am working on a 4 way density based traffic light controlled by AT89C51 microcontroller. The problem is, I dont know whether this source code is correct or not. I found this code and placed it in proteus and there are many errors detected.

Please help me guys.

C:

```
#include<reg51.h>
#define density_level P1
//void green_delay();
//Lights declaration
sbit ar = P0^0;
sbit ag = P0^1;
sbit br = P0^2;
sbit bg = P0^3;
sbit cr = P0^4;
sbit cg = P0^5;
sbit dr = P0^6;
sbit dg = P0^7;
//sensors declarartion
sbit IRaa=P1^0;
sbit IRab=P1^1;
sbit IRba=P1^2;
sbit IRbb=P1^3;
sbit IRca=P1^4;
sbit IRcb=P1^5;
sbit IRda=P1^6;
sbit IRdb=P1^7;
int a[]=
{
void main()
{
P1=0XFF;
P3=0X00;
P0=0X00;
P2=0X00;
ar=1;
br=1;
cr=1;
dr=1;
while(1)
{
int check_high;
bit a=0,b=0,c=0,d=0,high=0;
int lane_a,lane_b,lane_c,lane_d;
for (check_high=0;chec k_high<3;check_hig h++)
{
switch (density_level)
{
case 0XFC :
if(a==0)
{
ar = 0;
a=1;
for(lane_a=0;lane_a<9;lane_a++)
{
ag = 1;
}
ag = 0;
}
break;
case 0XF3 :
if(b==0)
{
br = 0;
b=1;
for(lane_b=0;lane_b<9;lane_b++)
{
bg = 1;
}
}
bg = 0;
break;
case 0XCF :
if(c==0)
{
cr = 0;
c=1;
for(lane_c=0;lane_c<9;lane_c++)
{ cg = 1;
}
} cg = 0;
break;
case 0X3F :
if(d==0)
{
dr = 0;
d=1;
for(lane_d=0;lane_d<9;lane_d++)
{
dg = 1;
}
}
dg = 0;
break;
}
P0 = P0&0XFF;
}
}
}
/*
{
while(high==1)
{
int check2;
for (check2=0;check2<2;check2++)
{
{
if(IRaa==0)
//check lane a
{
if(IRab==0)
{ ar = 0;
ag = 1;
green_delay();
ag = 0;
}
else
{
ag = 0;
//ay = 1;
//yellow_delay();
//ay = 0;
ar = 1;
}
}
}
{
if(IRba==0)
//check lane b
{
if(IRbb==0)
{
br = 0;
bg = 1;
}
else
{
bg = 0;
//by = 1;
//yellow_delay();
//by = 0;
br = 1;
}
}
}
{
if(IRca==0)
//check lane c
{
if(IRcb==0)
{
cr = 0;
cg = 1;
}
else
{
cg = 0;
//cy = 1;
//yellow_delay();
//cy = 0;
cr = 1;
}
}
}
{
if(IRda==0)
//check lane d
{
if(IRdb==0)
{
dr = 0;
dg = 1;
}
else
{
dg = 0;
//dy = 1;
//yellow_delay();
//dy = 0;
dr = 1;
}
}
}
}
}
}
}
*/ /*void green_delay()
{
int y;
for (y=0; y<1000; y++);
} */
```

Last edited by a moderator: