merge default into patterns

This commit is contained in:
Stefan Rupp 2014-03-19 03:51:58 +01:00
commit d9b7a3c915

72
lcd.c
View File

@ -50,6 +50,10 @@
// !!!!!!!
#define T_TIMEOUT (10)
static uint8_t lcd_initialized;
static inline uint8_t lcd_read_byte(uint8_t RS)
{
@ -79,14 +83,19 @@ static inline uint8_t lcd_read_byte(uint8_t RS)
}
static inline void lcd_wait_while_busy(void)
static inline int8_t lcd_wait_while_busy(void)
{
uint8_t byte;
uint32_t t_enter = timer_get();
do {
if (timer_get() > t_enter + T_TIMEOUT) {
return 0;
}
byte = lcd_read_byte(0);
} while (byte & 0x80);
return;
return 1;
}
@ -105,46 +114,59 @@ static inline void send_nibble(uint8_t nibble)
* \param byte The byte to send to the LCD
* \param RS specifies whether byte sent is data (RS==1) or command (RS==0)
*/
static inline void lcd_send_byte(uint8_t byte, uint8_t RS)
static inline int8_t lcd_send_byte(uint8_t byte, uint8_t RS)
{
lcd_wait_while_busy();
if (RS)
LCD_DATA_MODE();
else
LCD_CMD_MODE();
if (lcd_wait_while_busy() ) {
if (RS)
LCD_DATA_MODE();
else
LCD_CMD_MODE();
send_nibble(byte >> 4);
_NOP();
send_nibble(0x0f & byte);
send_nibble(byte >> 4);
_NOP();
send_nibble(0x0f & byte);
return 1;
}
return 0;
}
int lcd_get(void)
{
lcd_wait_while_busy();
return lcd_read_byte(1);
if ( lcd_wait_while_busy() ) {
return lcd_read_byte(1);
}
return -1;
}
int lcd_put(char c)
{
lcd_send_byte(c, 1);
return 0;
if (!lcd_initialized) {
return 0;
}
return lcd_send_byte(c, 1);
}
void lcd_puts(char *s)
{
if (!lcd_initialized) {
return;
}
while (*s) {
//lcd_put(*s++);
lcd_send_byte(*s++, 1);
if (!lcd_send_byte(*s++, 1)) {
return;
}
}
return;
}
void lcd_cursor(uint8_t blink)
{
if (blink) {
// enable display with cursor + blinking
lcd_send_byte(0x0f, 0);
lcd_send_byte(0x0f, 0);
}
else {
// enable display, no cursor, no blinking
@ -160,6 +182,8 @@ void lcd_init(void)
* display we be set to 4-bit data mode
*/
lcd_initialized = 0;
// wait until LCD gets ready to accept instructions.
timer_wait(50);
@ -189,7 +213,11 @@ void lcd_init(void)
// set to 5 x 8 dots per character,
// 16 characters per line, 2 lines
lcd_send_byte(0x28, 0);
int success = lcd_send_byte(0x28, 0);
if ( !success ) {
return;
}
// enable display, no cursor, no blinking
//lcd_send_byte(0x0c, 0);
@ -205,6 +233,8 @@ void lcd_init(void)
// clear dislay
lcd_clear();
lcd_initialized = 1;
return;
}
@ -215,6 +245,10 @@ void lcd_clear(void)
void lcd_locate(uint8_t row, uint8_t col)
{
if (!lcd_initialized) {
return;
}
if (row)
col += 0x40;
lcd_send_byte(0x80 + col, 0);