Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * lcd_funcs.c
- *
- * Created on: Apr 9, 2018
- * Author: Josh
- */
- #include "msp.h"
- #include "lcd_funcs.h"
- #include "delay.h"
- void LCD_INIT(void) {
- P3->DIR |= (BIT5 | BIT6 | BIT7);
- P4->DIR = 0xFF;
- P3->OUT = 0x00;
- P4->OUT = 0x00;
- //wait for the LCD to boot up
- delay_ms(400, CURRENT_FREQ);
- LCD_CMND(FN_SET);
- delay_ms(100, CURRENT_FREQ);
- LCD_CMND(SET_ENTRY_MODE);
- delay_ms(100, CURRENT_FREQ);
- LCD_CMND(DISP_ON);
- delay_ms(100, CURRENT_FREQ);
- clear_LCD();
- home_LCD();
- }
- void LCD_CMND(unsigned char cmnd) {
- P3->OUT &= ~(BIT5 + BIT6 + BIT7);
- P4->OUT = cmnd;
- //write first nybble
- P3->OUT |= EN;
- delay_us(500, CURRENT_FREQ);
- P3->OUT &= ~(EN);
- //shift left 4
- cmnd = cmnd << 4;
- //write second nybble
- P4->OUT = cmnd;
- P3->OUT |= EN;
- delay_us(500, CURRENT_FREQ);
- P3->OUT &= ~(EN);
- P4->OUT = 0x00;
- }
- void clear_LCD(void) {
- LCD_CMND(CLEAR_DISP);
- delay_ms(100, CURRENT_FREQ);
- }
- void home_LCD(void) {
- LCD_CMND(HOME_CMND);
- delay_ms(100, CURRENT_FREQ);
- }
- //write a character to the screen at address addr with ascii value val
- void write_char_LCD(unsigned char addr, unsigned char val) {
- addr = addr | 0x80;
- LCD_CMND(addr);
- delay_ms(50, CURRENT_FREQ);
- P3->OUT &= ~(BIT5 + BIT6 + BIT7);
- //write first nybble
- P4->OUT = val;
- P3->OUT |= (EN | RS);
- delay_us(100, CURRENT_FREQ);
- P3->OUT &= ~(EN);
- //shift left 4
- val = val << 4;
- //write second nybble
- P4->OUT = val;
- P3->OUT |= (EN);
- delay_us(100, CURRENT_FREQ);
- P3->OUT &= ~(EN);
- delay_us(100, CURRENT_FREQ);
- P3->OUT &= ~(RS);
- P4->OUT = 0x00;
- delay_us(100, CURRENT_FREQ);
- }
- void write_string(unsigned char* str,unsigned char addr){
- while (*str != '\0'){
- write_char_LCD(addr, *str);
- str++;
- addr++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement