久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3157|回復: 1
打印 上一主題 下一主題
收起左側

1602 2004 IIC模塊Arduino測試程序資料

[復制鏈接]
跳轉到指定樓層
樓主
1602 IICC模塊



單片機源程序如下:
  1. //YWROBOT
  2. //last updated on 21/12/2011
  3. //Tim Starling Fix the reset bug (Thanks Tim)
  4. //Compatible with the Arduino IDE 1.0
  5. //Library version:1.1


  6. #include "LiquidCrystal_I2C.h"
  7. #include <inttypes.h>
  8. #if defined(ARDUINO) && ARDUINO >= 100

  9. #include "Arduino.h"

  10. #define printIIC(args)        Wire.write(args)
  11. inline size_t LiquidCrystal_I2C::write(uint8_t value) {
  12.         send(value, Rs);
  13.         return 0;
  14. }

  15. #else
  16. #include "WProgram.h"

  17. #define printIIC(args)        Wire.send(args)
  18. inline void LiquidCrystal_I2C::write(uint8_t value) {
  19.         send(value, Rs);
  20. }

  21. #endif
  22. #include "Wire.h"



  23. // When the display powers up, it is configured as follows:
  24. //
  25. // 1. Display clear
  26. // 2. Function set:
  27. //    DL = 1; 8-bit interface data
  28. //    N = 0; 1-line display
  29. //    F = 0; 5x8 dot character font
  30. // 3. Display on/off control:
  31. //    D = 0; Display off
  32. //    C = 0; Cursor off
  33. //    B = 0; Blinking off
  34. // 4. Entry mode set:
  35. //    I/D = 1; Increment by 1
  36. //    S = 0; No shift
  37. //
  38. // Note, however, that resetting the Arduino doesn't reset the LCD, so we
  39. // can't assume that its in that state when a sketch starts (and the
  40. // LiquidCrystal constructor is called).

  41. LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows)
  42. {
  43.   _Addr = lcd_Addr;
  44.   _cols = lcd_cols;
  45.   _rows = lcd_rows;
  46.   _backlightval = LCD_NOBACKLIGHT;
  47. }

  48. void LiquidCrystal_I2C::init(){
  49.         init_priv();
  50. }

  51. void LiquidCrystal_I2C::init_priv()
  52. {
  53.         Wire.begin();
  54.         _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
  55.         begin(_cols, _rows);  
  56. }

  57. void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
  58.         if (lines > 1) {
  59.                 _displayfunction |= LCD_2LINE;
  60.         }
  61.         _numlines = lines;

  62.         // for some 1 line displays you can select a 10 pixel high font
  63.         if ((dotsize != 0) && (lines == 1)) {
  64.                 _displayfunction |= LCD_5x10DOTS;
  65.         }

  66.         // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
  67.         // according to datasheet, we need at least 40ms after power rises above 2.7V
  68.         // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
  69.         delay(50);
  70.   
  71.         // Now we pull both RS and R/W low to begin commands
  72.         expanderWrite(_backlightval);        // reset expanderand turn backlight off (Bit 8 =1)
  73.         delay(1000);

  74.           //put the LCD into 4 bit mode
  75.         // this is according to the hitachi HD44780 datasheet
  76.         // figure 24, pg 46
  77.        
  78.           // we start in 8bit mode, try to set 4 bit mode
  79.    write4bits(0x03 << 4);
  80.    delayMicroseconds(4500); // wait min 4.1ms
  81.    
  82.    // second try
  83.    write4bits(0x03 << 4);
  84.    delayMicroseconds(4500); // wait min 4.1ms
  85.    
  86.    // third go!
  87.    write4bits(0x03 << 4);
  88.    delayMicroseconds(150);
  89.    
  90.    // finally, set to 4-bit interface
  91.    write4bits(0x02 << 4);


  92.         // set # lines, font size, etc.
  93.         command(LCD_FUNCTIONSET | _displayfunction);  
  94.        
  95.         // turn the display on with no cursor or blinking default
  96.         _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
  97.         display();
  98.        
  99.         // clear it off
  100.         clear();
  101.        
  102.         // Initialize to default text direction (for roman languages)
  103.         _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
  104.        
  105.         // set the entry mode
  106.         command(LCD_ENTRYMODESET | _displaymode);
  107.        
  108.         home();
  109.   
  110. }

  111. /********** high level commands, for the user! */
  112. void LiquidCrystal_I2C::clear(){
  113.         command(LCD_CLEARDISPLAY);// clear display, set cursor position to zero
  114.         delayMicroseconds(2000);  // this command takes a long time!
  115. }

  116. void LiquidCrystal_I2C::home(){
  117.         command(LCD_RETURNHOME);  // set cursor position to zero
  118.         delayMicroseconds(2000);  // this command takes a long time!
  119. }

  120. void LiquidCrystal_I2C::setCursor(uint8_t col, uint8_t row){
  121.         int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
  122.         if ( row > _numlines ) {
  123.                 row = _numlines-1;    // we count rows starting w/0
  124.         }
  125.         command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
  126. }

  127. // Turn the display on/off (quickly)
  128. void LiquidCrystal_I2C::noDisplay() {
  129.         _displaycontrol &= ~LCD_DISPLAYON;
  130.         command(LCD_DISPLAYCONTROL | _displaycontrol);
  131. }
  132. void LiquidCrystal_I2C::display() {
  133.         _displaycontrol |= LCD_DISPLAYON;
  134.         command(LCD_DISPLAYCONTROL | _displaycontrol);
  135. }

  136. // Turns the underline cursor on/off
  137. void LiquidCrystal_I2C::noCursor() {
  138.         _displaycontrol &= ~LCD_CURSORON;
  139.         command(LCD_DISPLAYCONTROL | _displaycontrol);
  140. }
  141. void LiquidCrystal_I2C::cursor() {
  142.         _displaycontrol |= LCD_CURSORON;
  143.         command(LCD_DISPLAYCONTROL | _displaycontrol);
  144. }

  145. // Turn on and off the blinking cursor
  146. void LiquidCrystal_I2C::noBlink() {
  147.         _displaycontrol &= ~LCD_BLINKON;
  148.         command(LCD_DISPLAYCONTROL | _displaycontrol);
  149. }
  150. void LiquidCrystal_I2C::blink() {
  151.         _displaycontrol |= LCD_BLINKON;
  152.         command(LCD_DISPLAYCONTROL | _displaycontrol);
  153. }

  154. // These commands scroll the display without changing the RAM
  155. void LiquidCrystal_I2C::scrollDisplayLeft(void) {
  156.         command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
  157. }
  158. void LiquidCrystal_I2C::scrollDisplayRight(void) {
  159.         command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
  160. }

  161. // This is for text that flows Left to Right
  162. void LiquidCrystal_I2C::leftToRight(void) {
  163.         _displaymode |= LCD_ENTRYLEFT;
  164.         command(LCD_ENTRYMODESET | _displaymode);
  165. }

  166. // This is for text that flows Right to Left
  167. void LiquidCrystal_I2C::rightToLeft(void) {
  168.         _displaymode &= ~LCD_ENTRYLEFT;
  169.         command(LCD_ENTRYMODESET | _displaymode);
  170. }

  171. // This will 'right justify' text from the cursor
  172. void LiquidCrystal_I2C::autoscroll(void) {
  173.         _displaymode |= LCD_ENTRYSHIFTINCREMENT;
  174.         command(LCD_ENTRYMODESET | _displaymode);
  175. }

  176. // This will 'left justify' text from the cursor
  177. void LiquidCrystal_I2C::noAutoscroll(void) {
  178.         _displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
  179.         command(LCD_ENTRYMODESET | _displaymode);
  180. }

  181. // Allows us to fill the first 8 CGRAM locations
  182. // with custom characters
  183. void LiquidCrystal_I2C::createChar(uint8_t location, uint8_t charmap[]) {
  184.         location &= 0x7; // we only have 8 locations 0-7
  185.         command(LCD_SETCGRAMADDR | (location << 3));
  186.         for (int i=0; i<8; i++) {
  187.                 write(charmap[i]);
  188.         }
  189. }

  190. // Turn the (optional) backlight off/on
  191. void LiquidCrystal_I2C::noBacklight(void) {
  192.         _backlightval=LCD_NOBACKLIGHT;
  193.         expanderWrite(0);
  194. }

  195. void LiquidCrystal_I2C::backlight(void) {
  196.         _backlightval=LCD_BACKLIGHT;
  197.         expanderWrite(0);
  198. }



  199. /*********** mid level commands, for sending data/cmds */

  200. inline void LiquidCrystal_I2C::command(uint8_t value) {
  201.         send(value, 0);
  202. }


  203. /************ low level data pushing commands **********/

  204. // write either command or data
  205. void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) {
  206.         uint8_t highnib=value&0xf0;
  207.         uint8_t lownib=(value<<4)&0xf0;
  208.        write4bits((highnib)|mode);
  209.         write4bits((lownib)|mode);
  210. }

  211. void LiquidCrystal_I2C::write4bits(uint8_t value) {
  212.         expanderWrite(value);
  213.         pulseEnable(value);
  214. }

  215. void LiquidCrystal_I2C::expanderWrite(uint8_t _data){                                       
  216.         Wire.beginTransmission(_Addr);
  217.         printIIC((int)(_data) | _backlightval);
  218.         Wire.endTransmission();   
  219. }

  220. void LiquidCrystal_I2C::pulseEnable(uint8_t _data){
  221.         expanderWrite(_data | En);        // En high
  222.         delayMicroseconds(1);                // enable pulse must be >450ns
  223.        
  224.         expanderWrite(_data & ~En);        // En low
  225.         delayMicroseconds(50);                // commands need > 37us to settle
  226. }


  227. // Alias functions

  228. void LiquidCrystal_I2C::cursor_on(){
  229.         cursor();
  230. }

  231. void LiquidCrystal_I2C::cursor_off(){
  232.         noCursor();
  233. }

  234. void LiquidCrystal_I2C::blink_on(){
  235.         blink();
  236. }

  237. void LiquidCrystal_I2C::blink_off(){
  238.         noBlink();
  239. }

  240. void LiquidCrystal_I2C::load_custom_character(uint8_t char_num, uint8_t *rows){
  241.                 createChar(char_num, rows);
  242. }

  243. void LiquidCrystal_I2C::setBacklight(uint8_t new_val){
  244.         if(new_val){
  245.                 backlight();                // turn backlight on
  246.         }else{
  247.                 noBacklight();                // turn backlight off
  248.         }
  249. }

  250. void LiquidCrystal_I2C::printstr(const char c[]){
  251.         //This function is not identical to the function used for "real" I2C displays
  252.         //it's here so the user sketch doesn't have to be changed
  253.         print(c);
  254. }


  255. // unsupported API functions
  256. void LiquidCrystal_I2C::off(){}
  257. void LiquidCrystal_I2C::on(){}
  258. void LiquidCrystal_I2C::setDelay (int cmdDelay,int charDelay) {}
  259. uint8_t LiquidCrystal_I2C::status(){return 0;}
  260. uint8_t LiquidCrystal_I2C::keypad (){return 0;}
  261. uint8_t LiquidCrystal_I2C::init_bargraph(uint8_t graphtype){return 0;}
  262. void LiquidCrystal_I2C::draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len,  uint8_t pixel_col_end){}
  263. void LiquidCrystal_I2C::draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len,  uint8_t pixel_row_end){}
  264. void LiquidCrystal_I2C::setContrast(uint8_t new_val){}

  265.        
