十年专注单片机方案开发的方案公司英锐恩,分享秒表在MCD2配套的实验板可以运行。英锐恩现提供服务产品涉及主控芯片:8位单片机、16位单片机、32位单片机及各类运算放大器等。
#include//PIC16F877A
static int table[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
static int table1[6]={0xef,0xdf,0xfb,0xf7,0xfe,0xfd};
int sreg=0x00;
int i;
int s0=0x00,s1=0x00,s2=0x00,s3=0x00,s4=0x00,s5=0x00;
void INITIAL()
{
TRISC=0x00;
TRISA=0x00;
TRISB0=1;
}
void tmint()
{
T0CS=0;
PSA=1;
T0IF=0;
T0IE=1;
}
void DELAY()
{
for(i=300;--i;){;}
}
void DELAY2()
{
for(i=2000;--i;){;}
}
void displays()
{
PORTA=table1[0];
PORTC=table[s0];
DELAY();
PORTA=table1[1];
PORTC=table[s1];
DELAY();
PORTA=table1[2];
PORTC=table[s2];
DELAY();
PORTA=table1[3];
PORTC=table[s3];
DELAY();
PORTA=table1[4];
PORTC=table[s4];
DELAY();
PORTA=table1[5];
PORTC=table[s5];
DELAY();
}
void KEYSCAN()
{
while(1)
{
while(1)
{
displays();
if(RB0==0) break;
}
DELAY2();
if(RB0==0) break;
}
}
void keyrelax()
{
while(1)
{
displays();
if(RB0==1) break;
}
}
void interrupt clkint(void)
{
TMR0=0X13;
T0IF=0;
CLRWDT();
sreg++;
if(sreg==40)
{
sreg=0;
s0++;
if(s0==10)
{ s0=0;
s1++;
if(s1==10)
{ s1=0;
s2++;
if(s2==10)
{ s2=0;s3++;
if(s3==6)
{ s3=0;
s4++;
if(s4==10)
{s4=0; s5++;
if(s5==6) s5=0;
}
}
}
}
}
}
}
main()
{
tmint();
INITIAL();
di();
while(1)
{
KEYSCAN();
keyrelax();
ei();
TMR0=0X08;
KEYSCAN();
keyrelax();
di();
KEYSCAN();
keyrelax();
ei();
}
}
分辩度0.01S.
RB0控制启动,停止,启动.
(文源网络,侵删)