Debouncing a switch in a display menu code (MSP430FG4618)

Status
Not open for further replies.

fatma7886

Newbie level 3
Joined
Feb 28, 2010
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
electronics
Activity points
1,361
Hi;
I'am working with a MSP430FG4618, and I want to post a menu in order(menu_1, menu_2,menu_3)
when I press S1==> posting of the menu_1
when I press one more time S1==>posting of the menu_2
when I press third once S1==> posting of menu_3

for that, I have fixed a variable nomed "page" whith is incremented when the button is pressed. so I have used this fonction that I colled:

//********************************************************************
//select_page
//********************************************************************

void select_page ()
{


switch(page)
{
case 0X01: yes(); page <<= 1; break; // menu_1
case 0X02: LCDM11 |= 0x20; page <<= 1; break; // menu_2
case 0X04: LCDM11 |= 0x80; page <<= 1; break; // mebu_3
};
if( page >= 0X08 ) page = 0X01;
}
**********************************************************************
the problem is that,when i press S1, the variable" page" does not follow the order, it takes a random value. I don't know whay!!!!!
please help me.
My code is:

#include "msp430xG46x.h"
//*******************************************************************
// Declaration des fonctions prototypes
//*******************************************************************
void Test_LCD(void);
void Disp_BCD(unsigned long Value);
void clrlcd(void);
void bagage_1 (void);
void yes(void);
void select_page (void);

//********************************************************************
// Variables globales
//*******************************************************************
static unsigned char var1;
static unsigned char var2;
static unsigned char var3;
static unsigned char page=0X01;
//********************************************************************
// Parametrage des segments
//*******************************************************************
#define a 0x01
#define b 0x02
#define c 0x04
#define d 0x08
#define e 0x40
#define f 0x10
#define g 0x20

//********************************************************************
// Definition des digits
//********************************************************************
const char char_gen[] = {
a+b+c+d+e+f, // Displays "0"
b+c, // Displays "1"
a+b+d+e+g, // Displays "2"
a+b+c+d+g, // Displays "3"
b+c+f+g, // Displays "4"
a+c+d+f+g, // Displays "5"
a+c+d+e+f+g, // Displays "6"
a+b+c, // Displays "7"
a+b+c+d+e+f+g, // Displays "8"
a+b+c+d+f+g, // Displays "9"
a+b+c+e+f+g, // Displays "A"
a+f+e+d, // Displays "C"
a+f+e+d+g, // Displays "E"
a+e+f+g, // Displays "F"
b+c+e+f+g, // Displays "H"
b+c+d, // Displays "J"
c+e+f+g, // Displays "k"
d+e+f, // Displays "L"
a+b+c+e+f, // Displays "M"
c+e+g, // Displays "n"
a+b+e+f+g, // Diplays "P"
g+e, // Displays "r"
f+e+g, // Displays "t"
b+c+d+e+f, // Displays "U" & "V"
0, // Blank

};
//********************************************************************
// LCD Test Code
//********************************************************************

void Test_LCD(void)
{
}
//********************************************************************
// Displays the BCD number 'Value' on the LCD display. 7 digits are //output.
//********************************************************************
void Disp_BCD(unsigned long Value)
{
}
//********************************************************************
// Clear LCD
//********************************************************************
void clrlcd(void)
{
volatile int j;
unsigned int offset = 2; // LCD memory offset variable
for( j = 0; j < 12; j ++)
{
LCDMEM[j+offset] = 0; // Clear LCD
}
}
//********************************************************************
//bagage1
//********************************************************************
void bagage_1 (void)
{
}
//********************************************************************
//yes
//********************************************************************
void yes(void)
{
}

//********************************************************************
//select_page
//********************************************************************
void select_page ()
{


switch(page)
{
case 0X01: yes(); page <<= 1; break; // menu_1
case 0X02: LCDM11 |= 0x20; page <<= 1; break; // menu_2
case 0X04: LCDM11 |= 0x80; page <<= 1; break; // menu_3
};
if( page >= 0X08 ) page = 0X01;
}



//********************************************************************
// Main routine; Fonction principale
//********************************************************************

void main(void)
{
volatile unsigned int i;

WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FLL_CTL0 |= XCAP14PF; // Configure load caps

// LFXT1 startup delay
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0x47FF; i > 0; i--); // Time for flag to set
}
while (IFG1 & OFIFG); // OSCFault flag still set?



// Configuration du port P1

P1OUT = 0; // All P1.x reset
P1IES = 0x03; // P1.0, P1.1 hi/low edge
P1DIR = 0xFC; // P1.0/1 = input (switches)
P1IE |=BIT0+BIT1;
// LCD_A

// Configure COM0-COM3 and R03-R33 pins
P5SEL |= (BIT4 | BIT3 | BIT2);
P5DIR |= (BIT4 | BIT3 | BIT2);
// LCD_A S0-S21 configuration
LCDAPCTL0 = LCDS24 | LCDS20 | LCDS16 | LCDS12 | LCDS8 | LCDS4;

// Configure LCD_A
LCDACTL = LCDFREQ_128 | LCDMX1 | LCDMX0 | LCDSON | LCDON;
LCDAPCTL1 = 0;
LCDAVCTL0 = LCDCPEN;
LCDAVCTL1 = VLCD_2_60;
Test_LCD();
bagage_1 ();
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupt
}
//********************************************************************
// PORT1 interrupt handler : traitement de l'interruption
//********************************************************************

#pragma vector=PORT1_VECTOR
__interrupt void Port1_ISR (void)
{
if (!(P1IN & 0x01))
{

clrlcd();
select_page();
}
}
 

Re: display menu

Are you considering key bouncing ?

You should solve this either by hardware or software.

By software a 300 ~ 500 mSec delay will work.

Let us know.
 

display menu

I dont know how can I debounce the switch. help me please. haw can I do it?
 

Re: display menu

Try here

**broken link removed**
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…