|
本帖最后由 paulhyde 于 2014-9-15 04:04 编辑
#include "msp430x14x.h"
#define keyin (P1IN & 0x0f)
#define uchar unsigned char
#define uint unsigned int
void delay(void)
{
uint tmp;
for(tmp = 8000;tmp > 0;tmp--);
}
void main()
{
uint temp=1;
uint fre=1;
WDTCTL = WDTPW + WDTHOLD;
TACTL=TASSEL0+TACLR;
P1DIR = BIT7; //P1.7为输出,键盘
P1OUT = 0;
while(1)
{
if(keyin!=0x0f)
{
delay();
if(keyin!=0x0f)
{
temp=keyin;
while(keyin!=0x0f);
if(temp==0x0e)
{
fre++;
CCR0 = 100; // PWM 周期
CCTL2 = OUTMOD_7; // PWM toggle/reset
CCR2 = fre; // ccr1 Pwm cycle
P2DIR |= 0x01; // p1.2 模式设置
P2SEL |= 0x01; // p2.1 option select
TACTL |= MC0; // 设置递增模式
if(fre>100)
fre=0;
}
if(temp==0x0d)
{
fre--;
CCR0 = 100; // PWM 周期
CCTL2 = OUTMOD_7; // PWM toggle/reset
CCR2 = fre; // ccr1 Pwm cycle
P2DIR |= 0x01; // p2.1 模式设置
P2SEL |= 0x01; // p2.1 option select
TACTL |= MC0; // 设置递增模式
if(fre<1)
fre=1;
}
}
}
}
}
这是我写的pwm程序,是用按键控制的,但是产生的波形却会有负电压,我很费解,大家讨论起来吧 看看这个程序有没有问题
|
|