STC12CXX的PWM模块 我程序设脉宽为0的时候 还有高点平脉冲输出????附示波器显示波形图
http://cache.amobbs.com/bbs_upload782111/files_40/ourdev_645494P8BI92.jpg(原文件名:图像1156.jpg)
#include <STC12C5410AD.H>
#define uchar unsigned char
#define uint unsigned int
sbit D1=P2^6;
unsigned char i;
/* volatile unsigned char code sin=
{
0x7F,0x87,0x8F,0x97,0x9F,0xA6,0xAE,0xB5,0xBC,0xC3,0xCA,0xD0,0xD6,0xDC,0xE1,0xE6
,0xEB,0xEF,0xF2,0xF6,0xF8,0xFA,0xFC,0xFD,0xFE,0xFE,0xFE,0xFD,0xFC,0xFA,0xF8,0xF6
,0xF2,0xEF,0xEB,0xE6,0xE1,0xDC,0xD6,0xD0,0xCA,0xC3,0xBC,0xB5,0xAE,0xA6,0x9F,0x97
,0x8F,0x87,0x7F,0x77,0x6F,0x67,0x5F,0x58,0x50,0x49,0x42,0x3B,0x34,0x2E,0x28,0x22
,0x1D,0x18,0x13,0x0F,0x0C,0x08,0x06,0x04,0x02,0x01,0x00,0x00,0x00,0x01,0x02,0x04
,0x06,0x08,0x0C,0x0F,0x13,0x18,0x1D,0x22,0x28,0x2E,0x34,0x3B,0x42,0x49,0x50,0x58
,0x5F,0x67,0x6F,0x77
}; */
void PCA(void)
{
CMOD=0x02;
CL=0x00;
CH=0x00;
CCAP0L=0xFF;
CCAP0H=0xFF;
CCAPM0=0x42;
CR=1;
}
/*voidt0init()
{
AUXR=0X00;
TMOD=0x01; //选择定数计数器0的工作方式为16位定时器
TH0=0XFF; //赋初值,定时50ms
TL0=0XFe;
EA=1; //中断控制允许
ET0=1;
TR0=1;
}
void time0() interrupt 1 //定时器0中断函数
{
TH0=0XFF; //赋初值,定时50ms
TL0=0XFe;
D1=!D1;
for(i=0;i<100;i++)
{
CCAP0L=sin;
CCAP0H=sin;
}
} */
void main()
{
// t0init();
PCA();
while(1);
} 有些硬件本身就不支持吧,查查IC资料 它的PWM实际是9位,老妖说过了。 9位是怎么测试出来的啊? 晕
PWM的极性问题
匹配的时候输出高电平还是低电平可以通过极性来设置的。 看下 强烈关注 输出0脉宽的时候把PWM关了,直接让它没有输出。
页:
[1]