1._c

来自「avr atmega48的pwm输出」· _C 代码 · 共 58 行

_C
58
字号
#include <iom48v.h>
#include <macros.h>

void init_timer1()
{//OCR1AH=0x00;//设定pwm的值约为0.8s
 //OCR1AL=0x90;
 OCR1A=23;
 TCCR1B = 0x00; //stop
 //TCCR1A=0x82;
 TCCR1A=0x82;
 TCCR1B=0x1A;
 /*8分频,WGM14  快速PWM模式, OC1A正向PWM输出,TOP=ICR1*/
 ICR1=28;//设定TOP值,设置频率30赫兹
 
}
#pragma interrupt_handler timer1_capt_isr:11
void timer1_capt_isr(void)
{
 //timer 1 input capture event, read (int)value in ICR1 using;
 //TCNT1=0;
 DDRB=0x02;
}
#pragma interrupt_handler timer1_compa_isr:12
void timer1_compa_isr(void)
{
 //compare occured TCNT1=OCR1A
  DDRB=0x02;
}


void main()
{
 CLI();
 //init_port();
 PORTB = 0x02;
 DDRB  = 0x02;
 PORTC = 0x00; 
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0x00;
 init_timer1();
 MCUCR = 0x00;
 EICRA = 0x00; //extended ext ints
 EIMSK = 0x00;
 
 TIMSK0 = 0x00; //timer 0 interrupt sources
 TIMSK1 = 0x22; //timer 1 interrupt sources
 TIMSK2 = 0x00; //timer 2 interrupt sources
 
 PCMSK0 = 0x00; //pin change mask 0 
 PCMSK1 = 0x00; //pin change mask 1 
 PCMSK2 = 0x00; //pin change mask 2
 PCICR = 0x00; //pin change enable 
 PRR = 0x00; //power controller
 SEI();
 while(1);
 }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?