您的当前位置:首页正文

交通灯实训报告

2022-11-28 来源:星星旅游


#include

#define uchar unsigned char #define uint unsigned int uchar i,j=2,q=2,z; sbit RED_A=P0^0;

sbit YELLOW_A=P0^1; sbit GREEN_A=P0^2; sbit RED_B=P0^3;

sbit YELLOW_B=P0^4; sbit GREEN_B=P0^5; sbit key1=P3^0; sbit key2=P3^3; sbit key3=P3^4;

uchar Flash_Count = 0; Operation_Type = 1;

uchar dsy_code1[]={0x6f,0x7f,0x07,0x7d,0x6d,0x66,0x4f,0x5b,0x06,0x3f}; uchar Dsy_code2[]={0x5b,0x06,0x3f};

uchar Dsy_code4[]={0x66,0x4f,0x5b,0x06,0x3f}; uchar Dsy_code5[]={0x4f,0x5b,0x06,0x3f};

uchar Dsy_code6[]={0x6d,0x66,0x4f,0x5b,0x06,0x3f}; void DelayMS(uint x) {

uchar t,y; while(x--) { for(t=0;t<120;t++) for(y=0;y<120;y++); } }

void Traffic_lignt() {

switch(Operation_Type) { case 1:P1=0x4f; for(z=0;z<6;z++) {

RED_A=1;YELLOW_A=1;GREEN_A=0; RED_B=0;YELLOW_B=1;GREEN_B=1; P2=Dsy_code6[z]; DelayMS(20); }

P1=0x5b; while(q!=5) {

for(i=0;i<10;i++) {

RED_A=1;YELLOW_A=1;GREEN_A=0; RED_B=0;YELLOW_B=1;GREEN_B=1; P2=dsy_code1[i]; DelayMS(20); if(i==9) {

P1=Dsy_code5[q]; q=q+1; } } } Operation_Type = 2; break; case 2:

for(i=0;i<5;i++) {

GREEN_A=1; P2=Dsy_code4[i]; P1=0x00; YELLOW_A=~YELLOW_A; DelayMS(20); } Flash_Count=0; Operation_Type = 3; break; case 3: P1=0x66;

for(z=0;z<6;z++) {

RED_A=0;YELLOW_A=1;GREEN_A=1; RED_B=1;YELLOW_B=1;GREEN_B=0; P2=Dsy_code6[z]; DelayMS(20); }

P1=0x4f; while(j!=6) {

for(i=0;i<10;i++) {

RED_A=0;YELLOW_A=1;GREEN_A=1; RED_B=1;YELLOW_B=1;GREEN_B=0; P2=dsy_code1[i]; DelayMS(20); if(i==9) {

P1=Dsy_code4[j]; j=j+1; } } } Operation_Type = 4; break; case 4: for(i=0;i<5;i++) {

GREEN_B=1; P2=Dsy_code4[i]; P1=0x00; YELLOW_B=~YELLOW_B; DelayMS(20); } Flash_Count=0; Operation_Type = 1; break; } }

void main() {

while(1) {

EA=1;EX0=1;EX1=1; IT0=0;IT1=0;ET0=1; TMOD=0x01; TR0=1; TH0=(65535-500)/256; TL0=(65535-500)%256; j=2;q=2; Traffic_lignt(); } }

void key1_() interrupt 0 {

RED_A=0;RED_B=0;YELLOW_A=1;YELLOW_B=1; GREEN_A=1;GREEN_B=1; DelayMS(5); }

void key2_() interrupt 2 {

RED_A=0;RED_B=1;YELLOW_A=1;YELLOW_B=1; GREEN_A=1;GREEN_B=0; DelayMS(5); }

void time_() interrupt 1 {

if(key3==0) {

RED_A=1;RED_B=0;YELLOW_A=1;YELLOW_B=1; GREEN_A=0;GREEN_B=1;DelayMS(5); } }

因篇幅问题不能全部显示,请点此查看更多更全内容