Other Parts Discussed in Thread: MSP430G2553
Hello,
I am making my program using msp430g2553 launch pad. In this i have taken input from P2.4 and i want my output from P2.0, P2.1 and P2.2.
In this program i have to generate the pulse of 500ms from input. and my output will be three low pulses from the three pins. Meaning whenever i connect my oscilloscope probe to 2.4 i can see the pulse. But the program i made it didn't work. when i connect to the oscilloscope it is showing nothing.
when my input pulse is high i will get the three low pulses output.
here is my code, please check it and tell me what is wrong in the code? since it doesn't contains any error.
code:
#include <msp430g2553.h>
#define CPU_F ((double)16000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
char C_1, C_2;
void System_Clock_Init( void )
{
char i;
_NOP();
WDTCTL = WDTPW + WDTHOLD; // Close Watching dog
delay_ms(50); / / 1MHz
if( ( CALBC1_16MHZ == 0xff ) || ( CALDCO_16MHZ == 0xff ) ) // FLASH A was cleared!!!
((void (*)())RESET_VECTOR)();
BCSCTL1 = CALBC1_16MHZ; //ACLK=32768Hz
DCOCTL = CALDCO_16MHZ; //MCLK=DCOCLK=16MHz
BCSCTL2 = 0x06;//SMCLK=DCOCLK/8=2MHz
BCSCTL3 = 0x00; / /cap=1pF
IE1 &= ~OFIE; / /close crystal error interrupt
do
{
IFG1 &= ~OFIFG;
for( i = 0; i < 100; i++ )
{
_NOP();
}
}
while (IFG1 & OFIFG);
_NOP();
}
void IO_INIT(void)
{
NOP();
P2SEL &= ~BIT4;
P2SEL2 &= ~BIT4;
P2REN &= ~BIT4;
/*P2DIR |= BIT2;*/
P2IES |= BIT4;
P2IE |= BIT4;
P2IFG &= ~BIT4;
P2SEL &= ~(BIT0+BIT1);
P2SEL2 &= ~(BIT0+BIT1);
P2REN &= ~(BIT0+BIT1);
//P2DIR &= ~(BIT0+BIT1);
P2OUT &= ~(BIT0+BIT1);
P2SEL &= ~BIT2;
P2SEL2 &= ~BIT2;
P2REN &= ~BIT2;
//P3DIR &= ~BIT1;
P2OUT &= ~BIT2;
}
void main(void)
{
System_Clock_Init();
_NOP();
//WDTCTL = WDT_ARST_1000;
_NOP();
IO_INIT();
_NOP();
_EINT();//open all interrupt
_NOP();
LPM3;
_NOP();
while(1);
}
//------------------------------------------------------------------------------
//Function: Start Timer 0 A0 for Hour Timing 500ms
//------------------------------------------------------------------------------
#pragma vector = PORT2_VECTOR
__interrupt void PORT_C_Interrupt(void)
{
_NOP();
delay_us(20);
if( C_1 == 0xff)
{
if(!( P2IN & BIT4 )) C_2 = 0xff;
}
else
{
if(!( P2IN & BIT4 )) C_1 = 0xff;
}
if(( C_1 == 0xff) && ( C_2 == 0xff))
{
//output A B D
P2OUT |= BIT0;
delay_ms(2);
P2OUT |= BIT1;
P2OUT &= ~BIT0;
delay_ms(2);
P2OUT |= BIT2;
P2OUT &= ~BIT1;
delay_ms(2);
P2OUT &= ~BIT2;
delay_ms(2);
P2OUT ^= BIT1; //P2 toggle
P2IFG &= ~BIT1; //IFG cleared
C_1 =0x00;
C_2 =0x00;
}
_NOP();
}