📄 app.c
字号:
#include "avr/io.h"
#include "avr/pgmspace.h"
#include "avr/interrupt.h"
/* FCPU : 1Mhz
* CPU : ATMega16 */
const prog_char SIN[]={
128,131,134,137,140,143,146,149,152,155,158,162,165,167,170,173,
176,179,182,185,188,190,193,196,198,201,203,206,208,211,213,215,
218,220,222,224,226,228,230,232,234,235,237,238,240,241,243,244,
245,246,248,249,250,250,251,252,253,253,254,254,254,255,255,255,
255,255,255,255,254,254,254,253,253,252,251,250,250,249,248,246,
245,244,243,241,240,238,237,235,234,232,230,228,226,224,222,220,
218,215,213,211,208,206,203,201,198,196,193,190,188,185,182,179,
176,173,170,167,165,162,158,155,152,149,146,143,140,137,134,131,
128,124,121,118,115,112,109,106,103,100, 97, 93, 90, 88, 85, 82,
79, 76, 73, 70, 67, 65, 62, 59, 57, 54, 52, 49, 47, 44, 42, 40,
37, 35, 33, 31, 29, 27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11,
10, 9, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9,
10, 11, 12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35,
37, 40, 42, 44, 47, 49, 52, 54, 57, 59, 62, 65, 67, 70, 73, 76,
79, 82, 85, 88, 90, 93, 97,100,103,106,109,112,115,118,121,124};
void TimerConfig(void)
{
/* WGM[1;0]=[1,1] : Fast PWM
* COM[1;0]=[1,1] : Set OC0 on compare match, clear OC0 at BOTTOM
* CS0[2:0]=[0,1,0] : Clock=FCPU/8 (From prescaler) */
TCCR0=(1<<WGM00)|(1<<WGM01)|(1<<COM01)|(1<<COM00)|(0<<CS02)|(1<<CS01)|(0<<CS00);
/* Set the value of Timer/Counter Register to 0 */
TCNT0= 0x00;
/* Set the value of Output Compare Register to half of the top(255) value */
OCR0 = 127;
/* Enable the tim0 ISR */
TIMSK|=(1<<OCIE0);
/* Enable the ISR */
sei();
}
int main(void)
{
/* Set LED and Seg LE pin as output , databus as output */
DDRA |=(1<<PA4)|(1<<PA5)|(1<<PA6);
DDRB = 0xFF;
/* Off the Seg display */
PORTB = 0x00;
PORTA|= (1<<PA4)|(1<<PA5);
PORTA&=~((1<<PA6)|(1<<PA5));
/* Off the led and enable the Led LE */
PORTB = 0xFF;
PORTA|= (1<<PA6);
TimerConfig();
while(1)
{
;
}
return 0;
}
SIGNAL(TIMER0_COMP_vect)
{
static unsigned char x_LUT=0;
OCR0=pgm_read_byte(&SIN[x_LUT++]);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -