#include "CH552.H"
#include "Debug.H"
#include "Timer.H"
#include "stdio.h"
#include "GPIO.H"
#pragma NOAREGS
UINT8 FLAG;
UINT16 Cap[8] = {0};
typedef unsigned int uint16_t;
sbit LED1 = P3^4;
sbit led2 = P1^3;
sbit key = P1^4;
unsigned int condition=0;//这里高电平占一份
unsigned int cnt; //整个周期
void button();
void main( )
{
CfgFsys( ); //CH554时钟选择配置
mDelaymS(5); //修改主频,建议稍加延时等待主频稳定
Port3Cfg(1,4);
Port1Cfg(1,3);
Port1Cfg(3,4);
mTimer0Clk12DivFsys(); //T0定时器时钟设置
mTimer_x_ModInit(0,2); //T0 定时器模式设置
mTimer_x_SetData(0,0x5555); //T0定时器赋值
mTimer0RunCTL(1); //T0定时器启动
ET0 = 1; //T0定时器中断开启
EA = 1;
while(1);
{
if(cnt>=100)
{
LED1=0;
}
if(cnt
{
LED1=1;
}
else
{
LED1=0;
}
button();
}
}
void Time0Interrupt(void) interrupt INT_NO_TMR0 using 1
{
mTimer_x_SetData(0,0x5555); //T0定时器赋值
cnt++;
}
void button()
{
if(key!=1)
{
mDelaymS(5);
if(key!=1)
{
condition=condition+30; //调制脉宽
led2=!led2;//led灯反转
if(condition>=90)//如果脉宽等于总周期了等于0
{
condition=90;
}
while(!key); //等待按键松手
}
}
}