📄 shizhong.c
字号:
#include<pic.h>
#define uchar unsigned char
#define uint unsigned int
uchar second,minute,hour;
uchar i,counter;
const uchar led_digit[11] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,
0x82,0xf8,0x80,0x90,0xbf};
const uchar led_bit[8] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
//0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f
uchar volatile table[8] = {0,0,10,0,0,10,0,0};
void TMR0_INIT()
{
OPTION = 0X03;//1:16分频
TMR0 = 0X06;
T0IE = 1;
T0IF = 0;
}
void IO_INIT()
{
TRISC = 0X00;
TRISD = 0X00;
TRISE = 0X07;
PORTC = 0X00;
PORTD = 0X00;
}
void KEYSCAN()
{
if(RE0 == 0 )
{
second++;
if(second == 60)
second = 0;
while(RE0 == 0);
}
if(RE1 == 0)
{
minute++;
if(minute == 60)
minute = 0;
while(RE1 == 0);
}
if(RE2 == 0)
{
hour++;
if(hour == 24)
hour = 0;
while(RE2 == 0);
}
}
main()
{
GIE = 1;
TMR0_INIT();
IO_INIT();
while(1)
{
// if(RE0==1&&RE1==1&&RE2==1)
// {
if(counter == 250)
{
second++;
counter = 0;
}
if(second == 60)
{
second = 0;
minute++;
}
if(minute == 60)
{
minute = 0;
hour++;
}
if(hour == 24)
{
hour =0;
}
// }
// else
KEYSCAN();
table[7] = hour/10;
table[6] = hour%10;
table[4] = minute/10;
table[3] = minute%10;
table[1] = second/10;
table[0] = second%10;
}
}
void interrupt tmr0()
{
// if(T0IF == 1)
//{
T0IF = 0;
TMR0 = 0X06;
counter++;
PORTC = led_digit[table[i]];
PORTD = led_bit[i];
i++;
if(i == 7)
i = 0;
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -