code
int conv7segment(int number);
main()
{
int i;
TRISB = 0x00;
CMCON = 0x07;
TRISA = 0xFF;
i = 0;
while(1)
{
while(PORTA.F0==0)
{
i++;
if(i>9)
{
i = 0;
}
while(PORTA.F0==0)
{
Delay_ms(10);
}
}
while(PORTA.F1==0)
{
i--;
if(i<0)
{
i = 9;
}
while(PORTA.F1==0)
{
Delay_ms(10);
}
}
PORTB = conv7segment(i);
}
}
int conv7segment(int number)
{
switch(number)
{
case 1: return 0x06;
case 2: return 0x5b;
case 3: return 0x4f;
case 4: return 0x66;
case 5: return 0x6d;
case 6: return 0x7d;
case 7: return 0x07;
case 8: return 0x7f;
case 9: return 0x6f;
case 0: return 0x3f;
}
}
No comments:
Post a Comment