Home > other >  Beginner's request, help, about msp430g2553 single-chip microcomputer, the specific requirement
Beginner's request, help, about msp430g2553 single-chip microcomputer, the specific requirement

Time:10-13

Required at the beginning of the i2c extension plate 6 led by:
Led1 light 3 and 6 s, led2 light 3 and 5 s, LED3 light 3 s and 4, the led2 light 3 and 5 s, and in the order cycle, and demanded that the LCD display the countdown
Presses the button key1 extension board, led3 light 3 and 6 s, and demanded that the LCD display the countdown, and then return to the state before the
Press the key2, led1 light 3 s, and demanded that the LCD display the countdown, and then return
Press the key3, led4 bright 3 s, and demanded that the LCD display the countdown, and then return

Application:

# include "MSP430G2553. H"
# include "TCA6416A. H"

Void I2C_IODect ();//test event did happen

Void main (void)
{
WDTCTL=WDTPW + WDTHOLD;//off dogs
BCSCTL1=CALBC1_16MHZ;/* Set DCO to 8 MHZ */
DCOCTL=CALDCO_16MHZ;
TCA6416A_Init ();//initialize the IO expansion mouth
int i;
//- tip initialization success -
While (1)
{
PinOUT (0, 0);//led1 light
PinOUT (1, 1);//led2 out
PinOUT (2, 1);//led3 out
PinOUT (3, 1);//led4 out
PinOUT (4, 1);//led5 out
PinOUT (5, 0);//led6 bright
WDTCTL=WDT_ADLY_1000;//set WDT is -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for(i=0; i<3; I++)
{
IFG1 & amp;=~ WDTIFG;
while(! (IFG1 & amp; WDTIFG));
IFG1 & amp;=~ WDTIFG;
}
IE1 |=WDTIE;//-- -- -- -- -- WDT interrupt can make -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
PinOUT (0, 1);//led1 out
PinOUT (1, 0);//led2 light
PinOUT (2, 1);//led3 out
PinOUT (3, 1);//led4 out
PinOUT (4, 0);//led5 lights
PinOUT (5, 1);//led6 out
WDTCTL=WDT_ADLY_1000;//set WDT is -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for(i=0; i<3; I++)
{
IFG1 & amp;=~ WDTIFG;
while(! (IFG1 & amp; WDTIFG));
IFG1 & amp;=~ WDTIFG;
}
IE1 |=WDTIE;//-- -- -- -- -- WDT interrupt can make -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
PinOUT (0, 1);//led1 out
PinOUT (1, 1);//led2 out
PinOUT (2, 0);//led3 lights
PinOUT (3, 0);//led4 bright
PinOUT (4, 1);//led5 out
PinOUT (5, 1);//led6 out
WDTCTL=WDT_ADLY_1000;//set WDT is -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for(i=0; i<3; I++)
{
IFG1 & amp;=~ WDTIFG;
while(! (IFG1 & amp; WDTIFG));
IFG1 & amp;=~ WDTIFG;
}
IE1 |=WDTIE;//-- -- -- -- -- WDT interrupt can make -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
PinOUT (0, 1);//led1 out
PinOUT (1, 0);//led2 light
PinOUT (2, 1);//led3 out
PinOUT (3, 1);//led4 out
PinOUT (4, 0);//led5 lights
PinOUT (5, 1);//led6 out
WDTCTL=WDT_ADLY_1000;//set WDT is -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for(i=0; i<3; I++)
{
IFG1 & amp;=~ WDTIFG;
while(! (IFG1 & amp; WDTIFG));
IFG1 & amp;=~ WDTIFG;
}
IE1 |=WDTIE;//-- -- -- -- -- WDT interrupt can make -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
PinIN ();
I2C_IODect ();
_bis_SR_register (LPM0_bits);
}
}
/* * * * * * * * * * * WDT timer interrupt function * * * * * * * * * * * * */
# pragma vector=WDT_VECTOR
__interrupt void watchdog_timer (void)
{
//PinIN ();
//I2C_IODect ();
__bic_SR_register_on_exit (LPM0_bits);
}
/* * * * * * * * * * I2C extension IO interrupt handler function * * * * * * * * * * * * * * */
Void I2C_IO10_Onclick ()
{
int i;
The static unsigned char turn=1;
Turn ^=BIT0;
PinOUT (0, 1);//led1 out
PinOUT (1, 1);//led2 out
PinOUT (2, 0);//led3 lights
PinOUT (3, 1);//led4 out
PinOUT (4, 1);//led5 out
PinOUT (5, 0);//led6 bright
WDTCTL=WDT_ADLY_1000;//set WDT is -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for(i=0; i<3; I++)
{IFG1 & amp;=~ WDTIFG;
while(! (IFG1 & amp; WDTIFG));
IFG1 & amp;=~ WDTIFG;
}
IE1 |=WDTIE;//-- -- -- -- -- WDT interrupt can make -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
}
Void I2C_IO11_Onclick ()
{
int i;
The static unsigned char turn=1;
Turn ^=BIT0;
PinOUT (0, 0);//led1 light
PinOUT (1, 1);//led2 out
PinOUT (2, 1);//led3 out
PinOUT (3, 1);//led4 out
PinOUT (4, 1);//led5 out
PinOUT (5, 1);//led6 out
WDTCTL=WDT_ADLY_1000;//set WDT is -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for(i=0; i<3; I++)
{IFG1 & amp;=~ WDTIFG;
while(! (IFG1 & amp; WDTIFG));
IFG1 & amp;=~ WDTIFG;
}
IE1 |=WDTIE;//-- -- -- -- -- WDT interrupt can make -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
}
Void I2C_IO12_Onclick ()
{
int i;
The static unsigned char turn=1;
Turn ^=BIT0;
PinOUT (0, 1);//led1 out
PinOUT (1, 1);//led2 out
PinOUT (2, 1);//led3 out
PinOUT (3, 0);//led4 bright
PinOUT (4, 1);//led5 out
PinOUT (5, 1);//led6 out
WDTCTL=WDT_ADLY_1000;//set WDT is -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for(i=0; i<3; I++)
{IFG1 & amp;=~ WDTIFG;
while(! (IFG1 & amp; WDTIFG));
IFG1 & amp;=~ WDTIFG;
}
IE1 |=WDTIE;//-- -- -- -- -- WDT interrupt can make -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
}
Void I2C_IODect ()//detection event did happen
{
The static unsigned char KEY_Past=0, KEY_Now=0;
KEY_Past=KEY_Now;
//- determine whether even by I2C_IO10 KEY1 button is pressed -- -- -- -- -- --
If ((TCA6416A_InputBuffer & amp; BIT8)==BIT8)
KEY_Now |=BIT0;
The else
KEY_Now & amp;=~ BIT0;
If (((KEY_Past & amp; BIT0)==BIT0) & amp; & (KEY_Now & amp; BIT0)!=BIT0)
I2C_IO10_Onclick ();
//- determine whether even by I2C_IO11 KEY2 button is pressed -- -- -- -- -- --
If ((TCA6416A_InputBuffer & amp; Combination)==combination)
KEY_Now |=BIT1;
The else
KEY_Now & amp;=~ BIT1;
If (((KEY_Past & amp; BIT1)==BIT1) & amp; & (KEY_Now & amp; BIT1)!=BIT1)
I2C_IO11_Onclick ();
//- determine whether even by I2C_IO12 KEY3 button is pressed -- -- -- -- -- --
If ((TCA6416A_InputBuffer & amp; BITA)==BITA)
KEY_Now |=BIT2;
The else
KEY_Now & amp;=~ BIT2;
If (((KEY_Past & amp; BIT2)==BIT2 & amp; & (KEY_Now & amp; BIT2)==0)
{
I2C_IO12_Onclick ();
}
}

Now implement the main loop, but I don't know how to implement the key control interrupt and returns and LCD display, bosses, genuflect is begged help the