adjusted lcd.c to match this board
This commit is contained in:
		
							
								
								
									
										37
									
								
								lcd.c
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								lcd.c
									
									
									
									
									
								
							@@ -16,18 +16,31 @@
 | 
				
			|||||||
#include "timer.h"
 | 
					#include "timer.h"
 | 
				
			||||||
#include "lcd.h"
 | 
					#include "lcd.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//#define WAIT_250_ns()       _delay_us(1)
 | 
				
			||||||
 | 
					#if (F_CPU <= 4000000UL)
 | 
				
			||||||
#define WAIT_250_ns()       _NOP()
 | 
					#define WAIT_250_ns()       _NOP()
 | 
				
			||||||
 | 
					#elif (F_CPU <= 8000000UL)
 | 
				
			||||||
 | 
					#define WAIT_250_ns()       _NOP();_NOP()
 | 
				
			||||||
 | 
					#elif (F_CPU <= 12000000UL)
 | 
				
			||||||
 | 
					#define WAIT_250_ns()       _NOP();_NOP();_NOP()
 | 
				
			||||||
 | 
					#elif (F_CPU <= 16000000UL)
 | 
				
			||||||
 | 
					#define WAIT_250_ns()       _NOP();_NOP();_NOP();_NOP()
 | 
				
			||||||
 | 
					#elif (F_CPU <= 20000000UL)
 | 
				
			||||||
 | 
					#define WAIT_250_ns()       _NOP();_NOP();_NOP();_NOP();_NOP()
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#include <util/delay.h>
 | 
				
			||||||
 | 
					#define WAIT_250_ns()       _delay_us(1)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define LCD_DATA_MODE()     (PORTC |=  (1<<PC4))
 | 
					#define LCD_DATA_MODE()     (PORTD |=  (1<<PD6))
 | 
				
			||||||
#define LCD_CMD_MODE()      (PORTC &= ~(1<<PC4))
 | 
					#define LCD_CMD_MODE()      (PORTD &= ~(1<<PD4))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define LCD_SET_ENABLE()    (PORTC |=  (1<<PC5))
 | 
					#define LCD_SET_ENABLE()    (PORTD |=  (1<<PD5))
 | 
				
			||||||
#define LCD_RESET_ENABLE()  (PORTC &= ~(1<<PC5))
 | 
					#define LCD_RESET_ENABLE()  (PORTD &= ~(1<<PD5))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// !!!!!!!
 | 
					// !!!!!!!
 | 
				
			||||||
#define LCD_SET_READ()      DDRC &= ~(0x0f);PORTC &= ~(0x0f);PORTB |= (1<<PB0)
 | 
					#define LCD_SET_READ()      DDRA &= ~(0x0f);PORTA &= ~(0x0f);PORTD |= (1<<PD7)
 | 
				
			||||||
#define LCD_SET_WRITE()     PORTB &= ~(1<<PB0);DDRC |= 0x0f
 | 
					#define LCD_SET_WRITE()     PORTD &= ~(1<<PD7);DDRA |= 0x0f
 | 
				
			||||||
#define LCD_BUSY_FLAG       (0x80)
 | 
					 | 
				
			||||||
// !!!!!!!
 | 
					// !!!!!!!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -45,7 +58,7 @@ static inline uint8_t lcd_read_byte(uint8_t RS)
 | 
				
			|||||||
  
 | 
					  
 | 
				
			||||||
  LCD_SET_ENABLE();
 | 
					  LCD_SET_ENABLE();
 | 
				
			||||||
  WAIT_250_ns();
 | 
					  WAIT_250_ns();
 | 
				
			||||||
  byte = (PINC<<4);
 | 
					  byte = (PINA<<4);
 | 
				
			||||||
  LCD_RESET_ENABLE();
 | 
					  LCD_RESET_ENABLE();
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  WAIT_250_ns();
 | 
					  WAIT_250_ns();
 | 
				
			||||||
@@ -53,7 +66,7 @@ static inline uint8_t lcd_read_byte(uint8_t RS)
 | 
				
			|||||||
  
 | 
					  
 | 
				
			||||||
  LCD_SET_ENABLE();
 | 
					  LCD_SET_ENABLE();
 | 
				
			||||||
  WAIT_250_ns();
 | 
					  WAIT_250_ns();
 | 
				
			||||||
  byte |= PINC & 0x0f;
 | 
					  byte |= PINA & 0x0f;
 | 
				
			||||||
  LCD_RESET_ENABLE();
 | 
					  LCD_RESET_ENABLE();
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  return byte;  
 | 
					  return byte;  
 | 
				
			||||||
@@ -66,7 +79,7 @@ static inline void lcd_wait_while_busy(void)
 | 
				
			|||||||
  uint8_t byte;
 | 
					  uint8_t byte;
 | 
				
			||||||
  do {
 | 
					  do {
 | 
				
			||||||
    byte = lcd_read_byte(0);
 | 
					    byte = lcd_read_byte(0);
 | 
				
			||||||
  } while (byte & LCD_BUSY_FLAG);
 | 
					  } while (byte & 0x80);
 | 
				
			||||||
  return;
 | 
					  return;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -74,7 +87,7 @@ static inline void lcd_wait_while_busy(void)
 | 
				
			|||||||
static inline void send_nibble(uint8_t nibble)
 | 
					static inline void send_nibble(uint8_t nibble)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  LCD_SET_WRITE();
 | 
					  LCD_SET_WRITE();
 | 
				
			||||||
  PORTC = (PORTC & 0xf0) | (0x0f & nibble);
 | 
					  PORTA = (PORTA & 0xf0) | (0x0f & nibble);
 | 
				
			||||||
  LCD_SET_ENABLE();
 | 
					  LCD_SET_ENABLE();
 | 
				
			||||||
  WAIT_250_ns();
 | 
					  WAIT_250_ns();
 | 
				
			||||||
  LCD_RESET_ENABLE();
 | 
					  LCD_RESET_ENABLE();
 | 
				
			||||||
@@ -136,7 +149,7 @@ void lcd_cursor(uint8_t blink)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void lcd_init(void)
 | 
					void lcd_init(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  /* Initialize both ATmega and Dsiplay
 | 
					  /* Initialize both ATmega and Display
 | 
				
			||||||
   * After return from this function,
 | 
					   * After return from this function,
 | 
				
			||||||
   * display we be set to 4-bit data mode
 | 
					   * display we be set to 4-bit data mode
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user