具体问题是这样的。一开始给STC12C5A60S2 P3.0口一个高电平。然后STC12C5A60S2 P1.3口自动输出一个占空比40%的PWM波。再然后给P1.3口一个低电平,此时要求STC12C5A60S2 的P1.3口自动输出1s的60%占空比的PWM波,1s时间到了之后拉低P1.3口电平,我尝试写了下程序,总是不能成功实现。求哪位大神帮忙看看啊
#include <reg52.h>
#include "delay.h"
#define FOSC 18432000L
//Declare SFR associated with the PCA 声明与PCA相关联的SFR
sfr CCON = 0xD8; //PCA control register PCA控制寄存器
sbit CCF0 = CCON^0; //PCA module-0 interrupt flag PCA模块0中断标志
sbit CCF1 = CCON^1; //PCA module-1 interrupt flag PCA模块1中断标志
sbit CR = CCON^6; //PCA
timer run control bit PCA定时器运行控制位
sbit CF = CCON^7; //PCA timer overflow flag PCA定时器溢出标志
sfr CMOD = 0xD9; //PCA mode register PCA模式寄存器
sfr CL = 0xE9; //PCA base timer LOW PCA基定时器低
sfr CH = 0xF9; //PCA base timer HIGH PCA基定时器高
sfr CCAPM0 = 0xDA; //PCA module-0 mode register PCA模块0模式寄存器
sfr CCAP0L = 0xEA; //PCA module-0 capture register LOW PCA模块0捕捉寄存器低
sfr CCAP0H = 0xFA; //PCA module-0 capture register HIGH PCA模块0捕捉寄存器高
sfr CCAPM1 = 0xDB; //PCA module-1 mode register PCA模块1模式寄存器
sfr CCAP1L = 0xEB; //PCA module-1 capture register LOW PCA模块1捕捉寄存器低
sfr CCAP1H = 0xFB; //PCA module-1 capture register HIGH PCA模块1捕捉寄存器高
sfr PCAPWM0 = 0xf2;
sfr PCAPWM1 = 0xf3;
sbit P30 = P3^0;
void main()
{
CCON=0;
CL=0;
CH=0;
CMOD=0x02;
CCAP0H=CCAP0L=0x60;
CCAPM0=0X42;
CR=1;
loop:if (P30==1)
{
goto loop;
}
else
{
CCON=0;
CL=0;
CH=0;
CMOD=0x02;
CCAP0H=CCAP0L=0xA0;
CCAPM0=0X42;
CCAP1H=CCAP1L=0xff;
PCAPWM1=0x03;
CCAPM1=0X42;
CR=1;
}
delay(1000);
CCON=0;
CL=0;
CH=0;
CMOD=0x02;
CCAP0H=CCAP0L=0x80;
CCAPM0=0X42;
CR=1;
}
CCAPM0=0x00;//关
P3_0=0;//关IO
一周热门 更多>