#include "N76E003.h"
#include "Common.h"
#include "Delay.h"
#include "SFR_Macro.h"
#include "Function_define.h"
#include "stdio.h"
#define uchar unsigned char
#define uint unsigned int
uint jici=0,pinlv=0,count=0,jishu=0;
void delay(uint xms);
void dis();
void Timer0_ISR(void)interrupt 1
{
jici++;
TH0=1536/256;
TL0=1536%256;
if(jici==25)
{
jishu=jici;
TR0=TR1=0;
count=pinlv;
TL1=TH1=0;
count=0;
jici=0;
TR0=TR1=1;
}
}
void dis(uint num)
{
if(jishu==25)
{
if (num<100)
{
clr_LOAD;
set_SFRPAGE;
PWM5L+=10;
clr_SFRPAGE;
set_LOAD;
jishu=0;
}
}
}
void main()
{
Set_All_GPIO_Quasi_Mode;
PWM5_P03_OUTPUT_ENABLE;
PWM4_P01_OUTPUT_ENABLE;
PWM3_P00_OUTPUT_ENABLE;
set_T0M;
clr_PWMTYP;
clr_PWMMOD0;
clr_PWMMOD1;
PWM_CLOCK_DIV_8;
PWMPH = 0x07;
PWMPL = 0xCF;
set_SFRPAGE;
PWM5H = 0x03;
PWM5L = 0xe8;
PWM4H = 0x03;
PWM4L = 0xe8;
PWM3H = 0x00;
PWM3L = 0x00;
clr_SFRPAGE;
set_LOAD;
set_PWMRUN;
P11_Input_Mode;
clr_PIPS1;
set_PIPS0;
Enable_BIT1_FallEdge_Trig;
TIMER0_MODE1_ENABLE;
TH0=1536/256;
TL0=1536%256;
set_EPI;
set_ET0;
set_EA;
set_TR0;
while(1)
{
dis(pinlv);
}
}
void PinTnterrupt(void) interrupt 7
{
if(PIF==0x02)
{
PIF=0;
count++;
}
}
用管脚中断来检测外部脉冲,用定时器0来进行1S的定时。
通过检测外部频率来调整输出的PWM ,在外部脉冲频率小于100的时候PWM的占空比就会变大。
能帮我检查检查吗
|