#include <iom16v.h>
#include <macros.h>
unsigned char table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned int num=0;
void delay(unsigned int i) //1ms延时函数
{
while(i--)
{
unsigned int j;
for(j=1;j<=613;j++)
;
}
}
void display(unsigned int shu) //数码管显示函数
{
int shi,ge;
shi=shu%100/10;
ge=shu%10;
PORTB=0xfb;
PORTD=table[shi];
delay(5);
PORTB=0xf7;
PORTD=table[ge];
delay(5);
}
void keyscan(void)
{
if((PINC&(1<<PC0))==0) //按键1判断
{
delay(10);
if((PINC&(1<<PC0))==0)
{
num++;
while(!(PINC&(1<<PC0)));
}
}
}
void main(void)
{
DDRD=0XFF; //端口初始化,D口是段选,B口是位选
PORTD=0Xff;
DDRB=0XFF;
PORTB=0Xff;
DDRC=0X01;
PORTC=0Xff;
PORTB=0x00; //上电全亮
PORTD=0x3f;
while(1)
{
keyscan();
display(num);
}
}
|