This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Uses MSP4302274, project required to turn on both green and red LEDs, blinks for 5 seconds before turning off. I couldn't find where the problem causes the problem not to run but made to stop responding.
#include "msp430x22x4.h"
void main (void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= 0x01;
P1DIR |= 0x02;
P1OUT = 0x04;
P1REN |= 0x04;
TACCTL0 = CCIE;
TACCR0 = 65535;
TACTL = TASSEL_2 + MC_3 + ID_3;
__bis_SR_register(LPM0_bits + GIE);
while (1)
{
volatile unsigned int i;
i = 60000;
do i--;
while (i !=0);
}
#pragma vector=PORT1_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= 0x04;
}
}
}
Error[Pe065]: expected a ";"
Warning[Pe012]: parsing restarts here after previous syntax error
Error[Pe169]: expected a declaration
Error while running C/C++ Compiler
I was wonder does it cost by this part? where it should blink 5 secs, but when i calculate the answer is 0.8738.
TACCR0 = 65535;
TACTL = TASSEL_2 + MC_3 + ID_3;
You enabled TimerA CC0 interrupt, where is the ISR for TimerA CC0 interrupt?
You did not enable P1 interrupt, why do you have an ISR for P1 interrupt?
old_cow_yellow said:You enabled TimerA CC0 interrupt, where is the ISR for TimerA CC0 interrupt?
You did not enable P1 interrupt, why do you have an ISR for P1 interrupt?
Good catch.
And it seems that the Timer ISR is actually inside the main function! This will not work!
Also, it will never reach the while(1).... because you never exit from the LPM0!
BR,
Mo.
#include "msp430x22x4.h"
int rg = 0;
void main (void)
{
WDTCTL = WDTPW + WDTHOLD;
ADC10CTL0 = SREF_0 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
P1DIR |= 0x01;
P1DIR |= 0x02;
P1OUT = 0x04;
P1REN = 0x04;
ADC10AE0 |= 0x01;
P1IE = 0x04;
P1IES = 0x04;
{
if (rg == 0)
{P1OUT |= 0x01; P1OUT |= 0x02;}
volatile unsigned int i;
i = 60000;
do i--;
while (i !=0);
}
for(;;)
{
ADC10CTL0 |= ENC + ADC10SC;
__bis_SR_register(CPUOFF + GIE);
if (ADC10MEM > 0x300)
{
P1OUT |= 0x01;
P1OUT &= 0xFD;
P1OUT &= ~0x04;
}
if (ADC10MEM < 0x160)
{
P1OUT |= 0x01;
P1OUT |= 0x404;
}
}
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF);
}
#pragma vector=TIMERA0_VECTOR
__interrupt void TA0_ISR(void)
{
TACTL = 0;
LPM0_EXIT;
}
it still cannot blink for 5 seconds before they are turned off, what are the coding should i change any ideas?
This enables interrupts by P1.2. There is no ISR for P1 interrupts. So if an interrupt comes (and it comes, since you change the ES bit without clearing the IFG bit afterwards, which will almost certainly cause an interrupt as soon as GIE is set. First set PxES, then clear PxIFG, then set PxIE.Mark Wong2 said:P1IE = 0x04;
You waiting loop may or may not work. Declyrign a local variable as volatile doesn't prevent optimization. The compiler knows that nobody has the reference to this local variable and therefore no side-effect can happen. it will likely ignore the volatile flag and optimize your loop away as soon as compiler optimizations are enabled. And even if not, you don't know what code the compiler generates and therefore how long your loop will take to execute.
Use __deay_cycles instead.
The tiemr ISR is useless, since you never configure the timer or activate a tiemr interrupt.
The waiting loop is outside the endless main loop. So you configure the system, wait (or not, if optimized away) and then run the for loop as fast as the ADC can convert.
The brackets before if(rg==0) and after the while don't make sense. This code is exdcuted exactly once (no loop instruciton before or after the brackets)
rg is always zero, you never alter it.
i don't see anything in the code that might by any means be related to a tiem (interval/delay, whatever) of 5 seconds.
**Attention** This is a public forum