標題: 求51的觸摸燈作品和電路圖 [打印本頁]

作者: 13790987845    時間: 2017-12-12 09:37
標題: 求51的觸摸燈作品和電路圖
求51的觸摸燈作品和電路圖
作者: 都市郎    時間: 2018-3-8 15:09
網(wǎng)上看的程序,編譯不通過。你看下不知那里有問題!
/****************************************************************
                          STC15L104W觸摸燈   
***************************************************************/
#include <STC15F2K60S2.H>
#include "intrins.h"
typedef unsigned char  uchar;
typedef unsigned intuint;

//#define P3Set_IO(x)  P3M1&=~(1<<x);P3M0&=~(1<<x)
//#define P3Set_PP(x)  P3M1&=~(1<<x);P3M0|=1<<x  
//#define P3Set_IN(x)  P3M1|=1<<x;P3M0&=~(1<<x)
//#define P3Set_OD(x)  P3M1|=1<<x;P3M0|=1<<x

sbit KEY =P3^2;
sbit PWM_Out =P3^5;
//#define TRUN_1T
//#define SYSTEM_CLOOK   5.5296f   
#define Up   1
#define Down 0
sbit KEY_Flag = Up;
#define ON   1
#define OFF  0
#define bLightSwitch TR0
ucharucHighDuty = 150;
#define Sycle 200

void Delay(ucharxms)
{
   unsigned char i;
   do{
   while(i--);
   }while(xms--);
}
void T0_ISR() interrupt 1
{
   staticuchar Count;
   Count++;
   if(Count>ucHighDuty&&PWM_Out==1)
   PWM_Out=~PWM_Out;
   else if(Count>Sycle)
     {
            Count=0;
                PWM_Out=~PWM_Out;
         }
}
void INT0_ISR() interrupt 0
{
   bKEY_Flag = Down;
}
void main(void)
{
   bitbFlag,jieneng = 1;
   CLK_DIV|=0xC1;//P3.4輸出RC時鐘/4   系統(tǒng)時鐘=RC二分頻,二分頻可以省0.5mA.
   // P3M0=0x00;
   P3M1|=0x0F;        //P3.0-4 設(shè)置為高阻  
   // T0=lnit();
   AUXR|=0x80;
   TH0=0xFF;
   TL0=0x9C;
   IE|=0x83; //開啟EA T0 INT0
   //IT0=1;  // 1 下降沿中斷   0 邊沿中斷  
   while(1)
   {
             if(bKEY_Flag==Down)
          {
             Delay(255);
                 if(KEY==Up)
                 {
                    bLightSwitch = !bLightSwitch;
                        jieneng = !jieneng;
                        if(bLightSwitch == OFF)
                        {
                           PWM_Out = 1;
                           TH0 = 0xFF;
                           TL0 = 0x9C;
                        }
                  while(KEY==Down);
                 }
          else if(bLightSwitch == ON)
          {
             do{
                           if(bFlag == 1&&ucHighDuty<Sycle)
                          ucHighDuty+=1;
                          else if(ucHighDuty>0)
                          ucHighDuty-=1;
                          Delay(10);
                    }
           while(KEY==Down);
           bFlag=!bFlag;
          }
          bKEY_Flag=Up;
          }
        if(jieneng==1)
        {
           PCON|=0x01;
           Delay(255);
           while(KEY==Down)
           {
                     TH0=0xF4;
                  TL0=0x48;
           }
        }
   }
}





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