基于51单片机 红绿灯数码管程序
#define DataPort P0 //定义数据端口 程序中遇到DataPort 则用P0 替换
#define CtrlPort P1 //定义控制端口
unsigned char code DuanMa[10]={0xc0,0xf9,0xa4,0xb0, 0x99,0x92,0x82,0xf8,0x80,0x90};// 显示段码值0~9
unsigned char code WeiMa[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//分别对应相应的数码管点亮,即位码
unsigned char TempData[8]; //存储显示值的全局变量
void Delay(unsigned int t); //函数声明
void Display(unsigned char FirstBit,unsigned char Num);
unsigned char j,k,flag=1,flag1=1,flag2=1,aa=1,bb=1,cc=1,flag22=1;
unsigned char num=25,num1=30,num11=30,num22=25;
void init()
{
TMOD=0x11;
TH1=(65536-50000)/256;
TL1=(65536-50000)%6;
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;
EA=1;
ET1=1;
ET0=1;
TR1=1;
TR0=1;
}
void main()
{
init();
while(1)
{
{
if(flag==1)
{
if(j==20)
}
}
else
if(j==120)
{
j=0;
num=25;
flag=1;
aa=0;
}
}
if(num==0)
{
if(flag1==1)
{
TR0=0;
flag=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;
TR0=1;
flag1=0;
}
}
if(aa==0)
{
num11=30;
aa=1;
}
}
{
if(num1==-1)
{
bb=0;
num1=30;
}
}
if(bb==0)
{
if(cc==1)
{
if(flag22==1)
{
if(k==20)
}
}
else
if(k==120)
{
k=0;
flag22=1;
num22=25;
flag2=1;
bb=1;
}
}
if(num22==0)
{
if(flag2==1)
{
TR1=0;
flag22=0;
TH1=(65536-50000)/256;
TL1=(65536-50000)%6;
TR1=1;
flag2=0;
}
}
}
}
}
void Delay(unsigned int t)
{
}
void Display(unsigned char FirstBit,unsigned char Num)
{
} void exter0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%6; j++; } void exter1() interrupt 3 { TH1=(65536-50000)/256; TL1=(65536-50000)%6; k++; }
51单片机红绿灯数码管程 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)