基于单片机的交通灯设计c程序文档格式.docx

上传人:b****8 文档编号:22951986 上传时间:2023-02-06 格式:DOCX 页数:19 大小:16.77KB
下载 相关 举报
基于单片机的交通灯设计c程序文档格式.docx_第1页
第1页 / 共19页
基于单片机的交通灯设计c程序文档格式.docx_第2页
第2页 / 共19页
基于单片机的交通灯设计c程序文档格式.docx_第3页
第3页 / 共19页
基于单片机的交通灯设计c程序文档格式.docx_第4页
第4页 / 共19页
基于单片机的交通灯设计c程序文档格式.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

基于单片机的交通灯设计c程序文档格式.docx

《基于单片机的交通灯设计c程序文档格式.docx》由会员分享,可在线阅读,更多相关《基于单片机的交通灯设计c程序文档格式.docx(19页珍藏版)》请在冰豆网上搜索。

基于单片机的交通灯设计c程序文档格式.docx

ucharFlash_Count=0,Operation_Type=1,key,Set_flag,flag=0,x=0,x1=0,x2=0,x3=0,m1,m2,flag_pc=0,temp;

ucharled_seg_code[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

inta=0;

uchartime;

intt,t2,t3,t4;

voidcpuInit()//初始化

{

TMOD=0x21;

//定时器0按方式1工作

//PCON=0x7f;

SCON=0x70;

ET0=1;

EA=1;

TH0=0x3C;

//定时50ms(11.0592M)

TL0=0x0B0;

TH1=0x0f3;

TL1=0x0f3;

ES=1;

TR1=1;

P1=0x0ff;

//关LED

s1=1;

s2=1;

s3=1;

s4=1;

P0=0x00;

P2=0x0ff;

R_E=14;

Y_E=4;

G_E=15;

R_N=19;

Y_N=4;

G_N=10;

}

voidDisplay()//普通模式下显示

//uchartime;

//intt,t2;

uchari;

//intj;

m1=P0;

m2=P0;

switch(Operation_Type)

{

case1:

RED_E=1;

YELLOW_E=1;

GREEN_E=0;

RED_N=0;

YELLOW_N=1;

GREEN_N=1;

if(x==0)

{

i=G_E;

x=1;

time=R_N;

t=time/10;

t2=(int)time%10;

t3=i/10;

t4=(int)i%10;

}

P0=led_seg_code[t2];

s2=0;

s2=1;

P0=led_seg_code[t4];

s4=0;

s4=1;

P0=led_seg_code[t];

s1=0;

s1=1;

P0=led_seg_code[t3];

s3=0;

s3=1;

if(flag==1)

{

flag=0;

i--;

time--;

P0=led_seg_code[t2];

s2=0;

s2=1;

P0=led_seg_code[t4];

s4=0;

s4=1;

P0=led_seg_code[t];

s1=0;

s1=1;

P0=led_seg_code[t3];

s3=0;

s3=1;

if(i==0)

{

x=0;

Operation_Type=2;

}

break;

case2:

GREEN_E=1;

YELLOW_E=0;

x1++;

if(x1==4)

x1=0;

Operation_Type=3;

case3:

RED_E=0;

GREEN_E=1;

RED_N=1;

GREEN_N=0;

if(x2==0)

i=G_N;

x2=1;

time=R_E;

x2=0;

Operation_Type=4;

case4:

GREEN_N=1;

YELLOW_N=0;

x3++;

if(x3==4)

x3=0;

Operation_Type=1;

}

//voiddelay1ms()//1ms延时

//{

//inti,j;

//for(i=2;

i>

0;

i--)

//for(j=248;

j>

j--);

//}

voidkey_analyse()

unsignedcharkey_value;

key_value=P2;

if((key_value&

0x0f)!

=0x0f)//有键按下

smec(150);

key_value=key_value&

0x0f;

key=key_value;

switch(key)

case0x0e:

key=0;

kv_set_E();

break;

//进入东西功能键

case0x07:

kv_set_N();

//进入南北功能键

//case0x0d:

kv_set_pc();

//进入PC机修改

//case0x06:

kv_down_E();

//东西减

//case0x09:

kv_up_N();

//南北加

//case0x05:

kv_down_N();

//南北减

//case0x07:

Kv_Enter();

//确定键

default:

if(type==0)

Display2();

voidkv_set_E()

//uchartime2;

//inttt,tt2;

intn1=0,n2=0;

unsignedcharkey_s,key_d;

key_s=P0;

key_d=P2;

//time2=G_E;

//t=time/10;

//t2=(int)time%10;

while

(1)//k4为确定键

if(k4==0)

{

smec(150);

k4=1;

//P2=0x0ff;

//P0=0x0ff;

}

//time=G_E;

//tt=time2/10;

//tt2=(int)time2%10;

//P0=led_seg_code[tt2];

//s2=0;

//s2=1;

//P0=led_seg_code[tt];

//s1=0;

//s1=1;

if(k2==0)

++G_E;

//东西加

//time2=G_E;

++R_N;

n1++;

//t=time/10;

//t2=(int)time%10;

P0=led_seg_code[n1];

//s2=0;

//s2=1;

//P0=led_seg_code[t];

//s1=0;

//s1=1;

k2=1;

if(k3==0)

--G_E;

--R_N;

n2++;

P0=led_seg_code[n2];

k3=1;

//P0=key_s;

//P2=key_d;

voidkv_set_N()

//time2=G_E;

while

(1)//k1为确定键

if(k1==0)

k1=1;

++G_N;

++R_E;

//time2=G_N;

--G_N;

--R_E;

}

//voidkv_set_pc()

//inti=1;

//while(i)

//{

//

//while(RI==0)

//{

//if(k3==0)//k3键退出

//{

//smec(150);

//i=0;

//break;

//}

//}

//RI=0;

//G_E=SBUF;

//}

voidDisplay2()//智能模式下显示

inti=10;

while(i)

if(flag==1)

flag=0;

i--;

RED_E=1;

RED_N=0;

voidpc_EN()

if(flag_pc==1)

flag_pc=0;

G_E=temp;

R_N=G_E+4;

voidsmec(unsignedcharx)//1MS

unsignedintj;

while(x--)

for(j=0;

j<

80;

j++);

//voidUart_sc2(ucharbyte)

//SBUF=byte;

//while(!

RI);

//RI=0;

//G_E=SBUF;

intmain()

cpuInit();

//初始化

TR0=1;

while

(1)

Display();

key_analyse();

//查询是否有键按下

pc_EN();

voidt0_time()interrupt1

TH0=0X3C;

TL0=0X0B0;

a++;

if(a==20)

a=0;

flag=1;

voidset_pc()interrupt4

RI=0;

temp=SBUF;

flag_pc=1;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1