Question: fix this code for MSP 4 3 0 FR 6 9 8 9 to create some kind of character and put the character on A

fix this code for MSP430 FR6989 to create some kind of character and put the character on A4. If the left button (S1) is pressed, the
character moves 1 space to the left. If the right button (S2) is pressed, the character moves 1 space to
the right. If the left button is pressed, and the character is in the A1 position, then the red light should
go on and the character doesnt move. If the right button is pressed, and the character is in the A6
position, then the green light should go on and the character doesnt move.
#include
#define SEC 0x5A80
#define pos1B 9
#define pos2B 6
#define pos3B 4
#define pos4B 19
#define pos5B 15
#define pos6B 8
#define RED 0x01
#define GREEN 0x80
#define button10x0002
#define button20x0004
const unsigned int lcd_num[6]={0x00FC,0x0060,0x00DB,0x00F3,0x0067,0x00B7};
int currentPosition = pos4B;
void initGPIO(){
P1DIR |= RED | GREEN;
P1REN |= button1| button2;
P1OUT |= button1| button2;
}
void MoveCharacterLeft(){
if (currentPosition > pos1B){
currentPosition--;
__delay_cycles(10000); // Delay for debouncing
} else {
P1OUT |= RED;
}
}
void MoveCharacterRight(){
if (currentPosition < pos6B){
currentPosition++;
__delay_cycles(10000); // Delay for debouncing
} else {
P1OUT |= GREEN;
}
}
void displayCharacter(){
// Update LCD with the character's position
LCDMEM[pos1B]=(currentPosition == pos1B)? lcd_num[currentPosition] : 0x0000;
LCDMEM[pos2B]=(currentPosition == pos2B)? lcd_num[currentPosition] : 0x0000;
LCDMEM[pos3B]=(currentPosition == pos3B)? lcd_num[currentPosition] : 0x0000;
LCDMEM[pos4B]=(currentPosition == pos4B)? lcd_num[currentPosition] : 0x0000;
LCDMEM[pos5B]=(currentPosition == pos5B)? lcd_num[currentPosition] : 0x0000;
LCDMEM[pos6B]=(currentPosition == pos6B)? lcd_num[currentPosition] : 0x0000;
}
int main(void){
WDTCTL = WDTPW | WDTHOLD;
// Initialize LCD segments
LCDCPCTL0=0xFFFF;
LCDCPCTL1=0xFC3F;
LCDCPCTL2=0x0FFF;
LCDCCTL0= LCDDIV__1| LCDPRE__16| LCD4MUX | LCDLP;
LCDCVCTL = VLCD_1| VLCDREF_0| LCDCPEN;
LCDCCPCTL = LCDCPCLKSYNC;
LCDCMEMCTL = LCDCLRM;
LCDCCTL0|= LCDON;
PM5CTL0 &= ~LOCKLPM5;
initGPIO();
while (1){
if (!(P1IN & button1)){
MoveCharacterLeft();
MoveCharacterLeft(); // move the character twice to prevent fast scrolling
P1OUT &= ~RED; // Turn off red LED
}
if (!(P1IN & button2)){
MoveCharacterRight();
MoveCharacterRight(); // move the character twice to prevent fast scrolling
P1OUT &= ~GREEN; // Turn off green LED
}
displayCharacter();
}
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!