单片机
返回首页

Atmega16l单相逆变器SPWM原理图PCB及源程序

2019-10-21 来源:51hei

Altium Designer画的原理图和PCB图


Atmega16l单片机源码如下:

#include

#include

#define uint unsigned int

#define uchar unsigned char

uchar zd=0,c=0;

uint iv=0,ii=0,ov=0,oi=0,sj=0,b=0;

uchar table[3]={8,8,8};

#pragma data:code

flash uint table1[]={0X3f,0X06,0X5b,0X4f,0X66,0X6d,0X7d,0X07,0X7f,0X6f,0X77,0X7c,0X39,0X5e,0X79,0X71,0X00,

0X40,0XFF};

flash uint table2[]={

0,5,10,16,21,27,32,38,43,48,54,59,64,69,75,80,85,90,95,100,

105,110,115,120,124,129,134,138,143,147,152,156,160,164,168,172,176,180,184,187,

191,194,198,201,204,207,210,213,216,219,221,224,226,228,230,233,234,236,238,240,

241,242,244,245,246,247,247,248,249,249,249,249,250,249,249,249,249,248,247,247,

246,245,244,242,241,240,238,236,234,233,230,228,226,224,221,219,216,213,210,207,

204,201,198,194,191,187,184,180,176,172,168,164,160,156,152,147,143,138,134,129,

125,120,115,110,105,100,95,90,85,80,75,69,64,59,54,48,43,38,32,27,

21,16,10,5,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0};


flash uint table3[]={

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,

0,5,10,16,21,27,32,38,43,48,54,59,64,69,75,80,85,90,95,100,

105,110,115,120,124,129,134,138,143,147,152,156,160,164,168,172,176,180,184,187,

191,194,198,201,204,207,210,213,216,219,221,224,226,228,230,233,234,236,238,240,

241,242,244,245,246,247,247,248,249,249,249,249,250,249,249,249,249,248,247,247,

246,245,244,242,241,240,238,236,234,233,230,228,226,224,221,219,216,213,210,207,

204,201,198,194,191,187,184,180,176,172,168,164,160,156,152,147,143,138,134,129,

125,120,115,110,105,100,95,90,85,80,75,69,64,59,54,48,43,38,32,27,

21,16,10,5};


#pragma interrupt_handler timer2_capt_isr:5

#pragma interrupt_handler adc_sj:15

void timer2_capt_isr()

{

   TCNT2=5;

   c++;

   if(c>=2)

   {

     c=0;

         OCR1AH=0;

         OCR1AL=table2[b];

         OCR1BH=0;

     OCR1BL=table3[b];

         b++;

         if(b>=288){b=0;zd++;}

   }

}

void timer1_init()

{

    TCCR2=0X01;

        TCNT2=5;

        OCR1AH=0;

        OCR1AL=0;

        OCR1BH=0;

        OCR1BL=0;

        ICR1=250;

        TCCR1A=0XA0;

        TCCR1B=0X11;

}

void init_devices()

{

        DDRD|=BIT(4);

        DDRD|=BIT(5);

        timer1_init();

        MCUCR=0X00;

        GICR=0X00;

        TIMSK=0X40;

        SREG|=BIT(7);

}

void led()//正常指示灯

{

    PORTB|=BIT(3);

        PORTB&=~BIT(4);

}

void led1()//故障指示灯

{

   PORTB&=~BIT(3);

   PORTB|=BIT(4);

}

void led2()//报警指示灯

{

   PORTB|=BIT(4);

   PORTB|=BIT(3);

}

void ad_init(uchar a)//AD转换

{

  // uint sj;

   SFIOR=0;//设置ADC为连续工作模式

   ADMUX=a;//设置那一路ADC转换

   ADCSR=0X80;//ADC转换使能

   ADCSR|=BIT(ADSC);//启动ADC

   ADCSR|=BIT(ADIE);

   SREG|=BIT(7);

//  while(!(ADCSR&(BIT(ADIF))));//等待ADC转换完成

//  sj=ADCL;

//  sj=sj+256*ADCH;

  // ADCSR|=BIT(ADIF);

  // ADCSR=0X00;//关闭ADC

  // return sj;

}


void  show(uchar bai,uchar shi,uchar ge )

{   

         PORTC=table1[bai];

         PORTA|=BIT(7); 

         PORTA&=~BIT(7);

         PORTC=table1[shi];

         PORTA|=BIT(6);

         PORTA&=~BIT(6);

         PORTC=table1[ge];

         PORTA|=BIT(5);

         PORTA&=~BIT(5);

}

void adc_sj()

{

   sj=ADCL;

   sj=sj+256*ADCH;

   ADCSR|=BIT(ADIF);

   ADCSR=0X00;//关闭ADC

}

void  delay(uint ms)

{

           uint  x,y;

          for(x=0;x          {

             for(y=0;y<1141;y++);

          }

}

void main()

{

   uchar f=0;

   uint ci=0;

        DDRC=0XFF;

        DDRA|=BIT(5);

        DDRA|=BIT(6);

        DDRA|=BIT(7);

        PORTC=0X00;

    PORTA&=~BIT(7);

        PORTA&=~BIT(6);

        PORTA&=~BIT(5);

        DDRA&=~BIT(1);

        PORTA&=~BIT(1);

        DDRA&=~BIT(4);

        PORTA&=~BIT(4);

        

    DDRB|=BIT(3);

    DDRB|=BIT(4);

    PORTB&=~BIT(3);

    PORTB&=~BIT(4);

    DDRB|=BIT(6);

    PORTB&=~BIT(6);

    init_devices();

   while(1)

   {

    if(zd>=80)

           {

            zd=0;

                switch(f)

                {

                  case 0: table[0]=1;table[1]=17;table[2]=17;f++;ad_init(0x44);

                  break;

                  case 1:sj=sj/51;iv=sj;table[0]=iv/100;table[1]=iv%100/10;table[2]=iv%10;f++;sj=0;led();

                  break;

                  case 2: table[0]=2;table[1]=17;table[2]=17;f++;

                  break;

……………………



进入单片机查看更多内容>>
相关视频
  • RISC-V嵌入式系统开发

  • SOC系统级芯片设计实验

  • 云龙51单片机实训视频教程(王云,字幕版)

  • 2022 Digi-Key KOL 系列: 你见过1GHz主频的单片机吗?Teensy 4.1开发板介绍

  • TI 新一代 C2000™ 微控制器:全方位助力伺服及马达驱动应用

  • MSP430电容触摸技术 - 防水Demo演示

最新器件
精选电路图
  • CCD图像传感器在微光电视系统中的应用

  • 如何利用ESP8266制作一个简单的四轴飞行器

  • 非常简单的150W功放电路图

  • 基于IC555的可变PWM振荡器电路

  • 优化电路板布局的简单方法

  • 分享一个电网倾角计电路

    相关电子头条文章