Operácie

AVR lcd.h

Zo stránky SensorWiki

Verzia z 07:57, 28. október 2011, ktorú vytvoril Balogh (diskusia | príspevky)

// HD44780 LCD controller command set (do not modify these)

  1. include <avr/io.h>
  2. include <util/delay.h>


//#define LCD_DELAY asm volatile ("nop")

  1. define LCD_DELAY _delay_us(5)
  2. define SETBIT(VAR,BIT) (VAR|=(1<<BIT))
  3. define CLEARBIT(VAR,BIT) (VAR&=~(1<<BIT))
  4. define CHECKBIT(VAR,BIT) (VAR&(1<<BIT))
  1. define LCD_CLR 0 // DB0: clear display
  2. define LCD_HOME 1 // DB1: return to home position
  3. define LCD_ENTRY_MODE 2 // DB2: set entry mode
  4. define LCD_ENTRY_INC 1 // DB1: increment
  5. define LCD_ENTRY_SHIFT 0 // DB2: shift
  6. define LCD_ON_CTRL 3 // DB3: turn lcd/cursor on
  7. define LCD_ON_DISPLAY 2 // DB2: turn display on
  8. define LCD_ON_CURSOR 1 // DB1: turn cursor on
  9. define LCD_ON_BLINK 0 // DB0: blinking cursor
  10. define LCD_MOVE 4 // DB4: move cursor/display
  11. define LCD_MOVE_DISP 3 // DB3: move display (0-> move cursor)
  12. define LCD_MOVE_RIGHT 2 // DB2: move right (0-> left)
  13. define LCD_FUNCTION 5 // DB5: function set
  14. define LCD_FUNCTION_8BIT 4 // DB4: set 8BIT mode (0->4BIT mode)
  15. define LCD_FUNCTION_2LINES 3 // DB3: two lines (0->one line)
  16. define LCD_FUNCTION_10DOTS 2 // DB2: 5x10 font (0->5x7 font)
  17. define LCD_CGRAM 6 // DB6: set CG RAM address
  18. define LCD_DDRAM 7 // DB7: set DD RAM address

// ________________________________________________________

  1. define LCD_BUSY 7 // DB7: LCD is busy

// port and pins you will use for control lines

  1. define LCD_CTRL_PORT PORTD
  2. define LCD_CTRL_DDR DDRD
  3. define LCD_CTRL_RS 3
  4. define LCD_CTRL_RW 2
  5. define LCD_CTRL_E 1


// port you will use for data lines

  1. define LCD_DATA_PORT PORTD
  2. define LCD_DATA_PIN PIND
  3. define LCD_DATA_DDR DDRD
  4. define LCD_DATA_D7 7
  5. define LCD_DATA_D6 6
  6. define LCD_DATA_D5 5
  7. define LCD_DATA_D4 4

// define pin which control backlight

  1. define LCD_CTRL_LIGHT 4

// access mode you will use (default is 8bit unless 4bit is selected) #define LCD_DATA_4BIT

// LCD display geometry // change these definitions to adapt settings

  1. define LCD_LINES 2 // visible lines
  2. define LCD_LINE_LENGTH 16 // line length (in characters)

// cursor position to DDRAM mapping

  1. define LCD_LINE0_DDRAMADDR 0x00
  2. define LCD_LINE1_DDRAMADDR 0x40

// **************************************************

extern unsigned char lcdBusy(void); // waits until LCD is not busy extern void lcdControlWrite(unsigned char c_data); // writes a control command to the LCD extern unsigned char lcdControlRead(void); // read the control status from the LCD extern void lcdDataWrite(unsigned char w_data) ; // writes a data byte to the LCD screen at the current position extern unsigned char lcdDataRead(void); // reads the data byte on the LCD screen at the current position extern void lcdInit4(void);

extern unsigned char ReadButtons(); extern void lcdStringWrite(char* String);