标题: 急救 [打印本页] 作者: sgy52401314 时间: 2014-7-29 16:37 标题: 急救 有哪位大虾帮我这个新手编一下面的程序,小弟感觉不尽。
要求:1用msp430g2553.h实现。
2实现如下功能,每十秒钟灯光闪烁一次,每2秒灯光亮度变化一次,按键按一次延时时间增加5秒灯光亮度变化相反。 作者: mqwu 时间: 2014-9-16 15:46
我用我的MSP430F5438A写了个程序, 运行了下完全OK, 用示波器可以看到占空比的连续变化
//this is source code using MSP430F5438A, the Aclock is using XT1=32.768K, the will help to get second counts
__bis_SR_register(GIE); // Enter LPM0, enable interrupts
while(1)
{
TA0CCR4=temp;
Display(num1,num2,num3,num4);// if LPM0 is enable, the routine will not be preformed;
if (!(P6IN&0x01))
{
__delay_cycles(10);
if (!(P6IN&0x01))
{
temp+=5;
if (temp==512)
temp=128;
while(!(P6IN&0x01));
}
}
}
}
// Timer1 A0 interrupt service routine
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
count++;
if(count==2) //the light intensity increase 1every other 2sec
{
count=0;
temp++;
num1=temp/1000; //°ÑÕa¸ö±äá¿ÏÔê¾3öà′
num2=temp%1000/100;
num3=temp%100/10;
num4=temp%10;
if (temp==512)
temp=0;
}
count1++;
if (count1==10)
{
count1=0;
P7OUT^=0x01; //Output LED flahes every other 10 sec;
}
}
作者: mqwu 时间: 2014-9-16 15:48
下面是按照你的要求改写的程序, 我看了USER GUIDE 和 Datasheet 应该没有问题
//this is source code using MSP430G2553, the Aclock is using XT=32.768K, the will help to get second counts ------- MSP430G2553, 28-Pin Devices, TSSOP
#define uchar unsigned char
#define uint unsigned int
uint count,count1,temp=0;
void Init_Port(void)
{
P1OUT = 0x01 ; // O/P to high level and connect switch to ground
P1DIR &=~0x01 ;// set input DIR;
P1REN |= 0x01; //Enable P1.0 pull-up
P3DIR |= 0x20; // set the O/P as well as check waveform P3.5using scope
P3SEL |= 0x20; // P3.5 options select and connect LED to ground;
}
if (!(P1IN&0x01))
{
__delay_cycles(10);
if (!(P1IN&0x01))
{
temp+=5; //push the switch everytime, the intensity value add 5;
if (temp==512)
temp=0;
while(!(P1IN&0x01));
}
}
}
}
// Timer1 A0 interrupt service routine
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
count++;
if(count==2) //the light intensity increase 1every other 2sec
{
count=0;
temp++;
if (temp==512)
temp=0;
}
count1++;
if (count1==10)
{
count1=0;
P3OUT^=0x20; //Output LED flahes every other 10 sec;
}
}