//數碼管動態掃描,k1按下,數字+1,K2按下,數字-1,每次按下的同時,聽到DD二聲。
#include<pic.h>
#define uchar unsigned char
#define uint unsigned int
__CONFIG(0x3B31);
uint a;
const uchar aa[]=
{0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90};
void delay(uchar x)//延時函數
{
uchar a;
for(;x>0;x--)
for(a=220;a>0;a--);
}
void init()//初始化
{
TRISC=0xFF;
TRISD=0x00;
TRISB=0x00;
PORTD=0xff;
PORTC=0xFF;
}
void ss(uchar a,uchar b,uchar c)//數碼管顯示部份
{
PORTB=aa[a];
RD3=0;
delay(5);
RD3=1;
PORTB=aa;
RD4=0;
delay(5);
RD4=1;
PORTB=aa[c];
RD5=0;
delay(5);
RD5=1;
}
void kk()//按制掃描程序
{
if(RC0==0)//看k1是否按下
{
delay(5);
if(RC0==0)
{
a++;
if(a==1000)
{a=0;}
}
while(!RC0)
{
ss(a/100,a%100/10,a%10);
RD6=0;
}
RD6=1;
}
if(RC1==0)//看K2是否按下
{
delay(5);
if(RC1==0)
{
a--;
if(a==0)
{a=999;}
}
while(!RC1)
{
ss(a/100,a%100/10,a%10);
RD6=0;
}
RD6=1;
}
}
void main()
{
init();
while(1)
{
kk();
ss(a/100,a%100/10,a%10);
}
}
|