Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use the Code composer studio to programming msp430 with this code to display in lcd screen 2x16 #include #include #include volatile unsigned int count=0; unsigned
Use the Code composer studio to programming msp430 with this code to display in lcd screen 2x16
#include
#include
#include
volatile unsigned int count=0;
unsigned long button;
int i;
volatile unsigned int seconds=0;
volatile unsigned int minutes=0;
volatile unsigned int hours=0;
volatile unsigned int g=1000000;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
P1DIR |= 0x40;
P1REN |= BIT3;
P1OUT |= BIT3;
P1IE |= BIT3;
P1OUT &= ~0x40;
P1IFG &= ~BIT3;
TA0CCTL0 = CCIE; // CCR0 interrupt enabled
TA0CCR0 = 1000; // 1ms Timer
TA0CTL = TASSEL_2 + MC_1; // SMCLK, contmode
P1SEL = BIT1 + BIT2; // Select UART as the pin function
P1SEL2 = BIT1 + BIT2;
UCA0CTL1 |= UCSWRST; // Disable UART module for configuration
UCA0CTL0 = 0x00; // No parity, LSB first, 8-bit data, 1 stop bit, UART, Asynchronous
UCA0CTL1 = UCSSEL_2 + UCSWRST; // SMCLK source, keep in reset state
UCA0BR0 = 104; // 9600 Baud rate - Assumes 1 MHz clock
UCA0BR1 = 0; // 9600 Baud rate - Assumes 1 MHz clock
UCA0MCTL = 0x02; // 2nd Stage modulation = 1, Oversampling off
UCA0CTL1 &= ~UCSWRST; // Enable UART module
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
// Timer A0 interrupt service routine
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer_A (void)
{
count = count + 1;
if (count >=1000){
seconds=seconds + 1;
count=0;
serial_number(hours);
serial_string(":");
serial_number(minutes);
serial_string(":");
serial_number(seconds);
serial_string(" ");}
if(seconds>=60){
minutes= minutes + 1;
seconds =0;}
if(minutes>=60){
hours= hours + 1;
minutes=0;}
if (hours>=24){
hours=0;
minutes=0;
seconds=0;
count=0;
}
/*switch(count)
{
case 3554: P1OUT |= 0x40; TA0CCR1 = 0;
break;
}
TA0CCR1 += 1;*/
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
/* serial_number(hours);
serial_string(":");
serial_number(minutes);
serial_string(":");
serial_number(seconds);
serial_string(" ");*/
/*if(P1IN & 0x40){
button = TA0CCR1;
serial_string("Your Time was: ");
serial_number(button);
serial_string("ms ");
P1OUT &= ~0x40;
button = 0;
count = 0;
}*/
//P1IFG &= ~BIT3; // P1.3 IFG cleared
}
void serial_string(char string[])
{
int i;
for(i = 0; string[i] != '\0'; i++) // Send characters until end-of-string
{
while( !(IFG2 & UCA0TXIFG) ); // Wait until the transmit buffer is empty
UCA0TXBUF = string[i]; // Send the character through the Xmit buffer
}
}
void serial_number(int value)
{
char string[10];
sprintf(string, "%d", value); // Convert an integer to a character string
serial_string(string);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started