BlinkenArea - GitList
Repositories
Blog
Wiki
mips_sys
Code
Commits
Branches
Tags
Search
Tree:
df6d296
Branches
Tags
master
mips_sys
fw
lcd.c
implemented LCD peripheral
Stefan Schuermans
commited
df6d296
at 2012-02-12 15:31:45
lcd.c
Blame
History
Raw
#include "cyc_cnt.h" #include "lcd.h" /** * @brief set data to LCD * @param[in] data data to LCD */ void lcd_set_data(unsigned char data) { volatile unsigned char *p_lcd_d = (volatile unsigned char *)0x80000100; *p_lcd_d = data; } /** * @brief set enable signal to LCD * @param[in] state state for enable signal (0 or 1) */ void lcd_set_e(unsigned char state) { volatile unsigned char *p_lcd_e = (volatile unsigned char *)0x80000101; *p_lcd_e = 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) { volatile unsigned char *p_lcd_rs = (volatile unsigned char *)0x80000102; *p_lcd_rs = 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; *p_lcd_rw = 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, '!'); }