標(biāo)題:
單片機可調(diào)時鐘
[打印本頁]
作者:
鷙鳥微塵
時間:
2017-6-15 15:26
標(biāo)題:
單片機可調(diào)時鐘
56(M`@}SK$B1XZIF5~KXRJP.png
(4.59 KB, 下載次數(shù): 68)
下載附件
仿真圖
2017-6-15 15:25 上傳
#include"reg52.h"
#include"intrins.h"
sbit add=P1^0;
sbit dec=P1^1;
sbit key=P3^2;
#define uchar unsigned char
#define uint unsigned int
int tab[6],x,y,z,n,a,b,c,o;
void delay20ms(void) //軟件延時子程序
{
unsigned char i,j;
for(i=0;i<100;i++)
for(j=0;j<60;j++)
;
}
uchar code SEG[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void delay()
{uint i;
for(i=0;i<500;i++);
}
void chaifen()
{
tab[0]=x%10;
tab[1]=x/10;
tab[2]=y%10;
tab[3]=y/10;
tab[4]=z%10;
tab[5]=z/10;
}
void main()
{
TMOD=0x01;
TH0=0x3c;
TL0=0xb0;
EA=1;
EX0=1;
PX0=1;
TR0=1;
ET0=1;
n=0;
x=0;
y=0;
z=0;
chaifen();
while(1)
{
uchar i;
P2=0x40;
for(i=0;i<6;i++)
{
P2=_cror_(P2,1);
P0=SEG[tab[i]];
delay();
}
}
}
void wai() interrupt 0
{
while(!key)
{
a=x;
b=y;
c=z;
if (add==0)
{
delay20ms();
while(add==0);
a++;
}
else if(dec==0)
{
delay20ms();
while(dec==0);
a--;
}
x=a;
y=b;
z=c;
if(x==(60))
{
x=0;
y++;
if(y==(60))
{
y=0;
z++;
if(z==(24))
{z=0;}
}
}
if(x==(-1))
{
x=59;
y--;
if(y==(-1))
{
y=59;
z--;
if(z==(-1))
{z=23;}
}
}
P2=0x40;
for(o=0;o<6;o++)
{
P2=_cror_(P2,1);
P0=SEG[tab[o]];
delay();
}
chaifen();
}
}
void timer() interrupt 1
{
n++;
if(n==10)
{
n=0;
x--;
if(x==(-1))
{
x=59;
y--;
if(y==(-1))
{
y=59;
z--;
if(z==(-1))
{z=23;}
}
}
chaifen();
}
TH0=0x3c;
TL0=0xb0;
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1