pwm全频输出好用.txt

来自「数控直流电源和变频电源程序在c环境下编译」· 文本 代码 · 共 350 行 · 第 1/2 页

TXT
350
字号
253,247,241,234,228,222,217,211,206,200,195,191,186,182,178,174,171,168,165,163,161,159,158,157,
157,157,157,158,159,161,163,165,168,171,174,178,182,186,191,195,200,206,211,217,222, 228,234,241,247,253};

uchar code tl1_100[]={159,165,171,178,184,190,195,201,206,212,217,221,226,230,234,238,241,244,247,249,251,253,254,255,
255,255,255,254,253,251, 249,247,244,241,238,234,230,226,221,217,212,206,201,195,190,184,178,171,165,159,
159,165,171,178,184,190,195,201,206,212,217,221,226,230,234,238,241,244,247,249,251,253,254,255,
255,255,255,254,253,251, 249,247,244,241,238,234,230,226,221,217,212,206,201,195,190,184,178,171,165,159} ;




uchar code th0_20[]={256,256,256,256,255,255,255,255,255,255,255,255,255,255,254,254,254,254,254,254,254,254,254,254,
254,254,254,254,254,254,254,254,254,254,254,254,255,255,255,255,255,255,255,255,255,255,256,256,256,256,
256,256,256,256,255,255,255,255,255,255,255,255,255,255,254,254,254,254,254,254,254,254,254,254,
254,254,254,254,254,254,254,254,254,254,254,254,255,255,255,255,255,255,255,255,255,255,256,256,256,256} ;

uchar code th1_20[]={254,254,254,254,255,255,255,255,255,255,255,255,255,255,256,256,256,256,256,256,256,256,256,256,
256,256,256,256,256,256,256,256,256,256,256,256,255,255,255,255,255,255,255,255,255,255,254,254,254,254,
254,254,254,254,255,255,255,255,255,255,255,255,255,255,256,256,256,256,256,256,256,256,256,256,
256,256,256,256,256,256,256,256,256,256,256,256,255,255,255,255,255,255,255,255,255,255,254,254,254,254} ;

uchar code tl0_20[]={240,209,179,148,118,88,59,31,4,234,209,185,162,141,121,103,86,71,58,46,37,29,23,19,17,17,19,
23,29,37,46,58,71,86,103,121,141,162,185,209,234,4,31,59,88,118,148,179,209,240,
240,209,179,148,118,88,59,31,4,234,209,185,162,141,121,103,86,71,58,46,37,29,23,19,17,17,19,
23,29,37,46,58,71,86,103,121,141,162,185,209,234,4,31,59,88,118,148,179,209,240};

uchar code tl1_20[]={28,59,89,120,150,180,209,237,8,34,59,83,106,127,147,165,182,197,210,222,231,239,245,249,251,251,
249,245,239,231,222,210,197,182,165,147,127,106,83,59,34,8,237,209,180,150,120,89,59,28,
28,59,89,120,150,180,209,237,8,34,59,83,106,127,147,165,182,197,210,222,231,239,245,249,251,251,
249,245,239,231,222,210,197,182,165,147,127,106,83,59,34,8,237,209,180,150,120,89,59,28};

 uint i;
   uchar th0[]={0},tl0[]={0},th1[]={0},tl1[]={0};



   void  copy(uchar   *a,uchar  *b)
    {  uint j;
       for(j=0;j<100;j++)
       {
       *a=*b;a++;b++;}
       }



               
                
 void delays(uint xhm)
 { int i;
  for(i=0;i<xhm;i++)
     for(i=0;i<100;i++){}
}



uchar getkey()
 {uchar key;
   int i;
          delays(100);
   if(P1_0==1){i++;if(i>8){i=0;}}
       if(P1_1==1){i--;if(i<0){i=8;}}
            key=i;
           return(key);
            }
void init(void)
{
 TMOD=0X11;
 TH0=th0[i];
 TL0=tl0[i];
 TH1=th1[i];
 TL1=tl1[i];
 }

void  spwm(void)
 { 
 init();
 P1_0=1;
 EA=1;
 ET0=1;
 ET1=1;
 TR0=1;
 TR1=0;
  }

 void timer0(void) interrupt 1
 {
     P1_0=~P1_0;
     TR1=1;
     TR0=0;
     TH0=th0[i++];
     TL0=tl0[i++];
   }
   


void timer1(void) interrupt 3
{
 P1_0=~P1_0;
 TR0=1;
 TR1=0;
 TH1=th1[i++];
 TL1=tl1[i++];
  }
  
 void main()
 { 
   uchar keynum;
     delays(100);
    keynum=getkey();
      delays(100);
      delays(50000);
       switch(keynum)
     {
      case 0:
              copy(th0,th0_20);
              copy(th1,th1_20);
              copy(tl0,tl0_20);
              copy(tl1,tl1_20);

             break;    
     case 1:
              copy(th0,th0_30);
              copy(th1,th1_30);
              copy(tl1,tl1_30);
              copy(tl0,tl0_30);
                break;
      case 2:
              copy(th0,th0_40);
              copy(th1,th1_40);
              copy(tl1,tl1_40);
              copy(tl0,tl0_40);
                break;
     case 3:
                copy(th1,th1_50);
              copy(th0,th0_50);
              copy(tl1,tl1_50);
              copy(tl0,tl0_50);
                break; 
    case 4:
               copy(th0,th0_60);
              copy(th1,th1_60);
              copy(tl1,tl1_60);
              copy(tl0,tl0_60);  
                break;
      case 5:
              copy(th0,th0_70);
              copy(th1,th1_70);
              copy(tl1,tl1_70);
             copy(tl0,tl0_70);     
                break; 
      case 6:
              copy(th0_30,th0_80);
              copy(th1_30,th1_80);  
              copy(tl1_30,tl1_80);
              copy(tl0_30,tl0_80);
                break;
      case 7:
              copy(th0,th0_90);
              copy(th1,th1_90);
              copy(tl1,tl1_90);
              copy(tl0,tl0_90);
                break;
      case 8:       
               copy(th0_30,th0_100);
              copy(th1_30,th1_100);
              copy(tl1_30,tl1_100);
              copy(tl0_30,tl0_100);
                   break;          
      default :
              
                break;     }

   spwm();

 }  

⌨️ 快捷键说明

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