復制代碼

所有資料51hei提供下載:
1602 IIC模塊資料.rar (1.15 MB, 下載次數: 13)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:314887 發表于 2018-4-23 21:55 | 只看該作者
都是高人,
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产精品视频免费观看 | 精品乱码一区二区 | 国产激情视频网址 | 一区二区三区视频 | 午夜精品一区二区三区在线播放 | 日本精品视频 | 久久精品在线播放 | 国产一级视频免费播放 | 国产精品一区二区三区四区五区 | 婷婷久久五月天 | 一区二区不卡高清 | 最新国产福利在线 | 九九视频在线观看 | 亚洲精品电影在线观看 | 久久久久亚洲精品 | 91综合网| 成人一区二区在线 | 欧美在线观看一区 | 日韩www| 国产欧美一区二区三区在线看 | 网址黄| 中文字幕一区二区三区四区不卡 | 天堂综合网 | 2019天天干夜夜操 | 国产视频久 | 亚洲福利片 | 久草热8精品视频在线观看 午夜伦4480yy私人影院 | 日韩在线观看一区 | 99色在线视频 | av在线成人 | 欧洲妇女成人淫片aaa视频 | aaaaaaa片毛片免费观看 | 亚洲一区二区三区四区在线观看 | 成人av一区二区三区 | 99久久久国产精品 | 日本一区二区视频 | 亚洲精品1 | 91资源在线观看 | 欧美日韩国产精品一区 | 午夜资源| 天天干国产 |