Part Number: MSP430F5529
Tool/software: Code Composer Studio
Hello everyone!
I am new to the world of microprocessors and for the moment i am using the MSP-EXP430F5529LaunchPad and Code Composer Studio 7.4
I am trying to write a program using DriverLib for a safety belt system with the following specifications:
"The controller will light on a red LED if someone is sitting in a car seat and is not fastened after 15 seconds. If the passenger is fastened within 15 seconds, the controller will light on a green LED respectively.
This system has three inputs and two outputs. The inputs are a Push Button Sensor (P1.1) to know when a person is sitting, a Push Button (P2.1) that recognizes whether the belt is tied or not by the passenger and a timer notifying that the required time has elapsed.
The controller is idle when there is no one in the seat. When someone sits, the controller turns on the timer. If time is over before the safety belt is tightened, the red LED lights up. If the seat belt is fastened in time, the green LED lights up and the controller enters a surveillance mode. During the surveillance it is checked whether the passenger continues to have the belt tied. When the passenger leaves the seat, the controller returns to idle state."
I ended up with the following program:
#include <msp430.h>
#include <driverlib.h>
#define LF_CRYSTAL_FREQUENCY_IN_HZ 32768
#define HF_CRYSTAL_FREQUENCY_IN_HZ 4000000
volatile unsigned short beltButton = 0;
volatile unsigned short seatButton = 0;
void main(void)
{
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P2, GPIO_PIN1);
beltButton = GPIO_getInputPinValue(GPIO_PORT_P2, GPIO_PIN1);
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
seatButton = GPIO_getInputPinValue(GPIO_PORT_P1, GPIO_PIN1);
GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN7);
GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN7);
UCS_setExternalClockSource(
LF_CRYSTAL_FREQUENCY_IN_HZ,
HF_CRYSTAL_FREQUENCY_IN_HZ);
UCS_initClockSignal(UCS_ACLK,
UCS_REFOCLK_SELECT,
UCS_CLOCK_DIVIDER_8);
while (1){
unsigned volatile int i;
if((seatButton == GPIO_INPUT_PIN_LOW)&&(beltButton == GPIO_INPUT_PIN_HIGH))
{
for(i=10000;i>0;i--)
GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); }
if(beltButton == GPIO_INPUT_PIN_LOW)
{
GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN7);
GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
break;
}
else{GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
i=0;}
break;
}
}
If you press P2.1 the red LED lights up. If you keep pressing P2.1 and press P1.1 the red LED turns off and the green LED lights up. So far, so good.
My problem is that i cannot implement a timer so that the red LED lights up after P2.1 is kept pressed for 15 seconds ("The controller will light on a red LED if someone is sitting in a car seat and is not fastened after 15 seconds.).
Any ideas?