/*******************************************************************
實(shí)驗(yàn)名稱(chēng):產(chǎn)生正弦波演示實(shí)驗(yàn)
器件:ATmega16L
晶振:外部 12M
接線方法:
1.PD5接低通濾波輸入
2.用示波器測(cè)其輸出波形
*******************************************************************/
#include
#include
#include
#pragma interrupt_handler timer1:9
char auc_SinParam[128]={//128點(diǎn)正弦波樣本值
128,134,140,147,153,159,165,171,177,182,188,193,198,204,208,213,
218,222,226,230,233,237,240,242,245,247,249,251,252,253,254,254,
254,254,253,252,251,250,248,246,244,241,238,235,232,228,224,220,
215,211,206,201,196,191,185,179,174,168,162,156,150,144,137,131,
125,119,112,106,100,94,88,82,77,71,65,60,55,50,45,41,
36,32,28,24,21,18,15,12,10,8,6,5,4,3,2,2,
2,2,3,4,5,7,9,11,14,16,19,23,26,30,34,38,
43,48,52,57,63,68,74,79,85,91,97,103,109,116,122,128
};
char x=0;
//T/C1溢出中斷服務(wù)
void timer1(void)
{
x=x+1;
if (x>128)
x=0;
OCR1A=auc_SinParam[x];//auc_SinParam[x];//取樣點(diǎn)指針到比較匹配寄存器
}
void main(void)
{
DDRD=0xff;//PB3輸出方式,作為OC0輸出PWM波
TIMSK=0x04; //中斷屏蔽位,沒(méi)有開(kāi)啟任何中斷
TIFR=0; //中斷標(biāo)志位
TCCR1A=0xA1; //開(kāi)啟PWM
TCCR1B=0x09;//系統(tǒng)時(shí)鐘
SREG=0x80; //開(kāi)啟全局中斷
OCR1A=128;//auc_SinParam[x];
}