Advertisement
Guest User

Untitled

a guest
Dec 27th, 2012
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. /*
  2. LiquidCrystal Library - Hello World
  3.  
  4. Demonstrates the use a 16x2 LCD display. The LiquidCrystal
  5. library works with all LCD displays that are compatible with the
  6. Hitachi HD44780 driver. There are many of them out there, and you
  7. can usually tell them by the 16-pin interface.
  8.  
  9. This sketch prints "Hello World!" to the LCD
  10. and shows the time.
  11.  
  12. The circuit:
  13. =================================
  14. LCD pin Connect to
  15. ---------------------------------
  16. 01 - GND GND, pot
  17. 02 - VCC +5V, pot
  18. 03 - Contrast Pot wiper
  19. 04 - RS Pin8 (P2.0)
  20. 05 - R/W GND
  21. 06 - EN Pin9 (P2.1)
  22. 07 - DB0 GND
  23. 08 - DB1 GND
  24. 09 - DB2 GND
  25. 10 - DB3 GND
  26. 11 - DB4 Pin10 (P2.2)
  27. 12 - DB5 Pin11 (P2.3)
  28. 13 - DB6 Pin12 (P2.4)
  29. 14 - DB7 Pin13 (P2.5)
  30. 15 - BL+ +5V
  31. 16 - BL- GND
  32. =================================
  33.  
  34. Library originally added 18 Apr 2008
  35. by David A. Mellis
  36. library modified 5 Jul 2009
  37. by Limor Fried (http://www.ladyada.net)
  38. example added 9 Jul 2009
  39. by Tom Igoe
  40. modified 22 Nov 2010
  41. by Tom Igoe
  42.  
  43. This example code is in the public domain.
  44.  
  45. http://www.arduino.cc/en/Tutorial/LiquidCrystal
  46. */
  47.  
  48. // include the library code:
  49. #include <LiquidCrystal.h>
  50.  
  51. // initialize the library with the numbers of the interface pins
  52. LiquidCrystal lcd(P2_0, P2_1, P2_2, P2_3, P2_4, P2_5);
  53.  
  54. void setup() {
  55. // set up the LCD's number of columns and rows:
  56. lcd.begin(16, 2);
  57. // Print a message to the LCD.
  58. lcd.print("hello, world!");
  59. }
  60.  
  61. void loop() {
  62. // set the cursor to column 0, line 1
  63. // (note: line 1 is the second row, since counting begins with 0):
  64. lcd.setCursor(0, 1);
  65. // print the number of seconds since reset:
  66. lcd.print(millis()/1000);
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. **********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
  79.  
  80.  
  81. This is where the .c file ends. This next code is for the .h file ************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. #ifndef LiquidCrystal_h
  89. #define LiquidCrystal_h
  90.  
  91. #include <inttypes.h>
  92. #include "Print.h"
  93.  
  94. // commands
  95. #define LCD_CLEARDISPLAY 0x01
  96. #define LCD_RETURNHOME 0x02
  97. #define LCD_ENTRYMODESET 0x04
  98. #define LCD_DISPLAYCONTROL 0x08
  99. #define LCD_CURSORSHIFT 0x10
  100. #define LCD_FUNCTIONSET 0x20
  101. #define LCD_SETCGRAMADDR 0x40
  102. #define LCD_SETDDRAMADDR 0x80
  103.  
  104. // flags for display entry mode
  105. #define LCD_ENTRYRIGHT 0x00
  106. #define LCD_ENTRYLEFT 0x02
  107. #define LCD_ENTRYSHIFTINCREMENT 0x01
  108. #define LCD_ENTRYSHIFTDECREMENT 0x00
  109.  
  110. // flags for display on/off control
  111. #define LCD_DISPLAYON 0x04
  112. #define LCD_DISPLAYOFF 0x00
  113. #define LCD_CURSORON 0x02
  114. #define LCD_CURSOROFF 0x00
  115. #define LCD_BLINKON 0x01
  116. #define LCD_BLINKOFF 0x00
  117.  
  118. // flags for display/cursor shift
  119. #define LCD_DISPLAYMOVE 0x08
  120. #define LCD_CURSORMOVE 0x00
  121. #define LCD_MOVERIGHT 0x04
  122. #define LCD_MOVELEFT 0x00
  123.  
  124. // flags for function set
  125. #define LCD_8BITMODE 0x10
  126. #define LCD_4BITMODE 0x00
  127. #define LCD_2LINE 0x08
  128. #define LCD_1LINE 0x00
  129. #define LCD_5x10DOTS 0x04
  130. #define LCD_5x8DOTS 0x00
  131.  
  132. class LiquidCrystal : public Print {
  133. public:
  134. LiquidCrystal(uint8_t rs, uint8_t enable,
  135. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  136. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
  137. LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
  138. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  139. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
  140. LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
  141. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
  142. LiquidCrystal(uint8_t rs, uint8_t enable,
  143. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
  144.  
  145. void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
  146. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  147. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
  148.  
  149. void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
  150.  
  151. void clear();
  152. void home();
  153.  
  154. void noDisplay();
  155. void display();
  156. void noBlink();
  157. void blink();
  158. void noCursor();
  159. void cursor();
  160. void scrollDisplayLeft();
  161. void scrollDisplayRight();
  162. void leftToRight();
  163. void rightToLeft();
  164. void autoscroll();
  165. void noAutoscroll();
  166.  
  167. void createChar(uint8_t, uint8_t[]);
  168. void setCursor(uint8_t, uint8_t);
  169. virtual void write(uint8_t);
  170. void command(uint8_t);
  171. private:
  172. void send(uint8_t, uint8_t);
  173. void write4bits(uint8_t);
  174. void write8bits(uint8_t);
  175. void pulseEnable();
  176.  
  177. uint8_t _rs_pin; // LOW: command. HIGH: character.
  178. uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD.
  179. uint8_t _enable_pin; // activated by a HIGH pulse.
  180. uint8_t _data_pins[8];
  181.  
  182. uint8_t _displayfunction;
  183. uint8_t _displaycontrol;
  184. uint8_t _displaymode;
  185.  
  186. uint8_t _initialized;
  187.  
  188. uint8_t _numlines,_currline;
  189. };
  190.  
  191. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement