欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 89c52制作舵機 搖頭 快速回位 [打印本頁]

作者: xrfxrf008    時間: 2019-4-21 21:29
標題: 89c52制作舵機 搖頭 快速回位
廢話不多說直接代碼吧
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit pwm=P0^0;
sbit keyup=P3^2;
sbit keydn=P3^3;
sbit keysdk=P3^4;
sbit keysdm=P3^5;
uchar qi=10,zhi=10;
uchar count0,flag,jd;
int count1,sd=20;
void delay(uint z)
{
  uchar x,y;
  for(x=z;x>0;x--)
      for(y=110;y>0;y--);
}
void tm_init()
{
  TMOD=0x11;//¶¨Ê±Æ÷1¡¢2 ¹¤×÷ÔÚģʽ1 ¼´65536
  TH1=(65536-50000)/256;//¶¨Òå500ms
  TL1=(65536-50000)%256;
  TH0=0xff;//¶¨Òå0.1ms
  TL0=0x9c;
  IE=0x8a;
  TR0=1;
  TR1=1;  
}
void tm0_int() interrupt 1 //t0¶¨Òå
{
  uchar temp;
  TH0=0xff;//¶¨Òå0.1ms
  TL0=0x9c;  
  if(flag==1)
    temp=qi;
  else
    temp=zhi;
  if(count0<temp)
     pwm=1;
  else
     pwm=0;
  count0=count0+1;
  count0=count0%200;

}
void tm1_int() interrupt 3
{
   TH1=(65536-50000)/256;//¶¨Òå500ms
   TL1=(65536-50000)%256;
   count1++;
   if(count1==4)
      flag=0;     
   if(count1==sd)//30Ãë   600
   {
      flag=1;
      count1=0;
   }
      
}
void test()
{
   if(keyup==0)
   {
     delay(20);
     if(keyup==0)
     {
     
         qi++;
         count0=0;
         while(!keyup);
     }
   }
     if(keydn==0)
   {
     delay(20);
     if(keydn==0)
     {
     
         qi--;
         count0=0;
         while(!keydn);
     }
   }
    if(keysdk==0)
   {
     delay(20);
     if(keysdk==0)
     {
     
         sd=sd+20;
         count1=0;
         while(!keysdk);
     }
   }
   if(keysdm==0)
   {
     delay(20);
     if(keysdm==0)
     {
     
         sd=sd-20;
         count1=0;
         while(!keysdm);
     }
   }
}
  
void main()
{
  uint m=0;
  count0=0;count1=0;
  jd=15;
  flag=1;//falg=1ʱcount0=10 flag=0ʱcount0=10
  tm_init();
  while(1)
  {
   test();
  }
}




作者: admin    時間: 2019-4-22 04:36
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1