日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]//ICC-AVR application builder : 2006-7-7 11:30:51 // Target : M8 // Crystal: 8.0000Mhz 20k for G4PC50U#include #include #define INT0 6 //=====================周期為20ms,spwm頻率為20k==========

//ICC-AVR application builder : 2006-7-7 11:30:51
// Target : M8
// Crystal: 8.0000Mhz 20k for G4PC50U

#include
#include
#define INT0 6
//=====================周期為20ms,spwm頻率為20k===========================//
short list[]={1,4,7,10,13,16,19,22,25,28,31,34,37,39,42,45,48,51,54,57,60,62,
65,68,71,74,76,79,82,84,87,90,92,95,97,100,103,105,108,110,112,115,117,119,
122,124,126,128,131,133,135,137,139,141,143,145,147,149,151,152,154,156,157,
159,161,162,164,165,167,168,169,171,172,173,174,176,177,178,179,180,181,182,
182,183,184,185,185,186,186,187,187,188,188,189,189,189,189,189,189,189,189,
189,189,189,189,189,189,188,188,187,187,186,186,185,185,184,183,182,182,181,
180,179,178,177,176,174,173,172,171,169,168,167,165,164,162,161,159,157,156,
154,152,151,149,147,145,143,141,139,137,135,133,131,128,126,124,122,119,117,
115,112,110,108,105,103,100,97,95,92,90,87,84,82,79,76,74,71,68,65,62,60,57,
54,51,48,45,42,39,37,34,31,28,25,22,19,16,13,10,7,4,1};
//=====================周期為20ms,spwm頻率為20k===========================//
int count,zf=0;
void port_init(void)
{
PORTB = 0x00;
DDRB = 0xFF;//06;b口輸出
PORTC = 0x00;
DDRC = 0xFF;//c口輸出
PORTD = 0x00;
DDRD = 0x00;//d口輸入

}

//TIMER1 initialize - prescale:1
// WGM13:0=10) PWM phz correct, TOP= ICR1
// desired value: 10KHz
// actual value: 10.000KHz (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xFF; //setup
TCNT1L = 0x38;
OCR1AH = 0x00;
OCR1AL = 0xC8;
OCR1BH = 0x00;
OCR1BL = 0xC8;
ICR1H = 0x00;
ICR1L = 200;// 載波周期為50us
TCCR1A = 0xA2; //10100010 top時(shí)更新OCR1A OCR1B,向上計(jì)數(shù)比較匹配清零,反之置位
TCCR1B = 0x11; //start Timer 00010001 clk無分頻,相位修正PWM
TIMSK |= 0x20; //timer interrupt sources使能捕捉中斷
}

#pragma interrupt_handler timer1_capt_isr:6
void timer1_capt_isr(void)
{
OCR1A=500;
OCR1B=500;
//PORTB ^=0x10;
// 2 1 .spwm
//
// 4 3180
//
//

if(zf)
{
if(count<200)
{
if(count==1) //此時(shí)2#管子才關(guān)斷
{
//PORTB &= ~BIT(3); //3#管子已經(jīng)關(guān)斷
PORTB |= BIT(4); //開通4#管子
}
OCR1A=list[count++]; //開通1#管子
}
else if((count>=200)&&(count<400))
{
if(count==200)
{
PORTB &= ~BIT(4); //關(guān)斷4#管子
}
if(count==201) //此時(shí)1#管子才關(guān)斷
{
PORTB |= BIT(3); //開通3#管子
}
OCR1B=list[count++-200]; //開通2#管子
}
else
{
count=0; //2#管子已經(jīng)關(guān)斷
PORTB &= ~BIT(3); //關(guān)斷3#管子
//PORTB |= BIT(4); //開通4#管子
OCR1A=list[count++]; //開通1#管子
}
}
else;

}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer1_init();

SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//
void main(void)
{
init_devices();
//insert your functional code here...
zf = 1;
OCR1A=500;
OCR1B=500;
PORTB = 0;
while(1);
}

生成50hz正弦波

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