📄 cllock.c
字号:
#include "avr/io.h"
#include "util/delay.h"
#include "avr/pgmspace.h"
#include "avr/interrupt.h"
const prog_char SegCode[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,/* 0,1,2,3,4,5,6,7,8,9 */
0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x40 /* a,b,c,d,e,f, ,- */
};
#define SPACE 16
#define LINE 17
volatile unsigned char DisBuffer[8];
volatile unsigned long ClockCnt=0;
void TimerConfig(void)
{
TCCR0=(1<<CS01)|(1<<CS00); //控制寄存器,工作方式及时钟选择
TCNT0=(256-250);//计数值
TIMSK=0x01; //中断控制
sei();
}
SIGNAL(TIMER0_OVF_vect)
{
static unsigned char i=0;
static unsigned int Cnt=0;
TCNT0=(256-250);
PORTB = pgm_read_byte(&SegCode[DisBuffer[i]]);
PORTA|= (1<<PA4);
PORTA&=~(1<<PA4);
PORTB = (1<<i);
PORTA|= (1<<PA5);
PORTA&=~(1<<PA5);
i++;
if(i==8)
i=0;
Cnt++;
if(Cnt==500)
{
Cnt=0;
ClockCnt++;
if(ClockCnt>=86400)
ClockCnt=0;
}
}
int main(void)
{
/* Set LED and Smg LE pin as output , databus as output */
DDRA |=(1<<PA4)|(1<<PA5)|(1<<PA6);
DDRB = 0xFF;
/* Off the LED display */
PORTB = 0xFF;
PORTA|= (1<<PA6);
PORTA&=~(1<<PA6);
TimerConfig();
while(1)
{
DisBuffer[0]=ClockCnt/3600/10;
DisBuffer[1]=ClockCnt/3600%10;
DisBuffer[2]=LINE;
DisBuffer[3]=ClockCnt/60/10%6;
DisBuffer[4]=ClockCnt/60%10;
DisBuffer[5]=LINE;
DisBuffer[6]=ClockCnt/10%6;
DisBuffer[7]=ClockCnt%10;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -