交通灯程序:跪求一汇编交通灯程序!高手请进~~不胜感激

*/

交通灯程序:跪求一汇编交通灯程序!高手请进~~不胜感激

#include \"reg51.h\"

#define UINT unsigned int

#define ULONG unsigned long

#define UCHAR unsigned char

/*

信号灯变量

南北方向绿灯

sbit n_bike_g = P1^0; //自行车

sbit n_right_g = P1^1; //右转

sbit n_up_g = P1^2; //直行

sbit n_left_g = P1^3; //左转 调头

南北方向红灯

sbit n_bike_r = P1^4; //自行车

sbit n_right_r = P1^5; //右转

sbit n_up_r = P1^6; //直行

sbit n_left_r = P1^7; //左转 调头

南北方向黄灯

sbit n_bike_y = P3^0; //自行车

sbit n_right_y = P3^1; //右转

sbit n_up_y = P3^2; //直行

sbit n_left_y = P3^3; //左转 调头

东西方向绿灯

sbit e_bike_g = P2^0; //自行车

sbit e_right_g = P2^1; //右转

sbit e_up_g = P2^2; //直行

东西方向红灯

sbit e_bike_r = P2^4; //自行车

sbit e_right_r = P2^5; //右转

sbit e_up_r = P2^6; //直行

东西方向黄灯

sbit e_bike_y = P3^4; //自行车

sbit e_right_y = P3^5; //右转

sbit e_up_y = P3^6; //直行

*/

//延时

void delay(UINT t, UINT s)

{

while (t)

{

UINT i;

for (i = 0; i < s; i++)

{

}

t --;

}

}

//信号灯状态

void time_x(UCHAR P_P1, UCHAR P_P2, UCHAR P_P3)

{

P1 = P_P1;

P2 = P_P2;

P3 = P_P3;

delay(150, 65535);

}

void time_s(UCHAR P_P1, UCHAR P_P2, UCHAR P_P3, UCHAR P_P11, UCHAR P_P22)

{

UINT i;

for (i = 0; i < 3; i ++)

{

P1 = P_P1;

P2 = P_P2;

delay(5, 65535);

P1 = P_P11;

P2 = P_P22;

delay(5, 65535);

}

P1 = P_P1;

P2 = P_P2;

P3 = P_P3;

delay(10, 65535);

}

//主程序

void main()

{

P1 = P2 = P3 = 0x0;

while (1)

{

time_x(0xA5, 0x38, 0x0);

time_s(0xA4, 0x38, 0x1, 0xA5, 0x38);

time_x(0x96, 0x52, 0x0);

time_s(0x92, 0x52, 0x4, 0x96, 0x52);

time_x(0x5A, 0x52, 0x0);

time_s(0x50, 0x50, 0x2A, 0x5A, 0x52);

time_x(0xF0, 0x25, 0x0);

time_s(0xF0, 0x24, 0x20, 0xF0, 0x25);

time_x(0xD2, 0x16, 0x0);

time_s(0xD0, 0x10, 0x62, 0xD2, 0x16);

}

}

Dai_Weis 于 2005-5-4 13:43:23

说明交通灯程序

固定时间信号变换,南北设置调头交通灯程序、左传、直行、右转、自行车。

东西设置左传、直行、右转、自行车交通灯程序。

时序状态:

红 绿 红 绿

序号 左 前 右 自 左 前 右 自 前 右 自 前 右 自

1 1 0 1 0 0 1 0 1 1 1 1 0 0 0

2 1 0 0 1 0 1 1 0 1 0 1 0 1 0

3 0 1 0 1 1 0 1 0 1 0 1 0 1 0

4 1 1 1 1 0 0 0 0 0 1 0 1 0 1

5 1 1 0 1 0 0 1 0 0 0 1 1 1 0