BlinkenArea - GitList
Repositories
Blog
Wiki
mips_sys
Code
Commits
Branches
Tags
Search
Tree:
e5fcec6
Branches
Tags
master
mips_sys
fw
lcd.c
improve 200ms tick and task processing, get rid of UART output of received ethernet frames
Stefan Schuermans
commited
e5fcec6
at 2012-03-24 19:05:42
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) { 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(15 * CYC_CNT_MS); lcd_set_data(0x3F); lcd_set_e(1); cyc_cnt_delay(12); lcd_set_e(0); cyc_cnt_delay(4100 * CYC_CNT_US); lcd_set_e(1); cyc_cnt_delay(12); lcd_set_e(0); cyc_cnt_delay(100 * CYC_CNT_US); lcd_set_e(1); cyc_cnt_delay(12); lcd_set_e(0); cyc_cnt_delay(40 * CYC_CNT_US); lcd_set_data(0x2F); lcd_set_e(1); cyc_cnt_delay(12); lcd_set_e(0); cyc_cnt_delay(40 * CYC_CNT_US); } /** * @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(1 * CYC_CNT_US); lcd_set_data(byte << 4 | 0x0F); lcd_set_e(1); cyc_cnt_delay(12); lcd_set_e(0); cyc_cnt_delay(40 * CYC_CNT_US); } /** 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(1640 * CYC_CNT_US); } /** * @brief show character * @param[in] line number of line (0..1) * @param[in] pos position in line (0..15) * @param[in] chr character to set */ void lcd_chr(unsigned int line, unsigned int pos, char chr) { if (line > 1 || pos > 15) return; lcd_byte(0, 0x80 | line << 6 | pos); lcd_byte(1, chr); } /** * @brief show string * @param[in] line number of line (0..1) * @param[in] str string to show */ void lcd_str(unsigned int line, const char *str) { if (line > 1) return; lcd_byte(0, 0x80 | line << 6); unsigned int cnt; for (cnt = 0; cnt < 16 && str[cnt] != 0; ++cnt) lcd_byte(1, str[cnt]); for (; cnt < 16; ++cnt) lcd_byte(1, ' '); }