|
#include<pic.h>
__CONFIG(0x20d2);
__CONFIG(0xffff);
#define uint unsigned int
#define uchar unsigned char
const uchar table[]=
{
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f
};
const uchar chair[]=
{
0xbf,0x86,0xdb,0xcf,0xe6,
0xed,0xfd,0x87,0xff,0xef
};
uchar aa,shim,miao,haom;
uint b;
void delay(uint);
void init()
{
b=0;
TRISA=0x00;
TRISB=0x00;
TRISC=0x00;
TRISE=0x00;
INTCON=0b10100000;
TMR0=217;
}
void main()
{
init();
while(1)
{
if(RB0==0)
{
INTCON=0b00000000;
}
if(RB1==0)
{
INTCON=0b10100000;
}
if(RB2==0)
{
b=0;
}
if(aa==50)
{
aa=0;
b++;
if(b==1000)
{
b=0;
}
shim=b/100;
miao=b%100/10;
haom=b%10;
}
RE2=1;
PORTC=table[shim];
delay(1);
RE1=1;
PORTC=chair[miao];
delay(1);
RE0=1;
PORTC=table[haom];
delay(1);
}
}
void delay(uint x)
{
uint i,j;
for(i=0;i<x;i++)
for(j=125;j>0;j--);
}
void interrupt ISR(void)
{
if(T0IF==1)
{
T0IF=0;
TMR0=248;//TMR0赋初值,定时2ms
aa++;
}
}
|
|