Introduction: When you decide to interface Traffic controller module with P89v51RD2 microcontroller, we have to understand two things, first you should know how to burn code in P89v51RD2 microcontroller. This microcontroller is having serial programming facility. Normal ATMEL 8051 microcontroller which is cheaper in market but you cannot program via serial cable or using Flashmagic Utility. You need EPROM programmer for that. Second, you should know how to create HEX file code using Keil version 2 cross compiler.
Why we selected P89v51RD2 microcontroller?
Nowadays Intel stop manufacturing 8051 microcontroller. Some other companies are manufacturing 8051 microcontroller. This 8 bit microcontroller market is so huge, you will find more than 100 different 8051 microcontroller. Recently I was moving in Lamgigton Road market of Mumbai for P89v51RD2FN or BN, someone told me Philips (NXP) stopped manufacturing this IC.
If you google, you will find on many websites. What is distinguish difference between normal Atmel 8051 and P89v51RD2? P89v51rd2 is having boot loader, flashmagic is knowing address of this boot loader. Due to this bootloader, flash memory is easily programmable using Serial cable. We do not require some special voltage. If you are modifying code many times then it is always good to use P89v51rd2 microcontroller.
Requirement of experiment: a) 8051 kit and 12 V power supply and serial cable or Dongale to convert USB to serial port b)Traffic controller module with 12-16 burg wires for interfacing.
Logic of Traffic controller: We know traffic signals and its meaning. We have Red light, Green Light and Yellow light.
Traffic lights alternate the right of way of road users by displaying lights of a standard color (red, yellow/amber, and green), using a universal color code.
In the typical sequence of colored lights:
1)Illumination of the green light allows traffic to proceed in the direction denoted,
2)Illumination of the yellow/amber light denoting, if safe to do so, prepare to stop short of the intersection, and
3)Illumination of the red signal prohibits any traffic from proceeding. Usually, the red light contains some orange in its hue, and the green light contains some blue, for the benefit of people with red-green color blindness, and “green” lights in many areas are in fact blue lenses on a yellow light (which together appear green).
Table 1: Pin Assignment with 8051 and traffic module. Please assume that we are using separate traffic module. If you are using customized module, then you have to change some Io line here and there.
LANE Direction |
8051 Lines |
Module Interface |
NORTH |
Direction3_green=P1^2; //D3 |
GO(Green LED) |
Direction3_yellow = P1^1;//D2
|
Listen (yellow LED) |
|
Direction3_red = P1^0;//D1 |
STOP (red LED) |
|
East |
Direction4_green = P1^7;//D9 |
GO(Green LED) |
Direction4_yellow = P1^6;//D8 |
Listen (yellow LED) |
|
Direction4_red = P1^5;//D7 |
STOP (red LED) |
|
SOUTH |
Direction1_green = P0^2;//D12 |
GO(Green LED) |
Direction1_yellow = P0^1;//D11
|
Listen (yellow LED) |
|
Direction1_red = P0^0;//Connect D10 |
STOP (red LED) |
|
WEST |
Direction2_green = P0^7;//D6
|
GO(Green LED) |
Direction2_yellow = P0^6;//D5 |
Listen (yellow LED) |
|
Direction2_red = P0^5;//D4
|
STOP (red LED) |
Fig1 shows circuit diagram of interfacing of Traffic module with 8051 microcontroller.
Fig 1: Interfacing of Traffic module with 8051 (here AT89S52 or P89v51RD2)
Above figure shows total 12 LEDs interfaced with microcontrollers. Table 1 shows IO lines of 8051 port lines and directions.
Below Fig2 shows actual module of Traffic controller. Its 20 pins are available to interface with I/O lines of 8051 microcontroller. You have to take care that 5V should be provided to the Traffic controller module and common ground with 8051 board is reuired. In the diagram you can noticed that 20pin header is shown. You can find out conection from backside of PCB also.
Fig 2: Simple traffic controller module
You can notice Direction symbol on the traffic module, this is like MAP direction. For example, I want to control NORTH direction of traffic. I Have 3 LEDs, Green, Yellow and Red. So GREEN LED you have to interface to P1.2, and YELLOW LED to P1.1 and RED LED to P1.0 Io lines. Similarly you can do for other direction. Program logic is for these direction only.
Please type following code as source file in the Keil IDE version 2 screen and Save it as main.c and take care of reg51.h header file which will provide SFR details to compiler.
Main.c source code,
Create HEX file and download HEX file using FlashMagic software and do not forgot to do common grounding of 8051 kit and traffic controller module.
We are giving assembly listing also. You will find this little bit cryptic because this is taken from lst file. But you avoid memory location from Assembly listing. You should not type memory locations if you want to prepare traffic.asm kind from below code.
We have tested this code on normal P89v51RD2 board with simple traffic controller module. Our cross compiler is Keil version 2 (Eval)
Assembly listing is shown in below box.
; FUNCTION L?0018 (BEGIN) 0000 L?0019: 0000 AF00 R MOV R7,green_delay+01H 0002 AE00 R MOV R6,green_delay ; FUNCTION _MSDelayL (BEGIN) ; SOURCE LINE # 27 ;—- Variable ‘dtime’ assigned to Register ‘R6/R7’ —- ; SOURCE LINE # 28 ; SOURCE LINE # 30 ;—- Variable ‘i’ assigned to Register ‘R4/R5’ —- 0004 E4 CLR A 0005 FD MOV R5,A 0006 FC MOV R4,A 0007 ?C0001: 0007 C3 CLR C 0008 ED MOV A,R5 0009 9F SUBB A,R7 000A EC MOV A,R4 000B 9E SUBB A,R6 000C 5015 JNC ?C0007 ; SOURCE LINE # 31 ;—- Variable ‘j’ assigned to Register ‘R2/R3’ —- 000E E4 CLR A 000F FB MOV R3,A 0010 FA MOV R2,A 0011 ?C0004: 0011 0B INC R3 0012 BB0001 CJNE R3,#00H,?C0016 0015 0A INC R2 0016 ?C0016: 0016 BA04F8 CJNE R2,#04H,?C0004 0019 BBFBF5 CJNE R3,#0FBH,?C0004 001C ?C0003: 001C 0D INC R5 001D BD0001 CJNE R5,#00H,?C0017 0020 0C INC R4 0021 ?C0017: 0021 80E4 SJMP ?C0001 ; SOURCE LINE # 32 0023 ?C0007: 0023 22 RET ; FUNCTION _MSDelayL (END)
; FUNCTION all_off (BEGIN) ; SOURCE LINE # 34 ; SOURCE LINE # 35 ; SOURCE LINE # 36 0000 C280 CLR Direction1_red ; SOURCE LINE # 37 0002 C281 CLR Direction1_yellow ; SOURCE LINE # 38 0004 C282 CLR Direction1_green ; SOURCE LINE # 40 0006 C285 CLR Direction2_red ; SOURCE LINE # 41 0008 C286 CLR Direction2_yellow ; SOURCE LINE # 42 000A C287 CLR Direction2_green ; SOURCE LINE # 44
000C C290 CLR Direction3_red ; SOURCE LINE # 45 000E C291 CLR Direction3_yellow ; SOURCE LINE # 46 0010 C292 CLR Direction3_green ; SOURCE LINE # 48 0012 C295 CLR Direction4_red ; SOURCE LINE # 49 0014 C296 CLR Direction4_yellow ; SOURCE LINE # 50 0016 C297 CLR Direction4_green ; SOURCE LINE # 51 0018 22 RET ; FUNCTION all_off (END)
; FUNCTION Direction1 (BEGIN) ; SOURCE LINE # 53 ; SOURCE LINE # 54 ; SOURCE LINE # 55 0000 D285 SETB Direction2_red ; SOURCE LINE # 56 0002 D290 SETB Direction3_red ; SOURCE LINE # 57 0004 D295 SETB Direction4_red ; SOURCE LINE # 58 0006 C280 CLR Direction1_red ; SOURCE LINE # 60 0008 D282 SETB Direction1_green ; SOURCE LINE # 61 000A 120000 R LCALL L?0018 ; SOURCE LINE # 62 000D C282 CLR Direction1_green ; SOURCE LINE # 64 000F D281 SETB Direction1_yellow ; SOURCE LINE # 65 0011 AF00 R MOV R7,yellow_delay+01H 0013 AE00 R MOV R6,yellow_delay 0015 120000 R LCALL _MSDelayL ; SOURCE LINE # 66 0018 C281 CLR Direction1_yellow ; SOURCE LINE # 67 001A 22 RET ; FUNCTION Direction1 (END)
; FUNCTION Direction2 (BEGIN) ; SOURCE LINE # 69 ; SOURCE LINE # 70 ; SOURCE LINE # 71 0000 D280 SETB Direction1_red ; SOURCE LINE # 72 0002 D290 SETB Direction3_red ; SOURCE LINE # 73 0004 D295 SETB Direction4_red ; SOURCE LINE # 74 0006 C285 CLR Direction2_red ; SOURCE LINE # 76 0008 D287 SETB Direction2_green ; SOURCE LINE # 77 000A 120000 R LCALL L?0018 ; SOURCE LINE # 78 000D C287 CLR Direction2_green ; SOURCE LINE # 8
000F D286 SETB Direction2_yellow ; SOURCE LINE # 81 0011 AF00 R MOV R7,yellow_delay+01H 0013 AE00 R MOV R6,yellow_delay 0015 120000 R LCALL _MSDelayL ; SOURCE LINE # 82 0018 C286 CLR Direction2_yellow ; SOURCE LINE # 83 001A 22 RET ; FUNCTION Direction2 (END)
; FUNCTION Direction3 (BEGIN) ; SOURCE LINE # 85 ; SOURCE LINE # 86 ; SOURCE LINE # 87 0000 D280 SETB Direction1_red ; SOURCE LINE # 88 0002 D285 SETB Direction2_red ; SOURCE LINE # 89 0004 D295 SETB Direction4_red ; SOURCE LINE # 90 0006 C290 CLR Direction3_red ; SOURCE LINE # 92 0008 D292 SETB Direction3_green ; SOURCE LINE # 93 000A 120000 R LCALL L?0019 ; SOURCE LINE # 94 000D C292 CLR Direction3_green ; SOURCE LINE # 96 000F D291 SETB Direction3_yellow ; SOURCE LINE # 97 0011 AF00 R MOV R7,yellow_delay+01H 0013 AE00 R MOV R6,yellow_delay 0015 120000 R LCALL _MSDelayL ; SOURCE LINE # 98 0018 C291 CLR Direction3_yellow ; SOURCE LINE # 99 001A 22 RET ; FUNCTION Direction3 (END)
; FUNCTION Direction4 (BEGIN) ; SOURCE LINE # 101 ; SOURCE LINE # 102 ; SOURCE LINE # 103 0000 D280 SETB Direction1_red ; SOURCE LINE # 104 0002 D285 SETB Direction2_red ; SOURCE LINE # 105 0004 D290 SETB Direction3_red ; SOURCE LINE # 106 0006 C295 CLR Direction4_red ; SOURCE LINE # 108 0008 D297 SETB Direction4_green ; SOURCE LINE # 109 000A 120000 R LCALL L?0019 ; SOURCE LINE # 110 000D C297 CLR Direction4_green ; SOURCE LINE # 112 000F D296 SETB Direction4_yellow ; SOURCE LINE # 113 0011 AF00 R MOV R7,yellow_delay+01H 0013 AE00 R MOV R6,yellow_delay
0015 120000 R LCALL _MSDelayL ; SOURCE LINE # 114 0018 C296 CLR Direction4_yellow ; SOURCE LINE # 115 001A 22 RET ; FUNCTION Direction4 (END)
; FUNCTION main (BEGIN) ; SOURCE LINE # 117 ; SOURCE LINE # 118 ; SOURCE LINE # 119 0000 120000 R LCALL all_off 0003 ?C0013: ; SOURCE LINE # 120 ; SOURCE LINE # 121 ; SOURCE LINE # 122 0003 120000 R LCALL Direction1 ; SOURCE LINE # 123 0006 120000 R LCALL Direction2 ; SOURCE LINE # 124 0009 120000 R LCALL Direction3 ; SOURCE LINE # 125 000C 120000 R LCALL Direction4 ; SOURCE LINE # 126 000F 80F2 SJMP ?C0013 ; FUNCTION main (END) |
In above code various comment lines are there. To save time of typing or to increase readability of code, you can remove commented lines.
Project Source Code
Project Source Code
###
#include <Reg51.h>
#define OFF 0
#define ON 1
int green_delay = 1000;
int yellow_delay = 150;
sbit Direction1_red = P0^0;//Connect D10
sbit Direction1_yellow = P0^1;//D11
sbit Direction1_green = P0^2;//D12
sbit Direction2_red = P0^5;//D4
sbit Direction2_yellow = P0^6;//D5
sbit Direction2_green = P0^7;//D6
sbit Direction3_red = P1^0;//D1
sbit Direction3_yellow = P1^1;//D2
sbit Direction3_green = P1^2;//D3
sbit Direction4_red = P1^5;//D7
sbit Direction4_yellow = P1^6;//D8
sbit Direction4_green = P1^7;//D9
void MSDelayL(unsigned int dtime)
{
unsigned int i,j;
for(i=0;i<dtime;i++)
for(j=0;j<1275;j++);
}
void all_off()
{
Direction1_red = OFF;
Direction1_yellow = OFF;
Direction1_green = OFF;
Direction2_red = OFF;
Direction2_yellow = OFF;
Direction2_green = OFF;
Direction3_red = OFF;
Direction3_yellow = OFF;
Direction3_green = OFF;
Direction4_red = OFF;
Direction4_yellow = OFF;
Direction4_green = OFF;
}
void Direction1()
{
Direction2_red = ON;
Direction3_red = ON;
Direction4_red = ON;
Direction1_red = OFF;
Direction1_green = ON;
MSDelayL(green_delay);
Direction1_green = OFF;
Direction1_yellow = ON;
MSDelayL(yellow_delay);
Direction1_yellow = OFF;
}
void Direction2()
{
Direction1_red = ON;
Direction3_red = ON;
Direction4_red = ON;
Direction2_red = OFF;
Direction2_green = ON;
MSDelayL(green_delay);
Direction2_green = OFF;
Direction2_yellow = ON;
MSDelayL(yellow_delay);
Direction2_yellow = OFF;
}
void Direction3()
{
Direction1_red = ON;
Direction2_red = ON;
Direction4_red = ON;
Direction3_red = OFF;
Direction3_green = ON;
MSDelayL(green_delay);
Direction3_green = OFF;
Direction3_yellow = ON;
MSDelayL(yellow_delay);
Direction3_yellow = OFF;
}
void Direction4()
{
Direction1_red = ON;
Direction2_red = ON;
Direction3_red = ON;
Direction4_red = OFF;
Direction4_green = ON;
MSDelayL(green_delay);
Direction4_green = OFF;
Direction4_yellow = ON;
MSDelayL(yellow_delay);
Direction4_yellow = OFF;
}
void main(void)
{
all_off();
while(1)
{
Direction1();
Direction2();
Direction3();
Direction4();
}
}
###
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.