#include<reg52.h>//包含头文件,一般情况不需要改动,
//头文件包含特殊功能寄存器的定义
sbit LACTCH1=P2^2;
sbit LACTCH2=P2^3;
/*------------------------------------------------
全局变量
------------------------------------------------*/
bit red,green,yellow,turnred;//定义红绿黄灯标志位
code unsigned char tab[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//共阴数码管 0-9
unsigned char Dis_Shiwei;//定义十位
unsigned char Dis_Gewei; //定义个位
/*------------------------------------------------
------------------------------------------------*/
void delay(unsigned int cnt)
{
while(--cnt);
}
/*------------------------------------------------
主程序
------------------------------------------------*/
main()
{
TMOD |=0x01;//定时器设置 10ms in 12M crystal
TH0=0xd8;
TL0=0xf0;
IE= 0x82; //打开中断
TR0=1;
P1=0xfc; //红灯亮
red =1;
while(1)
{
P0=Dis_Shiwei;//显示十位
LACTCH1=1;
【51单片机】交通灯2
于 2024-03-03 11:30:38 首次发布