標(biāo)題:
八位數(shù)碼管時(shí)鐘 利用單片機(jī)INT0,INT1兩個(gè)引腳的中斷程序
[打印本頁]
作者:
dashisong
時(shí)間:
2018-1-17 20:33
標(biāo)題:
八位數(shù)碼管時(shí)鐘 利用單片機(jī)INT0,INT1兩個(gè)引腳的中斷程序
八位數(shù)碼管時(shí)鐘。利用 INT0,INT1兩個(gè)引腳的中斷程序
#include<reg51.h>
sbit led=P1^0;
sbit led1=P1^1;
sbit led2=P1^2;
sbit led3=P1^3;
sbit led4=P1^4;
sbit led5=P1^5;
sbit led6=P1^6;
sbit led7=P1^7;
unsigned char t[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned int h,m,s;
void ys()
{
int k;
for(k=125;k>0;k--);
}
void js()
{
s++;
if(s==60)
{
s=0;
m++;
if(m==60)
{
m=0;
h++;
if(h==24)
{
h=0;
}
}
}
}
void xs()
{
led=1;
P2=t[h/10];
ys();
led=0;
led1=1;
P2=t[h%10];
ys();
led1=0;
led2=1;
P2=0xbf;
ys();
led2=0;
led3=1;
P2=t[m/10];
ys();
led3=0;
led4=1;
P2=t[m%10];
ys();
led4=0;
led5=1;
P2=0xbf;
ys();
led5=0;
led6=1;
P2=t[s/10];
ys();
led6=0;
led7=1;
P2=t[s%10];
ys();
led7=0;
}
void main()
{
EX0=1;
EX1=1;
EA=1;
while(1)
{
xs();
js();
}
}
void w() interrupt 0
{
while(INT0==0);
h=0;m=0;s=0;
}
void w1() interrupt 2
{
while(INT1==0);
h--;if(h==0) h=24;
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1