?? pwm._c
字號:
#include <iom16v.h>
#include <macros.h>
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0xff;
DDRD = 0xff;
}
//TIMER1 initialize - prescale:64
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 1000Hz
// actual value: 1000.000Hz (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xFF; //setup
TCNT1L = 0x83;
OCR1AH = 0x00;
OCR1AL = 0x65; //占空比
OCR1BH = 0x00;
OCR1BL = 0x10; //占空比
ICR1H = 0x00;
ICR1L = 0x7D;
TCCR1A = 0xA2;
TCCR1B = 0x13; //start Timer
}
//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();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
main()
{
init_devices();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -