BlinkenArea - GitList
Repositories
Blog
Wiki
mips_sys
Code
Commits
Branches
Tags
Search
Tree:
21e3f0f
Branches
Tags
master
mips_sys
fw
lcd.c
converted code to use constants in data memory
Stefan Schuermans
commited
21e3f0f
at 2012-02-12 18:24:53
lcd.c
Blame
History
Raw
#include "cyc_cnt.h" #include "lcd.h" static volatile unsigned char *const lcd_ptr = (volatile unsigned char *)0x80000100; /** * @brief set data to LCD * @param[in] data data to LCD */ void lcd_set_data(unsigned char data) { lcd_ptr[0] = data; } /** * @brief set enable signal to LCD * @param[in] state state for enable signal (0 or 1) */ void lcd_set_e(unsigned char state) { lcd_ptr[1] = state; } /** * @brief set register select signal to LCD * @param[in] state state for register select signal (0 or 1) */ void lcd_set_rs(unsigned char state) { lcd_ptr[2] = state; } /** * @brief set read/write signal to LCD * @param[in] state state for read/write signal (0 or 1) */ void lcd_set_rw(unsigned char state) { volatile unsigned char *p_lcd_rw = (volatile unsigned char *)0x80000103; lcd_ptr[3] = state; } /** set LCD to 4 bit mode */ void lcd_set4bit(void) { lcd_set_data(0x0F); lcd_set_e(0); lcd_set_rs(0); lcd_set_rw(0); cyc_cnt_delay_ms(15); lcd_set_data(0x3F); lcd_set_e(1); cyc_cnt_delay(12); lcd_set_e(0); cyc_cnt_delay_us(4100); lcd_set_e(1); cyc_cnt_delay(12); lcd_set_e(0); cyc_cnt_delay_us(100); lcd_set_e(1); cyc_cnt_delay(12); lcd_set_e(0); cyc_cnt_delay_us(40); lcd_set_data(0x2F); lcd_set_e(1); cyc_cnt_delay(12); lcd_set_e(0); cyc_cnt_delay_us(40); } /** * @brief output a byte to LCD * @param[in] data if the byte is a data byte (command otherwise) * @param[in] byte byte to write */ void lcd_byte(unsigned char data, unsigned char byte) { lcd_set_e(0); lcd_set_rs(data ? 1: 0); lcd_set_rw(0); lcd_set_data(byte | 0x0F); lcd_set_e(1); cyc_cnt_delay(12); lcd_set_e(0); cyc_cnt_delay_us(1); lcd_set_data(byte << 4 | 0x0F); lcd_set_e(1); cyc_cnt_delay(12); lcd_set_e(0); cyc_cnt_delay_us(40); } /** initialize LCD */ void lcd_init(void) { lcd_set4bit(); lcd_byte(0, 0x28); lcd_byte(0, 0x06); lcd_byte(0, 0x0C); lcd_byte(0, 0x01); cyc_cnt_delay_us(1640); lcd_byte(1, 'H'); lcd_byte(1, 'e'); lcd_byte(1, 'l'); lcd_byte(1, 'l'); lcd_byte(1, 'o'); lcd_byte(1, ' '); lcd_byte(1, 'W'); lcd_byte(1, 'o'); lcd_byte(1, 'r'); lcd_byte(1, 'l'); lcd_byte(1, 'd'); lcd_byte(1, '!'); }