標題: 急救 [打印本頁] 作者: 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;
}
}