网站大量收购独家精品文档,联系QQ:2885784924

单片机交通灯C语言设计(附带电路图).doc

  1. 1、本文档共10页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
单片机交通灯C语言设计(附带电路图)

#includereg51.h #define uchar unsigned char #define uint unsigned int uchar code seg7[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; uchar cs,second_counts; uchar k; uchar Flash_count=0,Operation_type=1; //east and west leds sbit RED_A=P2^0; sbit YELLOW_A=P2^1; sbit GREEN_A=P2^2; //south and north leds sbit RED_B=P2^3; sbit YELLOW_B=P2^4; sbit GREEN_B=P2^5; //7segments control bits sbit S1=P3^0; sbit S2=P3^1; sbit S3=P3^2; sbit S4=P3^3; //Delay function void Delay(uchar ms) { uchar j; while(ms--) for(j=0;j120;j++); } //east and west leds control funtion void East_West_Leds() { //south green leds on //让东、西的灯和南、北的灯亮时不冲突,即东、西灯亮绿灯时南、北灯亮红灯// RED_A=1; YELLOW_A=1; GREEN_A=0; //east red leds on // 符合实际交通 // RED_B=0; YELLOW_B=1; GREEN_B=1; } //east and west 7segments control function void East_West_7seg() { S1=0; S2=0; S3=0; S4=0; if(second_counts0) { S1=1; S2=0; P1=seg7[second_counts/10]; Delay(2); S1=0; S2=1; P1=seg7[second_counts%10]; Delay(2); } } //east and west flashing void East_West_Flash() { GREEN_A=1; YELLOW_A=!YELLOW_A; S1=0; S2=0; Delay(500); for(k=0;k10;k++) East_West_7seg(); } //south and north leds control funtion void South_North_Leds() { //south green leds on RED_A=0; YELLOW_A=1; GREEN_A=1; //east red leds on RED_B=1; YELLOW_B=1; GREEN_B=0; } //south and north 7segments control function void South_North_7seg() { S1=0; S2=0; S3=0; S4=0; if(second_counts0) { S3=1; S4=0; P1=seg7[second_counts/10]; Delay(2); S3=0; S4=1; P1=seg7[second_counts%10]; Delay(2); } } //south led flashing void South_North_Flash() { GREEN_B=1; YELLOW_B=!YELLOW_B; S3=0; S4=0; Delay(500); for(k=0;k10;k++) South_North_7seg(); } //traffic function void Traffic() { switch (Operation_type) { //east go,south stop case 0: { East_West_Leds(); while(second_counts3) East_West_7seg(); while(sec

您可能关注的文档

文档评论(0)

qwd513620855 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档