Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- LiquidCrystal Library - Hello World
- Demonstrates the use a 16x2 LCD display. The LiquidCrystal
- library works with all LCD displays that are compatible with the
- Hitachi HD44780 driver. There are many of them out there, and you
- can usually tell them by the 16-pin interface.
- This sketch prints "Hello World!" to the LCD
- and shows the time.
- The circuit:
- =================================
- LCD pin Connect to
- ---------------------------------
- 01 - GND GND, pot
- 02 - VCC +5V, pot
- 03 - Contrast Pot wiper
- 04 - RS Pin8 (P2.0)
- 05 - R/W GND
- 06 - EN Pin9 (P2.1)
- 07 - DB0 GND
- 08 - DB1 GND
- 09 - DB2 GND
- 10 - DB3 GND
- 11 - DB4 Pin10 (P2.2)
- 12 - DB5 Pin11 (P2.3)
- 13 - DB6 Pin12 (P2.4)
- 14 - DB7 Pin13 (P2.5)
- 15 - BL+ +5V
- 16 - BL- GND
- =================================
- Library originally added 18 Apr 2008
- by David A. Mellis
- library modified 5 Jul 2009
- by Limor Fried (http://www.ladyada.net)
- example added 9 Jul 2009
- by Tom Igoe
- modified 22 Nov 2010
- by Tom Igoe
- This example code is in the public domain.
- http://www.arduino.cc/en/Tutorial/LiquidCrystal
- */
- // include the library code:
- #include <LiquidCrystal.h>
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(P2_0, P2_1, P2_2, P2_3, P2_4, P2_5);
- void setup() {
- // set up the LCD's number of columns and rows:
- lcd.begin(16, 2);
- // Print a message to the LCD.
- lcd.print("hello, world!");
- }
- void loop() {
- // set the cursor to column 0, line 1
- // (note: line 1 is the second row, since counting begins with 0):
- lcd.setCursor(0, 1);
- // print the number of seconds since reset:
- lcd.print(millis()/1000);
- }
- **********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
- This is where the .c file ends. This next code is for the .h file ************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
- #ifndef LiquidCrystal_h
- #define LiquidCrystal_h
- #include <inttypes.h>
- #include "Print.h"
- // commands
- #define LCD_CLEARDISPLAY 0x01
- #define LCD_RETURNHOME 0x02
- #define LCD_ENTRYMODESET 0x04
- #define LCD_DISPLAYCONTROL 0x08
- #define LCD_CURSORSHIFT 0x10
- #define LCD_FUNCTIONSET 0x20
- #define LCD_SETCGRAMADDR 0x40
- #define LCD_SETDDRAMADDR 0x80
- // flags for display entry mode
- #define LCD_ENTRYRIGHT 0x00
- #define LCD_ENTRYLEFT 0x02
- #define LCD_ENTRYSHIFTINCREMENT 0x01
- #define LCD_ENTRYSHIFTDECREMENT 0x00
- // flags for display on/off control
- #define LCD_DISPLAYON 0x04
- #define LCD_DISPLAYOFF 0x00
- #define LCD_CURSORON 0x02
- #define LCD_CURSOROFF 0x00
- #define LCD_BLINKON 0x01
- #define LCD_BLINKOFF 0x00
- // flags for display/cursor shift
- #define LCD_DISPLAYMOVE 0x08
- #define LCD_CURSORMOVE 0x00
- #define LCD_MOVERIGHT 0x04
- #define LCD_MOVELEFT 0x00
- // flags for function set
- #define LCD_8BITMODE 0x10
- #define LCD_4BITMODE 0x00
- #define LCD_2LINE 0x08
- #define LCD_1LINE 0x00
- #define LCD_5x10DOTS 0x04
- #define LCD_5x8DOTS 0x00
- class LiquidCrystal : public Print {
- public:
- LiquidCrystal(uint8_t rs, uint8_t enable,
- uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
- uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
- LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
- uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
- uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
- LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
- uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
- LiquidCrystal(uint8_t rs, uint8_t enable,
- uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
- void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
- uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
- uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
- void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
- void clear();
- void home();
- void noDisplay();
- void display();
- void noBlink();
- void blink();
- void noCursor();
- void cursor();
- void scrollDisplayLeft();
- void scrollDisplayRight();
- void leftToRight();
- void rightToLeft();
- void autoscroll();
- void noAutoscroll();
- void createChar(uint8_t, uint8_t[]);
- void setCursor(uint8_t, uint8_t);
- virtual void write(uint8_t);
- void command(uint8_t);
- private:
- void send(uint8_t, uint8_t);
- void write4bits(uint8_t);
- void write8bits(uint8_t);
- void pulseEnable();
- uint8_t _rs_pin; // LOW: command. HIGH: character.
- uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD.
- uint8_t _enable_pin; // activated by a HIGH pulse.
- uint8_t _data_pins[8];
- uint8_t _displayfunction;
- uint8_t _displaycontrol;
- uint8_t _displaymode;
- uint8_t _initialized;
- uint8_t _numlines,_currline;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement