📄 app.c
字号:
#include "avr/io.h"
#include "util/delay.h"
#include "avr/pgmspace.h"
#include "avr/interrupt.h"
const prog_char SegCode[16]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
volatile unsigned char DisBuffer[8];
void TimerConfig(void)
{
TCCR0=(1<<CS01)|(1<<CS00); //控制寄存器,工作方式及时钟选择
TCNT0=(256-250);//计数值
TIMSK=0x01; //中断控制
sei();
}
SIGNAL(TIMER0_OVF_vect)
{
static unsigned char i=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;
}
void delay_ms(unsigned int ms)
{
while(ms--)
_delay_ms(1);
}
int main(void)
{
unsigned int Count=0;
/* 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)
{
Count++;
DisBuffer[0]=0;
DisBuffer[1]=0;
DisBuffer[2]=0;
DisBuffer[3]=Count/10000%10;
DisBuffer[4]=Count/1000%10;
DisBuffer[5]=Count/100%10;
DisBuffer[6]=Count/10%10;
DisBuffer[7]=Count/1%10;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -