单片机源程序如下:
#include # include #define uchar unsigned char //定义为uchar类型 #define uint unsigned int //定义为uint类型 # define COM XBYTE[0XFE00] //控制字地址(总控制,决定了PA/B/C是写还是读等) # define PA XBYTE[0XFE01] //控制PA地址(总控制写的是读时,里面存的是读的值; // 写的是写时,里面要写入控制值) # define PB XBYTE[0XFE02] //控制PB地址 # define PC XBYTE[0XFE03] //控制PC地址 sbit g = P2^1; sbit s = P2^2; sbit eg = P2^3; sbit ws = P2^4; //sbit Key_N = P1^4; //独立按键 //sbit Key_S = P1^5; //sbit Key_W = P1^6; //sbit Key_E = P1^7; sbit KEYA = P1^4; sbit KEYB = P1^5; uint ge,shi; //定义全局变量 uint m = 30; uint n; uint num; /*交通灯的数值*/ uchar lcd1 = 10; //倒计时初始值为25用于改变 uchar lcd2 = 15; //的倒计时初始值为30用于改变 uchar lcd11; //倒计时 uchar lcd22; //倒计时 uchar change1; //LCD1红绿灯转换 uchar yellow1 = 3; /*一些辅助标志位的声明*/ uchar code smguan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //数码管显示0~9 uchar t=3; uchar sign = 0; uchar time_Count; //进行计时 void delay(uint t) { while(t--); } void Digital(uint ge,uint shi) //数码管显示 { PA = smguan[ge]; s = 1; delay(500); s = 0; PA = smguan[shi]; g = 1; delay(500); g = 0; PB = smguan[ge]; eg = 1; delay(500); eg = 0; PB = smguan[shi]; ws = 1; delay(500); ws = 0; } void Traffic_lights() { if(t == 3) { P1 = 0x01; if(m == 0) { m = 3; t = 2; } } if(t == 2) { P1 = 0x02; if(m == 0) { m = 30; t = 1; } } if(t == 1) { P1 = 0x04; if(m == 0) { m = 3; t = 0; } } if(t == 0) { P1 = 0x02; if(m == 0) { m = 30; t = 3; } } } void INIT() { IT0=1; IT1=1; EX0=1; EX1=1; EA=1; }
设计资源 培训 开发板 精华推荐
- LTC1402 串行 12 位、2.2 Msps 采样 ADC 的典型应用
- CH347-Flash-Programmer
- NCV78763R1DAGEVB:NCV78763 子板
- DER-653 - 使用BridgeSwitch电机驱动器和LinkSwitch-TN2的300 W三相变频器
- 103板
- LTC222 的典型应用 - 具有数据锁存器的微功率、低电荷注入、四通道 CMOS 模拟开关
- ADC120 8通道,50ksps至1Msps,12位模数转换器的评估板
- BD49L39电压检测IC在BD49xxx系列中的典型应用
- NCP1580DEMO/D,基于NCP1580同步降压转换器的演示板
- OP284ESZ-REEL 缓冲网络补偿容性负载的典型应用