I am working on TI experiments board. I have written a certain chunk of code basically to display time. which works perfectly.Now I want to use two push buttons in order to adjust time hours:minutes. However, its not working. Am I am missing something here. Or can someone tell me a better way to do it. The switches are connected to p1.0 and p1.1.??? Any help will be much appreciated.Scroll down to the bold bit. thanks
#include <msp430fg4618.h>//change it for LCD driver model MSP430FG461
#include <intrinsics.h>
#include <stdint.h>
#define LCDMEMS 11 //to access the LCD memory
uint8_t * const LCDMem= (uint8_t *) &LCDM3;
#define SEG_A BIT0
#define SEG_B BIT1
#define SEG_C BIT2
#define SEG_D BIT3
#define SEG_E BIT4
#define SEG_F BIT5
#define SEG_G BIT6
#define SEG_H BIT7 // define statement.. each occurence will be replaced by subsequent bits
const uint8_t LCDHexChar[] = {
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, //0
SEG_B | SEG_C , //1
SEG_A | SEG_B | SEG_D | SEG_G | SEG_F, //2
SEG_A | SEG_B | SEG_C | SEG_D | SEG_F, //3
SEG_B | SEG_C | SEG_E | SEG_F, //4
SEG_A | SEG_C | SEG_D | SEG_E | SEG_F, //5
SEG_A | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, //6
SEG_A | SEG_B | SEG_C, //7,
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F |SEG_G,//8
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, //9
};
const uint8_t LCDAMChar = SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G;//display characters to indicate AM(A) and PM (p)
const uint8_t LCDPMChar = SEG_A | SEG_B | SEG_E | SEG_F | SEG_G;
const uint8_t LCDBlankChar = 0;
void InitLCD (void); //will be used later
void main(void) {
WDTCTL = WDTPW|WDTHOLD; //WATCHDOG TIMER STOP
InitLCD();
TACCR0 = 0x8000; //upper limit for timer count
TACCTL0 = CCIE; //enable compare 0 interrupts
TACTL = MC_1|TASSEL_1|TACLR; //setting up timer A ,no clock division
P1DIR&=~BIT0; //To enable these pins to be used as inputs
P1DIR&=~BIT1;
for (;;) {
__low_power_mode_3(); //Asynchronous clock continues to run
}
}
//INITIALIZING THE LCD DISPLAY
void InitLCD (void)
{
int i;
for (i = 0; i <LCDMEMS; ++i) { //clear LCD memory
LCDMem [i] = 0;
}
//configuring LCD-A controller
P5SEL =BIT4|BIT3|BIT2;//shared pins of port 5 are assigned to backplanes (COM)
LCDAPCTL0 =LCDS4|LCDS8|LCDS12|LCDS16|LCDS20|LCDS24;//Enable LCD segs 4-27 (till 25 used),
LCDAVCTL0 = 0;// no charge pump used
LCDACTL = LCDFREQ_128 |LCD4MUX|LCDSON |LCDON;//Aclk/128 ; 4 mux; segments on;LCD_A on
}
//ISR FOR TIMER//
#pragma vector = TIMERA0_VECTOR
__interrupt void TIMERA0_ISR (void){
//variables need to be static so that they dont change and short as to match with the intrinsic functions for BCD arithmetic
static unsigned short seconds = 0x59; //initial time in BCD 23:59:59
static unsigned short minutes = 0x59;
static unsigned short hours = 0x23;
//Updating time//
seconds = __bcd_add_short(seconds, 0x01);//seconds incremented(intrinsic function used)
if(seconds >= 0x60){
seconds = 0;
minutes = __bcd_add_short(minutes,0x01); //minutes incremented
if(minutes >= 0x60){
minutes = 0; //new hour started
hours = __bcd_add_short(hours,0x01);//hours incremented
if (hours >= 0x24){
hours = 0; //new day
}
}
}
LCDMem[1] = LCDHexChar[seconds & 0x0F]; //Updating all the digits ;segment H is the colon
LCDMem[2] = LCDHexChar[(seconds >> 4) & 0x0F] | SEG_H ;
LCDMem[3] = LCDHexChar[minutes & 0x0F];
LCDMem[4] = LCDHexChar[(minutes >> 4) & 0x0F] | SEG_H;
LCDMem[5] = LCDHexChar[hours & 0x0F];
LCDMem[6] = LCDHexChar[(hours >> 4) & 0x0F] | SEG_H;
}
//TIME ADJUSTMENT //
#pragma vector = PORT1_VECTOR
__interrupt void Port1_ISR(void)
{
//variables need to be static so that they dont change and short as to match with the intrinsic functions for BCD arithmetic
static unsigned short seconds = 0x59; //initial time in BCD 23:59:59
static unsigned short minutes = 0x59;
static unsigned short hours = 0x23;
if ((P1IN & BIT0)==0){
hours = __bcd_add_short(hours,0x01);
if ((P1IN & BIT1)==0){
minutes = __bcd_add_short(minutes,0x01);
}
}
LCDMem[3] = LCDHexChar[minutes & 0x0F];
LCDMem[4] = LCDHexChar[(minutes >> 4) & 0x0F] | SEG_H;
LCDMem[5] = LCDHexChar[hours & 0x0F];
LCDMem[6] = LCDHexChar[(hours >> 4) & 0x0F] | SEG_H;
}