Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the Code composer studio to programming msp430 with this code to display in

ID: 3714861 • Letter: U

Question

Use the Code composer studio to programming msp430 with this code to display in lcd screen 2x16 Use the Code composer studio to programming msp430 with this code to display in lcd screen 2x16
#include <msp430.h> #include <stdint.h> #include <stdio.h> 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] != ''; 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); }
#include <msp430.h> #include <stdint.h> #include <stdio.h> 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] != ''; 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); }

Explanation / Answer

#include "8bit_lcd.h"

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // stop watchdog timer

lcd_init();

send_string("Manpreet Singh");

send_command(0xC0);

send_string("Minhas");

while(1){}

}

I've written a seperate header file which can be included in any c program to use its functions. I've made one function for sending command instructions, one for sending data as individual characters and sending strings.

/* 8bit_lcd.h

* Created on: 12-Nov-2013

* Author: Manpreet

*/

#include

#define DR P2OUT = P2OUT | BIT0 // define RS high

#define CWR P2OUT = P2OUT & (~BIT0) // define RS low

#define READ P2OUT = P2OUT | BIT1 // define Read signal R/W = 1 for reading

#define WRITE P2OUT = P2OUT & (~BIT1) // define Write signal R/W = 0 for writing

#define ENABLE_HIGH P2OUT = P2OUT | BIT2 // define Enable high signal

#define ENABLE_LOW P2OUT = P2OUT & (~BIT2) // define Enable Low signal

unsigned int i;

unsigned int j;

void delay(unsigned int k)

{

for(j=0;j<=k;j++)

{

for(i=0;i<1000;i++);

}

}

void data_write(void)

{

ENABLE_HIGH;

delay(2);

ENABLE_LOW;

}

void data_read(void)

{

ENABLE_LOW;

delay(2);

ENABLE_HIGH;

}

void check_busy(void)

{

P1DIR &= ~(BIT7); // make P2.3 as input

while((P1IN&BIT7;)==1)

{

data_read();

}

P1DIR |= BIT7; // make P2.3 as output

}

void send_command(unsigned char cmd)

{

check_busy();

WRITE;

CWR;

P1OUT = (P1OUT & 0x00)|(cmd);

data_write(); // give enable trigger

}

void send_data(unsigned char data)

{

check_busy();

WRITE;

DR;

P1OUT = (P1OUT & 0x00)|(data);

data_write(); // give enable trigger

}

void send_string(char *s)

{

while(*s)

{

send_data(*s);

s++;

}

}

void lcd_init(void)

{

P2DIR |= 0xFF;

P1DIR |= 0xFF;

P2OUT &= 0x00;

P1OUT &= 0x00;

send_command(0x38); // 8 bit mode

send_command(0x0E); // clear the screen

send_command(0x01); // display on cursor on

send_command(0x06);// increment cursor

send_command(0x80);// cursor position

}