Question: I have wrote a code, but it isn't working. Could someone please help me Part I Blinking the cursor on the LCD The four 4-line
I have wrote a code, but it isn't working. Could someone please help me
Part I Blinking the cursor on the LCD
- The four 4-line dot matrix LCD is a component in your lab kit.
- Create a new CCS project and type in the code related to the sequence of operations listed in the flowcharts. Also, create functions as listed above and use them in your code as required.
- Use the SysTick timer peripheral to generate the required delays in milliseconds and microseconds. Delays play an important part in the steps involved in initializing the LCD module and writing the data/instructions to the LCD.
- If you initialized the LCD correctly, you will observe that the LCD cursor is blinking at the HOME position after downloading your program onto the MSP432 Launchpad board.
#include "msp.h" //PROTORYPES void SysTick_init(void); void delay_ms(uint8_t ms); void delay_micro(uint8_t microsecond); void pulseEnablePin(void); void pushNibble(uint8_t nibble); void pushByte(uint8_t byte); void commandWrite(uint8_t command); void LCD_init(void);
void main(void) { WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer LCD_init(); SysTick_init(); } /* ***| void SysTick_init(void) | ***************************************** * Brief: Initialization of the systic timer * param: * return: *************************************************************/ void SysTick_init(void){ SysTick -> CTRL = 0; //disable systick during step SysTick -> LOAD = 0x00FFFFFF; //max reload value SysTick -> VAL = 0; // any write to current clears it SysTick -> CTRL = 0x00000005; // enable systick } /* ***| void delay_micro(unsigned microsec) | ***************************************** * Brief: SysTick timer generated delay in microseconds * param: * return: *************************************************************/ void delay_micro(uint8_t microsecond){ SysTick -> LOAD = ((microsecond*3) -1); //delay * 3 SysTick -> VAL = 0; // clears counter while((SysTick -> CTRL & 0x00010000) == 0); } /* ***| void delay_ms(uint8_t ms) | ***************************************** * Brief: SysTick timer generated delay in milliseconds * param: * return: *************************************************************/ void delay_ms(uint8_t ms){ SysTick -> LOAD = ((ms * 3000)-1); //delay * 3000 SysTick -> VAL = 0; // clears counter while((SysTick -> CTRL & 0x00010000) == 0); } /* ***| void pulseEnablePin(void) | ***************************************** * Brief: This function will sequence the Enable (E) pin * param: * return: *************************************************************/ void pulseEnablePin(void){ P4OUT &= ~BIT2; // make sure pulse starts out at 0V. E pin is OFF delay_micro(10); P4OUT |= BIT2; // E pin is ON delay_micro(10); P4OUT &= ~BIT2; // E pin is OFF delay_micro(10); } /* ***| void pushNibble(uint8_t nibble) | ***************************************** * Brief: This function pushes 1 nibble onto the data * pins and pulses the Enable pin * param: * return: *************************************************************/ void pushNibble(uint8_t nibble){ P4OUT &= ~0xF0; //clears port 4 pin 4-7 P4OUT |= (nibble & 0x0F) << 4; // P4.4-P4.7 wired to D4-D7 pulseEnablePin(); // calls out function } /* ***| void pushByte(uint8_t byte) | ***************************************** * Brief: This function first pushes the most significant 4 bits of the * byte onto the data pins by calling the pushNibble function * Next, it pushes the least significant 4 bits onto the data pins * by calling the pushNibble function * param: * return: *************************************************************/ void pushByte(uint8_t byte){ uint8_t nibble; nibble= (byte & 0xF0) >> 4; pushNibble(nibble); nibble = byte & 0x0f; pushNibble(nibble); delay_micro(100); } /* ***| void commandWrite(uint8_t command) | ***************************************** * Brief: Writing one byte of command by calling the pushByte function * with the command parameter * param: * return: *************************************************************/ void commandWrite(uint8_t command){ P4OUT &= ~BIT1; //setting P4.1 as 0 delay_micro(100); pushByte(command); } /* ***| void LCD_init(void) | ***************************************** * Brief: Initialization of the Liquid Crystal Display * param: * return: *************************************************************/ void LCD_init(void){ P4SEL0 = 0x00; //Clears port 4 P4SEL1 = 0x00; P4DIR |= BIT1; //Set P4.1 as an OUTPUT for RS P4DIR |= BIT2; //Set P4.2 as an OUTPUT for E P4DIR |= (BIT4|BIT5|BIT6|BIT7); //Set P4.4-P4.7 as OUTPUT P4REN |= 0xF0; //Enables Pull Resistor for pin 4-7 P4OUT |= 0xF0; //RESETING SEQUENCE commandWrite(3); delay_ms(100); commandWrite(3); delay_micro(200); commandWrite(3); delay_ms(100); //SETTING 4-BIT MODE commandWrite(2); delay_micro(100); commandWrite(2); delay_micro(100); //2LINE 5X7 FORMAT commandWrite(0x38); delay_micro(100); //display ON Cursor ON commandWrite(0x0E); delay_micro(100); //CLEAR DISPLAY commandWrite(0x01); delay_micro(100); //INCREMENTS CURSOR commandWrite(0x80); delay_micro(10);
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
