Hi,
I am currently working on 'Face Recognition' which requires LCD to be interfaced with the MSP430G2553. I have to display a message repeatedly. So i am planning to have a code as under
while(1)
{
ClearLcmScreen();
PrintStr("Press LOGIN to start logging in"); // main program starts
// __delay_cycles(1000000);
_BIS_SR (LPM3_bits + GIE);
Decision();
}
First the main string is displayed then the msp goes into sleep mode. when any person presses the LOGIN button the msp wakes and initiates decision function.
After the decision function gets over, the msp must again go back to orignal mode and display "Press LOGIN". and again the process repeates.
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
{
}
In the ISR i want to turn off the sleep mode and start active mode.
This is my program code.
//
// MSP430 LCD Code
//
#include "msp430g2553.h"
// Defining ports for LCM
#define LCM_DIR P1DIR
#define LCM_OUT P1OUT
// Defining ports for BUTTONS
#define BUT_DIR P2DIR
#define BUT_IN P2IN
//
// Define symbolic LCM - MCU pin mappings
// We've set DATA PIN TO 4,5,6,7 for easy translation
//
#define LCM_PIN_RS BIT0 // P1.0
#define LCM_PIN_EN BIT1 // P1.1
#define LCM_PIN_D7 BIT7 // P1.7
#define LCM_PIN_D6 BIT6 // P1.6
#define LCM_PIN_D5 BIT5 // P1.5
#define LCM_PIN_D4 BIT4 // P1.4
// Define symbolic BUTTON - MCU mapping
// we've set ports p2.0,p2.1,p2.2 as input ports
#define BUT_PIN_T1 BIT0 // P2.0
#define BUT_PIN_T2 BIT1 // P2.1
#define ENROLL BIT2 // P2.2
#define LOGIN BIT3 // P2.3
#define LCM_PIN_MASK (LCM_PIN_RS | LCM_PIN_EN | LCM_PIN_D7 | LCM_PIN_D6 | LCM_PIN_D5 | LCM_PIN_D4)
#define BUT_PIN_MASK (BUT_PIN_T1 | BUT_PIN_T2 | ENROLL | LOGIN)
#define FALSE 0
#define TRUE 1
//
// Routine Desc:
//
// This is the function that must be called
// whenever the LCM needs to be told to
// scan it's data bus.
//
// Parameters:
//
// void.
//
// Return
//
// void.
//
void PulseLcm()
{
//
// pull EN bit low
//
LCM_OUT &= ~LCM_PIN_EN;
__delay_cycles(200);
//
// pull EN bit high
//
LCM_OUT |= LCM_PIN_EN;
__delay_cycles(200);
//
// pull EN bit low again
//
LCM_OUT &= (~LCM_PIN_EN);
__delay_cycles(200);
}
//
// Routine Desc:
//
// Send a byte on the data bus in the 4 bit mode
// This requires sending the data in two chunks.
// The high nibble first and then the low nible
//
// Parameters:
//
// ByteToSend - the single byte to send
//
// IsData - set to TRUE if the byte is character data
// FALSE if its a command
//
// Return
//
// void.
//
void SendByte(char ByteToSend, int IsData)
{
//
// clear out all pins
//
LCM_OUT &= (~LCM_PIN_MASK);
//
// set High Nibble (HN) -
// usefulness of the identity mapping
// apparent here. We can set the
// DB7 - DB4 just by setting P1.7 - P1.4
// using a simple assignment
//
LCM_OUT |= (ByteToSend & 0xF0);
if (IsData == TRUE)
{
LCM_OUT |= LCM_PIN_RS;
}
else
{
LCM_OUT &= ~LCM_PIN_RS;
}
//
// we've set up the input voltages to the LCM.
// Now tell it to read them.
//
PulseLcm();
//
// set Low Nibble (LN) -
// usefulness of the identity mapping
// apparent here. We can set the
// DB7 - DB4 just by setting P1.7 - P1.4
// using a simple assignment
//
LCM_OUT &= (~LCM_PIN_MASK);
LCM_OUT |= ((ByteToSend & 0x0F) << 4);
if (IsData == TRUE)
{
LCM_OUT |= LCM_PIN_RS;
}
else
{
LCM_OUT &= ~LCM_PIN_RS;
}
//
// we've set up the input voltages to the LCM.
// Now tell it to read them.
//
PulseLcm();
}
//
// Routine Desc:
//
// Set the position of the cursor on the screen
//
// Parameters:
//
// Row - zero based row number
//
// Col - zero based col number
//
// Return
//
// void.
//
void LcmSetCursorPosition(char Row, char Col)
{
char address;
//
// construct address from (Row, Col) pair
//
if (Row == 0)
{
address = 0;
}
else
{
address = 0x40;
}
address |= Col;
SendByte(0x80 | address, FALSE);
}
//
// Routine Desc:
//
// Clear the screen data and return the
// cursor to home position
//
// Parameters:
//
// void.
//
// Return
//
// void.
//
void ClearLcmScreen()
{
//
// Clear display, return home
//
__delay_cycles(20000);
SendByte(0x01, FALSE);
__delay_cycles(2000);
SendByte(0x02, FALSE);
__delay_cycles(20000);
}
//
// Routine Desc:
//
// Initialize the LCM after power-up.
//
// Note: This routine must not be called twice on the
// LCM. This is not so uncommon when the power
// for the MCU and LCM are separate.
//
// Parameters:
//
// void.
//
// Return
//
// void.
//
void InitializeLcm(void)
{
//
// set the MSP pin configurations
// and bring them to low
//
LCM_DIR |= LCM_PIN_MASK;
LCM_OUT &= ~(LCM_PIN_MASK);
//
// wait for the LCM to warm up and reach
// active regions. Remember MSPs can power
// up much faster than the LCM.
//
__delay_cycles(100000);
//
// initialize the LCM module
//
// 1. Set 4-bit input
//
LCM_OUT &= ~LCM_PIN_RS;
LCM_OUT &= ~LCM_PIN_EN;
LCM_OUT = 0x20;
PulseLcm();
//
// set 4-bit input - second time.
// (as reqd by the spec.)
//
SendByte(0x28, FALSE);
//
// 2. Display on, cursor on, blink cursor
//
SendByte(0x0F, FALSE);
//
// 3. Cursor move auto-increment
//
SendByte(0x06, FALSE);
__delay_cycles(500);
SendByte(0x80,FALSE);
}
//
// Routine Desc
//
// Initializes the Buttons so that input can be taken
//
// Parameters:
//
// void
//
// Returns
//
// void.
//
void InitializeBut()
{ BUT_DIR &= ~(BUT_PIN_MASK);
BUT_IN &= BUT_PIN_MASK;
P2IE |= LOGIN; // Interrupt Enable in P2.3
P2IES &= ~LOGIN; // P2.3 Interrupt flag low-to-high transition
P2IFG &= ~LOGIN; // P2.3 IFG cleared
}
//
// Routine Desc
//
// Print a string of characters to the screen
//
// Parameters:
//
// Text - null terminated string of chars
//
// Returns
//
// void.
//
void PrintStr(char *Text)
{
char *c;
c = Text;
unsigned short int n=0;
while ((c != 0) && (*c != 0))
{ if(n>15)
{
LcmSetCursorPosition(1,n-16);
}
SendByte(*c,TRUE);
__delay_cycles(305000);
c++;
n++;
}
}
//
// Routine Desc
//
// Print a string of characters to the screen according to the value of buttons
//
// Parameters:
//
// void
//
// Returns
//
// void.
//
void Decision()
{
if ((BUT_IN & BUT_PIN_T1) == BUT_PIN_T1)
{
if ((BUT_IN & BUT_PIN_T2) == BUT_PIN_T2)
{ ClearLcmScreen();
PrintStr("Face recognized Access Granted");
__delay_cycles(1000000);
}
else
{ ClearLcmScreen();
PrintStr("unknown face like object");
__delay_cycles(1000000);
}
}
else
{
if ((BUT_IN & BUT_PIN_T2) == BUT_PIN_T2)
{ ClearLcmScreen();
PrintStr("unknown face");
__delay_cycles(1005000);
ClearLcmScreen();
PrintStr("You can be added to the database");
__delay_cycles(1005000);
ClearLcmScreen();
PrintStr("Press ENROLL to start enrolling");
__delay_cycles(5005000);
// put a button pressing routine here
if ((BUT_IN & ENROLL) == ENROLL)
{
ClearLcmScreen();
PrintStr("u pressed ENROLL...enrolling....");
__delay_cycles(1000000);
ClearLcmScreen();
PrintStr("image enrolled");
__delay_cycles(1000000);
}
else
{ ClearLcmScreen();
PrintStr("access denied");
__delay_cycles(1000000);
}
}
else
{ ClearLcmScreen();
PrintStr("unknown object");
__delay_cycles(1000000);
}
}
// ClearLcmScreen();
// PrintStr("Press LOGIN to login again");
// __delay_cycles(5000000);
}
// Port2 Interrupt Service Routine
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
{
}
//
// Routine Desc
//
// main entry point to the sketch
//
// Parameters
//
// void.
//
// Returns
//
// void.
//
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
InitializeLcm(); // initializes the LCM
InitializeBut(); // initializes the buttons for now
// in fact it contains inputs from DSP
ClearLcmScreen(); // clears the LCM screen
PrintStr(" Welcome to Bio Recs");
__delay_cycles(1000000);
while(1)
{
ClearLcmScreen();
PrintStr("Press LOGIN to start logging in"); // main program starts
// __delay_cycles(1000000);
_BIS_SR (LPM3_bits + GIE);
Decision();
}
//if ((BUT_IN & LOGIN) == LOGIN) // put an interrupt here so that only
// decision is called when interrupted
// { __delay_cycles(1000000);
// Decision();
// }
}
Can the PORT2 have 2 interrupts? If yes then how to prioritize them?
I am planning to put 2 push buttons for interrupts.