找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

刚写好了数码管定时PCB感光器的程序

[复制链接]
admin 发表于 2012-9-2 07:36:01 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
大家一起学习一下,也可以用屏蔽了的那个函数变成时钟,晶振是12M的,高手就不用来看了,做出来后再加个遥控程序进去
#include<reg52.h>
#include<intrins.h>
bit setting;
bit beep;
bit locking1;
bit displayOK;
sbit beepping=P3^7;
sbit Position=P2^0;
sbit Section1=P2^1;
sbit Section2=P2^2;
unsigned char led1;
unsigned char timer;
unsigned char delaytime;
unsigned char CDmsTime,CDsecTime,CDminTime,CDhourTime,CDdayTime,Count;
unsigned char keytemp;
unsigned char num,x;
unsigned char displaynum[10];
//unsigned char code PositionTable[10]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6};
unsigned char code PositionTable[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//unsigned char code Sectiontable[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
//unsigned char code Sectiontable[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code Sectiontable1[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
//unsigned char code Sectiontable2[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
//0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f
void delayus(unsigned char time)
{
unsigned char i;
for(i=0;i<time;i++);
}
void delayms(unsigned char value)
{
while(value--)
{
delayus(190) ;
}
}
void Countdown()
{
if(CDmsTime==0xff)
{
CDmsTime=99;
CDsecTime--;
}
if(CDsecTime==0xff)
{
CDsecTime=59;
CDminTime--;
}
if(CDminTime==0xff)
{
CDminTime=59;
CDhourTime--;
}
if(CDhourTime==0xff)
{
CDhourTime=23;
CDdayTime--;
}
if(CDdayTime==0xff)
{
CDdayTime=6;
}
}
/*void Clockwise()
{
if(CDmsTime==100)
{
CDmsTime=0;
CDsecTime++;
}
if(CDsecTime==60)
{
CDsecTime=0;
CDminTime++;
}
if(CDminTime==60)
{
CDminTime=0;
CDhourTime++;
}
if(CDhourTime==24)
{
CDhourTime=0;
CDdayTime++;
}
if(CDdayTime==8)
{
CDdayTime=1;
}
} */
void display()
{
unsigned char i;
displaynum[0]=PositionTable[CDmsTime%10];
displaynum[1]=PositionTable[CDmsTime/10];
displaynum[2]=PositionTable[CDsecTime%10];
displaynum[3]=PositionTable[CDsecTime/10];
displaynum[4]=PositionTable[CDminTime%10];
displaynum[5]=PositionTable[CDminTime/10];
displaynum[6]=PositionTable[CDhourTime%10];
displaynum[7]=PositionTable[CDhourTime/10];
displaynum[8]=PositionTable[CDdayTime%10];

if(setting)
{
x++;
if(x==50)
x=0;
if(!locking1)
{
if(x>24)
{
if(timer==1)
led1=0x04;
else if(timer==2)
led1=0x08;
else if(timer==3)
led1=0x10;
else if(timer==4)
led1=0x20;
else if(timer==5)
led1=0x40;
}
else
{
led1=0;
}
}
else
{
if(timer==1)
led1=0x04;
else if(timer==2)
led1=0x08;
else if(timer==3)
led1=0x10;
else if(timer==4)
led1=0x20;
else if(timer==5)
led1=0x40;
}
}
else
{
if(CDmsTime==0)
led1=0X02;
else if(CDmsTime==49)
led1=0;
}
displaynum[9]=led1;
for(i=0;i<10;i++)
{
P0=displaynum;
Position=1;
Position=0;
if(i>7)
{
P0=Sectiontable1[i-8];
Section2=1;
Section2=0;
P0=0xff;
delayus(20);
Section2=1;
Section2=0;
}
else
{
P0=Sectiontable1;
Section1=1;
Section1=0;
delayus(20);
P0=0xff;
Section1=1;
Section1=0;
}
}
/* P0=displaynum[8];
Position=1;
Position=0;
Section2=1;
Section2=0;
delayus(20);
P0=0xff;
Section1=1;
Section1=0;
/* if(CDmsTime==0)
led1=1;
if(CDmsTime==49)
led1=0;
{
led1=!led1;
Position=1;
Position=0;
Section2=1;
Section2=0;
delayus(20);
P0=0xff;
Section1=1;
Section1=0;
} */
}
void tim_isr0 (void) interrupt 1
{
TH0=0Xd8;
TL0=0xEF;
if(displayOK)
{
CDmsTime--;
Countdown();
if((CDmsTime==0)&&(CDsecTime==0)&&(CDminTime==0)&&(CDhourTime==0)&&(CDdayTime==0))
{
// TR0=0;
TH0=0XD8;
TL0=0xEF;
displayOK=0;
beep=1;
// TR1=1;
}
}
display();
}
/*void tim_isr1 (void) interrupt 3
{
TH1=0XD8;
TL1=0xEF;
// Countdown();
display();

} */
void keysacn()
{
P1=0xf0;

keytemp=P1;
if(keytemp!=0xf0)
{
delayms(10);
switch(keytemp)
{
case 0xe0:num=1;
break;
case 0xd0:num=2;locking1=!locking1;
break;
case 0xb0:num=3;
break;
case 0x70:num=4;
break;
}
beep=0;
while(keytemp!=0xf0)
{
P1=0xf0;
keytemp=P1;
}
}
P1=0xff;
}
void timesetting()
{
locking1=0;
timer=1;
displayOK=0;
while(setting)
{
num=0;
keysacn();
/*switch(timer)
{
case 1: Count=CDdayTime;
break;
case 2: Count=CDhourTime;
break;
case 3: Count=CDminTime;
break;
case 4: Count=CDsecTime;
break;
case 5: timer=1;
break;
} */
/* if(timer==1)
{
Count=CDdayTime;
}
if(timer==2)
{
Count=CDhourTime;
}
if(timer==3)
{
Count=CDminTime;
}
if(timer==4)
{
Count=CDsecTime;
}
if(timer>=5)
timer=1;
if(timer==0)*/

if(timer==1)
{
Count=CDhourTime;
}
if(timer==2)
{
Count=CDminTime;
}
if(timer==3)
{
Count=CDsecTime;
}
if(timer>=4)
timer=1;
if(timer==0)
timer=3;
if(num==1)
setting=0;
if(num==3)
timer++;
if(num==4)
timer--;
if(num==2)
{
while(locking1)
{
num=0;
keysacn();
if(num==3)
Count++;
if(num==4)
Count--;

switch(timer)
{
/* case 1:
if(Count==0xff)
Count=6;
if(Count==7)
Count=0;
CDdayTime=Count;
break;
case 2:
if(Count==0xff)
Count=23;
if(Count==24)
Count=0;
CDhourTime=Count;
break;
case 3:
if(Count==0xff)
Count=59;
if(Count==60)
Count=0;
CDminTime=Count;
break;
case 4:
if(Count==0xff)
Count=59;
if(Count==60)
Count=0;
CDsecTime=Count;
break;
*/

case 1:
if(Count==0xff)
Count=23;
if(Count==24)
Count=0;
CDhourTime=Count;
break;
case 2:
if(Count==0xff)
Count=59;
if(Count==60)
Count=0;
CDminTime=Count;
break;
case 3:
if(Count==0xff)
Count=59;
if(Count==60)
Count=0;
CDsecTime=Count;
break;
}
if(num==2)
{
locking1=0;
}
}
}
}
TH0=0XD8;
TL0=0xEF;
}
void main()
{
beepping=0;
CDmsTime=0;
CDsecTime=1;
CDminTime=0;
CDhourTime=0;
CDdayTime=0;
displayOK=0;
TMOD=0X11;
TH0=0Xd8;
TL0=0xEF;
// TH1=0XD8;
// TL1=0xEF;
// TR1=1;
// ET1=1;
ET0=1;
EA=1;
TR0=1;
while(1)
{
keysacn();
switch(num)
{
case 1:setting=1;timesetting();
break;
case 2:setting=0;displayOK=1;
break;
case 3:timer++;
break;
case 4:timer--;
}
if(beep)
{
beepping=1;
delayus(15);
beepping=0;
delayus(delaytime);
delaytime++;

}
num=0;
}
}
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 07:52 , Processed in 0.052317 second(s), 10 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表