#include #include /* LCD with 4 bit mode for an ATMEGA32P processor _ LCD _ _ ATMEGA32P (arduino)_ 1 VSS -> GND 2 VDD -> +5V 3 V0 -> Potentiometer 4 RS -> PortB4 (Pin 12 arduino) 5 RW -> GND 6 E -> PortB3 (Pin 11 arduino) (7 - 10) -> ... 11 D4 -> PortD5 (Pin 5 arduino) 12 D5 -> PortD4 (Pin 4 arduino) 13 D6 -> PortD3 (Pin 3 arduino) 14 D7 -> PortD2 (Pin 2 arduino) 15 A -> +5v with resistor 16 K -> GND */ // LCD display size #define LCD_START_LINE1 0x00 #define LCD_START_LINE2 0x40 // LCD ports/pins/ddr #define LCD_RS_PORT PORTB #define LCD_RS_PIN 4 #define LCD_RS_DDR DDRB #define LCD_E_PORT PORTB #define LCD_E_PIN 3 #define LCD_E_DDR DDRB #define LCD_D4_PORT PORTD #define LCD_D4_PIN 5 #define LCD_D4_DDR DDRD #define LCD_D5_PORT PORTD #define LCD_D5_PIN 4 #define LCD_D5_DDR DDRD #define LCD_D6_PORT PORTD #define LCD_D6_PIN 3 #define LCD_D6_DDR DDRD #define LCD_D7_PORT PORTD #define LCD_D7_PIN 2 #define LCD_D7_DDR DDRD //LCD instructions (see LCD-1602A datasheet) #define LCD_CLEAR 0b00000001 #define LCD_HOME 0b00000010 #define LCD_ENTRY_MODE 0b00000110 #define LCD_DISPLAY_ON 0b00001100 #define LCD_DISPLAY_OFF 0b00001000 #define LCD_CURSOR_SET 0b10000000 #define LCD_FUNCTION_SET_8bit 0b00110000 #define LCD_FUNCTION_SET_4bit 0b00101000 // Functions void dinit(void); void lcd_init(void); void lcd_write(uint8_t); void lcd_cmd(uint8_t); void lcd_char(uint8_t); void lcd_string(uint8_t *);