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.
code requirements-
1.five buttons connected to P2.0 to P2.4.
2.Only one button will be pressed at a time and the i/p will be high on button press.
3.Inputs are proned to EMI and hence have to be debounced.
4.There are 3 signls-SG1,SG2,SG3 where for now SG1 is OFF,SG2 is ON,SG3 will be ON for half a second and approximately OFF for half a second.
5.We are required to generate these signals
6.o/p will be on P1.0 and P1.6 of Launchpad
7.Truth table is as follows:
Button pressed LED0 LED1
(after debounced)
NONE SG1 SG1
P2.0 SG1 SG2
P2.1 SG2 SG1
P2.2 SG1 SG3
P2.3 SG3 SG1
P2.4 SG2 SG2
8.At every 2.5ms Current register will be checked for consecutive 1's and if it is found then store it into Deb_array.
If such 8 consecutive 1's are found then toggle the Final register.
program code is given below:
#include "msp430g2452.h"
#define INPUTS BIT0 + BIT1 + BIT2 + BIT3 + BIT4
#define TOTAL_INPUTS 5
#define SG1_MASK BIT0
#define SG2_MASK BIT1
#define SG3_MASK BIT2
volatile char Current,Change,Deb_array[TOTAL_INPUTS],Signals;
volatile char Final=0x00;
volatile char Test_bit;
unsigned int Counter = 0x00;
void configWDT(void);
void configClocks(void);
void configPins(void);
void Debounce(void);
void configTimer(void);
void init_variables(void);
//void loop(void);
void Process_outputs(void);
void main(void)
{
configWDT();
configClocks();
configPins();
init_variables();
configTimer();
// loop();
__enable_interrupt();
while(1)
{
Debounce();
Process_outputs();
__bis_SR_register(LPM0 + GIE);// LPM0 with interrupts enabled
}
}
void configWDT(void)
{
WDTCTL = WDTPW + WDTHOLD;
}
void configClocks(void)
{
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
BCSCTL2 = SELM_0 + DIVM_0 + DIVS_3;
}
void configPins(void)
{
P2DIR =BIT5 + BIT6 +BIT7;
P2REN = INPUTS;
P2OUT &= ~INPUTS;
P1OUT = 0;
P2OUT = 0;
}
void configTimer(void)
{
CCTL0 = CCIE;
CCR0 = 39;
TACTL = TASSEL_2 + MC_1 + TAIE + ID_3;
/*SMCLK,UP_MODE*/
}
void init_variables(void)
{
int i;
for(i=0;i<TOTAL_INPUTS;i++)
{
Deb_array[i] = 0;
}
Signals = BIT1 + BIT2;
}
/*void loop(void)
{
while(1)
{
_BIS_SR(LPM0_bits + GIE);
}
}*/
void Debounce(void)
{
int j;
Current = P2IN & INPUTS;
Change = Current ^ Final;
Test_bit=0x01;
for(j=0 ; j<TOTAL_INPUTS; j++)
{
while(!(Test_bit & INPUTS))
Test_bit *=2;
if(Test_bit & Change)
{
*(Deb_array +j) *= 2;
*(Deb_array +j)+=1;
if(*(Deb_array +j) == 0xff)
Final ^= Test_bit;
}
else
*(Deb_array + j) = 0;
Test_bit *=2;
}
if(Counter < 200)
Counter++;
else
{
Counter = 0;
Signals ^= BIT2;
}
}
void Process_outputs(void)
{
if(Final & BIT0)
{
if(Signals & SG1_MASK)
P1OUT |= BIT6;
else
P1OUT &= ~BIT6;
if(Signals & SG2_MASK)
P1OUT |= BIT0;
else
P1OUT &= ~BIT0;
}
else if(Final & BIT1)
{
if(Signals & SG2_MASK)
P1OUT |= BIT6;
else
P1OUT &= ~BIT6;
if(Signals & SG1_MASK)
P1OUT |= BIT0;
else
P1OUT &= ~BIT0;
}
else if(Final & BIT2)
{
if(Signals & SG1_MASK)
P1OUT |= BIT6;
else
P1OUT &= ~BIT6;
if(Signals & SG3_MASK)
P1OUT |= BIT0;
else
P1OUT &= ~BIT0;
}
else if(Final & BIT3)
{
if(Signals & SG3_MASK)
P1OUT |= BIT6;
else
P1OUT &= ~BIT6;
if(Signals & SG1_MASK)
P1OUT |= BIT0;
else
P1OUT &= ~BIT0;
}
else if (Final & BIT4)
{
if(Signals & SG2_MASK)
P1OUT |= BIT6;
else
P1OUT &= ~BIT6;
if(Signals & SG3_MASK)
P1OUT |= BIT0;
else
P1OUT &= ~BIT0;
}
else
{
if(Signals & SG1_MASK)
P1OUT |= BIT6 + BIT0;
else
P1OUT &= ~(BIT6 + BIT0);
}
}
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A(void)
{
__bic_SR_register_on_exit(LPM3 + GIE);
}
This piece of code is not encountering any kind of compile time error but after entering into ISR it gives an error "unknown Error: execution state prevented access" and code stops running.
Please make suggestions.
**Attention** This is a public forum