void beep(void);
int display_led(int in);
main()
{
int i,j,time_n;
TRISB = 0x00;
CMCON = 0x07;
TRISA = 0xfd;
while(1)
{
time_n =120;
while(PORTA.F0==1)
{
time_n++;
if(time_n>240)
{
time_n=120;
}
}
j=1;
for(i=1;i<time_n;i++)
{
PORTB = display_led(j);
beep();
Delay_ms(10);
j++;
if(j>6)
{
j = 1;
}
}
}
}
int display_led(int in)
{
switch (in)
{
case 1:return 0b0001000;
case 2:return 0b0010100;
case 3:return 0b0101010;
case 4:return 0b1100011;
case 5:return 0b1101011;
case 6:return 0b1110111;
}
}
void beep ( void )
{
int i_b;
for(i_b=0;i_b<20;i_b++)
{
PORTA.F1=1;
Delay_us(300);
PORTA.F1=0;
Delay_us(300);
}
}
No comments:
Post a Comment