0% found this document useful (0 votes)
32 views2 pages

Project 11

programming project on msp430.

Uploaded by

russejustice
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Project 11

programming project on msp430.

Uploaded by

russejustice
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <msp430.

h>
extern void LCDini(void);

const char lcd_number_map[10] = {


0xFC, // 0
0x60, // 1
0xDB, // 2
0xF3, // 3
0x67, // 4
0xB7, // 5
0xBF, // 6
0xE4, // 7
0xFF, // 8
0xF7 // 9
};

volatile int seconds = 0;


volatile int minutes = 0;
volatile int hours = 0;
volatile int running = 0; // Timer is stopped by default

void display_time(void) {
// Display hours
LCDMEM[9] = lcd_number_map[hours / 10]; // Tens place of hours
LCDMEM[5] = lcd_number_map[hours % 10]; // Units place of hours

// Display minutes
LCDMEM[3] = lcd_number_map[minutes / 10]; // Tens place of minutes
LCDMEM[18] = lcd_number_map[minutes % 10];// Units place of minutes

// Display seconds
LCDMEM[14] = lcd_number_map[seconds / 10]; // Tens place of seconds
LCDMEM[7] = lcd_number_map[seconds % 10]; // Units place of seconds
}

void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop Watchdog timer
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO high-impedance mode
LCDini(); // Initialize the LCD

display_time(); // Show 00:00:00 initially

// Enable colon indicators on the LCD


LCDMEM[6] |= BIT2; // Left Colon
LCDMEM[19] |= BIT2; // Right Colon

// Set up switch S1 (connected to P1.1 for example)


P1DIR &= ~BIT1; // Set P1.1 as input
P1REN |= BIT1; // Enable pull-up resistor
P1OUT |= BIT1; // Set pull-up mode
P1IE |= BIT1; // Enable interrupt on P1.1
P1IES |= BIT1; // High-to-low edge
P1IFG &= ~BIT1; // Clear interrupt flag

// Setup Timer_A for 1-second interrupts


TA0CCTL0 = CCIE; // Enable interrupt for CCR0
TA0CCR0 = 32767; // Set CCR0 value for 1-second delay (assuming
32.768 kHz crystal)
TA0CTL = TASSEL_1 + MC_1; // ACLK, up mode

__enable_interrupt(); // Enable global interrupts

while (1) {
__low_power_mode_3(); // Enter low-power mode, wait for interrupts
}
}

// Timer ISR - Triggered every second


#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A_ISR(void) {
if (running) {
seconds++;
if (seconds == 60) {
seconds = 0;
minutes++;
if (minutes == 60) {
minutes = 0;
hours++;
}
}

// Update LCD with new time


display_time();
}
}

// Switch ISR - Handle button press to start/stop timer


#pragma vector=PORT1_VECTOR
__interrupt void Port_1_ISR(void) {
if (P1IFG & BIT1) {
running = !running; // Toggle running state
P1IFG &= ~BIT1; // Clear interrupt flag
}
}

void LCDini(void) {
// LCD initialization as provided in the previous code
LCDCPCTL0 = 0xFFFF;
LCDCPCTL1 = 0xFC3F;
LCDCPCTL2 = 0x00FF;

PJSEL0 = BIT4 | BIT5; // Turn on LFXT


CSCTL0_H = CSKEY >> 8; // Unlock CS registers
CSCTL4 &= ~LFXTOFF; // Enable LFXT
do {
CSCTL5 &= ~LFXTOFFG; // Clear LFXT fault flag
SFRIFG1 &= ~OFIFG;
} while (SFRIFG1 & OFIFG); // Test oscillator fault flag
CSCTL0_H = 0; // Lock CS registers

// Initialize LCD_Clock
LCDCCTL0 = LCDDIV__1 | LCDPRE__16 | LCD4MUX | LCDLP;

// VLCD generated internally, charge pump enabled


LCDCVCTL = VLCD_1 | VLCDREF_0 | LCDCPEN;
LCDCCPCTL = LCDCPCLKSYNC; // Clock synchronization enabled
LCDCMEMCTL = LCDCLRM; // Clear LCD memory
LCDCCTL0 |= LCDON; // Turn LCD on
}

You might also like