#include <iom16v.h>
#include <macros.h>
unsigned char const NUM[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //共阴数码管段码表
unsigned char num=0;
void delay_ms(unsigned int times)
{
unsigned int i,j;
for (i=0;i<times;i++)
for (j=0;j<1140;j++);
}
void display_num()
{
PORTC&=~BIT(0); //第一个数码管位选设置为0(共阴)
PORTA=NUM[num/10];
delay_ms(5);
PORTC|=BIT(0);
PORTC&=~BIT(1);
PORTA=NUM[num%10];
delay_ms(5);
PORTC|=BIT(1);
}
void check_key()
{
if ((PINC&BIT(0))!=BIT(0)) //如果按键1为低电平
{
delay_ms(100);
if ((PINC&BIT(0))!=BIT(0))
{
num++;
if (num>99)
num=0;
while ((PINC&BIT(0))!=BIT(0));
}
}
if ((PINC&BIT(1))!=BIT(1))
{
delay_ms(100);
if ((PINC&BIT(1))!=BIT(0))
{
if (num==0)
num=99;
else
num--;
while ((PINC&BIT(1))!=BIT(0));
}
}
}
void main()
{
/*DDRA=PORTC=DDRB=PORTB=0xff;
DDRC=0xcf;
PORTA=NUM[0];
while (1)
{
display_num();
check_key();
if (num%2==0)
PORTB=BIT(0);
else
PORTB=0xff;
}*/
DDRA=0xff;
DDRC=0xff;
while (1)
{
PORTA=0xff;
PORTC=0xff;
}
}