merge default into patterns
This commit is contained in:
		
							
								
								
									
										72
									
								
								lcd.c
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								lcd.c
									
									
									
									
									
								
							@@ -50,6 +50,10 @@
 | 
				
			|||||||
// !!!!!!!
 | 
					// !!!!!!!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define T_TIMEOUT (10)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static uint8_t lcd_initialized;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline uint8_t lcd_read_byte(uint8_t RS)
 | 
					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;
 | 
					  uint8_t byte;
 | 
				
			||||||
 | 
					  uint32_t t_enter = timer_get();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  do {
 | 
					  do {
 | 
				
			||||||
 | 
						if (timer_get() > t_enter + T_TIMEOUT) {
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
    byte = lcd_read_byte(0);
 | 
					    byte = lcd_read_byte(0);
 | 
				
			||||||
  } while (byte & 0x80);
 | 
					  } 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 byte The byte to send to the LCD
 | 
				
			||||||
  * \param RS specifies whether byte sent is data (RS==1) or command (RS==0)
 | 
					  * \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 (lcd_wait_while_busy() ) {
 | 
				
			||||||
  if (RS)
 | 
						  if (RS)
 | 
				
			||||||
    LCD_DATA_MODE();
 | 
							  LCD_DATA_MODE();
 | 
				
			||||||
  else
 | 
						  else
 | 
				
			||||||
    LCD_CMD_MODE();
 | 
							  LCD_CMD_MODE();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  send_nibble(byte >> 4);
 | 
						  send_nibble(byte >> 4);
 | 
				
			||||||
  _NOP();
 | 
						  _NOP();
 | 
				
			||||||
  send_nibble(0x0f & byte);
 | 
						  send_nibble(0x0f & byte);
 | 
				
			||||||
 | 
						  return 1;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int lcd_get(void)
 | 
					int lcd_get(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  lcd_wait_while_busy();
 | 
						if ( lcd_wait_while_busy() ) {
 | 
				
			||||||
  return lcd_read_byte(1);
 | 
							return lcd_read_byte(1);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int lcd_put(char c)
 | 
					int lcd_put(char c)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  lcd_send_byte(c, 1);
 | 
						if (!lcd_initialized) {
 | 
				
			||||||
  return 0;
 | 
							return 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return lcd_send_byte(c, 1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void lcd_puts(char *s)
 | 
					void lcd_puts(char *s)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (!lcd_initialized) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
  while (*s) {
 | 
					  while (*s) {
 | 
				
			||||||
    //lcd_put(*s++);
 | 
					    //lcd_put(*s++);
 | 
				
			||||||
    lcd_send_byte(*s++, 1);
 | 
						  if (!lcd_send_byte(*s++, 1)) {
 | 
				
			||||||
 | 
							  return;
 | 
				
			||||||
 | 
						  }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  return;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void lcd_cursor(uint8_t blink)
 | 
					void lcd_cursor(uint8_t blink)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  if (blink) {
 | 
					  if (blink) {
 | 
				
			||||||
    // enable display with cursor + blinking
 | 
					    // enable display with cursor + blinking
 | 
				
			||||||
    lcd_send_byte(0x0f, 0);
 | 
						lcd_send_byte(0x0f, 0);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  else  {
 | 
					  else  {
 | 
				
			||||||
    // enable display, no cursor, no blinking
 | 
					    // enable display, no cursor, no blinking
 | 
				
			||||||
@@ -160,6 +182,8 @@ void lcd_init(void)
 | 
				
			|||||||
   * display we be set to 4-bit data mode
 | 
					   * display we be set to 4-bit data mode
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
						lcd_initialized = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // wait until LCD gets ready to accept instructions.
 | 
					  // wait until LCD gets ready to accept instructions.
 | 
				
			||||||
  timer_wait(50);
 | 
					  timer_wait(50);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -189,7 +213,11 @@ void lcd_init(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // set to 5 x 8 dots per character,
 | 
					  // set to 5 x 8 dots per character,
 | 
				
			||||||
  // 16 characters per line, 2 lines
 | 
					  // 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
 | 
					  // enable display, no cursor, no blinking
 | 
				
			||||||
  //lcd_send_byte(0x0c, 0);
 | 
					  //lcd_send_byte(0x0c, 0);
 | 
				
			||||||
@@ -204,6 +232,8 @@ void lcd_init(void)
 | 
				
			|||||||
  
 | 
					  
 | 
				
			||||||
  // clear dislay
 | 
					  // clear dislay
 | 
				
			||||||
  lcd_clear();
 | 
					  lcd_clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  lcd_initialized = 1;
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
  return;
 | 
					  return;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -215,6 +245,10 @@ void lcd_clear(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void lcd_locate(uint8_t row, uint8_t col)
 | 
					void lcd_locate(uint8_t row, uint8_t col)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (!lcd_initialized) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (row)
 | 
					  if (row)
 | 
				
			||||||
    col += 0x40;
 | 
					    col += 0x40;
 | 
				
			||||||
  lcd_send_byte(0x80 + col, 0);
 | 
					  lcd_send_byte(0x80 + col, 0);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user