里面带仿真带程序
单片机源程序如下:
- #include <reg52.h>
- #define INT8U unsigned char
- #define INT16U unsigned int
- sbit RED_A = P1^0;
- sbit YELLOW_A = P1^1;
- sbit GREEN_A = P1^2;
- sbit RED_B = P1^4;
- sbit YELLOW_B = P1^5;
- sbit GREEN_B = P1^6;
- INT8U Flash_Count = 0,Operation_Type = 1;//闪烁次数及操作类型变量定义
- void delay_ms(INT16U x)
- {
- INT8U t;
- while(x--)
- for(t = 0;t < 120; t++);
- }
- void Traffic_light()
- {
- switch (Operation_Type)
- {
- case 1:
- RED_A = 1; YELLOW_A = 1; GREEN_A = 0;
- RED_B = 0; YELLOW_B = 1; GREEN_B = 1;
- delay_ms(2000);
- Operation_Type = 2;
- break;
- case 2:
- delay_ms(300);
- YELLOW_A = ~YELLOW_A; GREEN_A = 1;
- if (++Flash_Count != 10)
- return;
- Flash_Count = 0;
- Operation_Type = 3;
- break;
- case 3:
- RED_A = 0; YELLOW_A = 1; GREEN_A = 1;
- RED_B = 1; YELLOW_B = 1; GREEN_B = 0;
- delay_ms(2000);
- Operation_Type = 4;
- break;
- case 4:
- delay_ms(300);
- YELLOW_B = ~YELLOW_B; GREEN_B = 1;
- if (++Flash_Count != 10)
- return;
- Flash_Count = 0;
- Operation_Type = 1;
- }
- }
- void main()
- {
- while(1)
- Traffic_light();
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
3-4LED模拟交通灯.zip
(31.38 KB, 下载次数: 7)
|