⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fisipwm.c~

📁 AVR单片机的快速PWM使用范例 开发环境CAVR
💻 C~
字号:
/*****************************************************
Project             : fisiPWM_led 
Date                : 2005-11-7
Author              : Linbrid                
Company             : TianJin Univeisity                
Chip type           : ATmega16L
Program type        : Application
Clock frequency     : 4.000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/

#include <mega16.h>
#include <math.h>

float pi = 3.14159265;

char sin_128(char x)                                //128个正弦波采样点计算函数
{
        float a,b;
        float sin_ocr;
        b=(2*pi*(x/127));
        a=sin(b);
        sin_ocr=(128+(char)127*a);
        return(sin_ocr);
}

char x_SW=2,x_LUT=0;        


interrupt [TIM0_OVF] void timer0_ovf_isr(void)      
{
    x_LUT+=x_SW;                                    //新样点指针
    if(x_LUT>=127)                                  //样点指针调整
    {
        x_LUT-=128;
    }
    OCR0=sin_128(x_LUT);                           //取新样点值到比较匹配寄存器
    //OCR0+=1;

}


void main(void)
{

DDRB=0x08;
PORTB=0x08;

TCCR0=0x69;
TCNT0=0x00;
OCR0=0x80;

TIMSK=0x01;

#asm("sei")

while (1)
      {
      

      };
}

⌨️ 快捷键说明

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