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

標題: stc89c51單片機+pcf8574(默認地址0x27)+lcd1602沒有亮 [打印本頁]

作者: jokerking    時間: 2023-3-21 16:03
標題: stc89c51單片機+pcf8574(默認地址0x27)+lcd1602沒有亮
stc89c51+pcf8574(默認地址0x27)+lcd1602代碼燒錄上去,lcd沒有亮,不知道到底是哪里出現(xiàn)了問題,LCD1602是在某一個寶上面買的,只有個C8051的破的代碼和arduino都用不了,我們學校要求用stc89c51單片機去編寫,求大佬看看哪里出現(xiàn)了問題。

單片機源程序如下:
  1. #include <reg52.h>
  2. #include "intrins.h"
  3. #define uchar unsigned char
  4. #define uint unsigned int

  5. //#define                        L1                0x80            // 第一行寫入地址
  6. //#define                        L2                0xc0            // 第二行寫入地址

  7. sbit SCL = P2^1;
  8. sbit SDA = P2^0;

  9. uchar woder[]={"wangzijie"};

  10. //char ADDR = 0x4E;    // PCF8574  T  模塊的地址碼
  11. //char ADDR = 0x7e;    // PCF8574   AT  模塊的地址碼
  12. char ADDR = 0x27;    // PCF8574   AT  模塊的地址碼


  13. //***************************** 延時 y  ms ***********************************************


  14. void delay1(int y)   //
  15. {
  16.          ;
  17.         while(y--)
  18.         {
  19.         unsigned char a,b,c;
  20.         for(c=1;c>0;c--)
  21.         for(b=142;b>0;b--)
  22.         for(a=2;a>0;a--);
  23.         }
  24. }






  25. //******************************** IIC 串口開始 ********************************************


  26. void IIC_start(void)
  27. {
  28.         SDA=1;
  29.         _nop_();
  30.         SCL=1;
  31.         _nop_();
  32.         _nop_();
  33.         _nop_();
  34.         _nop_();
  35.         _nop_();
  36.         SDA=0;
  37.         _nop_();
  38.         _nop_();
  39.         _nop_();
  40.         _nop_();
  41.         _nop_();
  42.         SCL=0;
  43. }




  44. //********************************** IIC 串口寫1個字節(jié) ******************************************


  45. void IIC_writeByte(char temp)
  46. {
  47.         char i;
  48.         for(i=0;i<8;i++)
  49.         {
  50.                 SDA=(bit)(temp & 0x80) ;   // 根據(jù)規(guī)定1602的數(shù)據(jù)最高位必須為  1  
  51.                 temp <<=1;
  52.                 _nop_();
  53.                 _nop_();
  54.                 SCL=1;
  55.                 _nop_();
  56.                 _nop_();
  57.                 _nop_();
  58.                 _nop_();
  59.                 _nop_();
  60.                 SCL=0;
  61.         }
  62.         _nop_();
  63.         _nop_();
  64.         _nop_();
  65.         _nop_();
  66.         SDA=1;
  67.         _nop_();
  68.         _nop_();
  69.         _nop_();
  70.         _nop_();
  71.         SCL=1;
  72.         _nop_();
  73.         _nop_();
  74.         _nop_();
  75.         while(SDA);
  76.         _nop_();
  77.         SCL=0;
  78. }




  79. //******************************** 1602寫命令 ********************************************


  80. void LCD_write_command(char comm)
  81. {
  82.         char tmp;
  83.         IIC_start();          // 串口開始
  84.         IIC_writeByte(ADDR);  // 先選PCF 8574T 的地址  (應該是相當于選中的意思吧)

  85.         tmp = comm & 0xF0;    // 與0xf0 應該是取第四位的意思吧
  86.         tmp |= 0x0C;         //保留高4位為指令的高四位,低四位為   RS = 0, RW = 0, EN = 1  
  87.         IIC_writeByte(tmp);  //從串口送出
  88.         delay1(20);
  89.         tmp &= 0xFB;        //Make EN = 0
  90.         IIC_writeByte(tmp);

  91.         tmp = (comm & 0x0F) << 4 ;  //將指令的低四位 送到高位置保存
  92.         tmp |= 0x0C;        //RS = 0, RW = 0, EN = 1
  93.         IIC_writeByte(tmp);
  94.         delay1(20);
  95.         tmp &= 0xFB; // Make EN = 0
  96.         IIC_writeByte(tmp);

  97. }
  98. //******************************** 1602寫數(shù)據(jù) ********************************************


  99. void LCD_write_data(char data1)
  100. {
  101.         char tmp;
  102.         IIC_start();
  103.         IIC_writeByte(ADDR);   // 先選PCF8574T 的地址  (應該是相當于選中的意思吧)

  104.         tmp = data1 & 0xF0;
  105.         tmp |= 0x0D; //RS = 0, RW = 0, EN = 1
  106.         IIC_writeByte(tmp);
  107.         delay1(20);
  108.         tmp &= 0xFB; //Make EN = 0
  109.         IIC_writeByte(tmp);

  110.         tmp = (data1 & 0x0F) << 4 ;
  111.         tmp |= 0x0D; //RS = 0, RW = 0, EN = 1
  112.         IIC_writeByte(tmp);
  113.         delay1(20);
  114.         tmp &= 0xFB ; // Make EN = 0
  115.         IIC_writeByte(tmp);
  116. }


  117. //******************************** 1602初始化 ********************************************


  118. void Init_Lcd(void)
  119. {
  120.         LCD_write_command(0x33); //將8位總線轉(zhuǎn)為4位總線
  121.         delay1(50) ;
  122.         LCD_write_command(0x32); //
  123.         delay1(50) ;
  124.         LCD_write_command(0x28); // 4位數(shù)據(jù)線0x28,顯示2行,5*7點陣字符  !如果是0x38  則為8位數(shù)據(jù)線,顯示2行,5*7點陣字符
  125.         delay1(50) ;
  126.         LCD_write_command(0x0C); // 開顯示,關閉光標,不閃爍
  127.         delay1(50) ;  
  128.         LCD_write_command(0x06); // 設定輸入方式,增量不位移
  129.         delay1(50) ;
  130.         LCD_write_command(0x01); // 清屏
  131.         delay1(50) ;
  132. //                LCD_write_command(0x80);  //設置數(shù)據(jù)指針起點
  133. //                delay1(50) ;
  134. }








  135. //*************************************** 在指定位置顯示字符串 *************************************


  136. void Write_LCD(int x, int y, char *str)
  137. {
  138.         char addr;
  139.         if( x < 0)
  140.         {
  141.                 x = 0;
  142.         }
  143.         if(x > 15)
  144.         {
  145.                 x = 15;
  146.         }
  147.         if(y<0)
  148.         {
  149.                 y = 0;
  150.         }
  151.         if(y > 1)
  152.         {
  153.                 y = 1;
  154.         }

  155.         addr = 0x80 + 0x40 * y + x;   // Move cursor  移動光標
  156.         LCD_write_command(addr);
  157.         while (*str)
  158.         {
  159.                 LCD_write_data(*str++);
  160.         }
  161. }


  162. //-------------------------------------------- 顯示字符串的函數(shù) ----------------------------------------------------


  163. void LCD_write_word(unsigned char *s)                  //顯示字符串的函數(shù)
  164. {
  165.         while(*s>0)
  166.         {
  167.                 LCD_write_data(*s);
  168.                 s++;
  169.         }
  170. }

  171. void main()
  172. {               
  173.          uchar i;
  174.         Init_Lcd();
  175. //        for(i=0;i<9;i++)
  176. //        {
  177.         Write_LCD(0,0,(uchar *)woder[i]);
  178.         LCD_write_word((uchar *)woder[i]);
  179. //        }
  180.         while(1);                                
  181. }


  182. //********************************* 指定位置顯示一個字符*******************************************


  183. /*
  184. void Print_Char (unsigned char line,unsigned char num,unsigned char date)
  185. {
  186.                 LCD_write_command(line+num);
  187.                 LCD_write_data(date);
  188. }


  189. */




  190. //按指定位置顯示一個字符(針對1602液晶)-用在溫度顯示


  191. //void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
  192. //{
  193. //Y &= 0x1;
  194. //X &= 0xF;                 //限制X不能大于15,Y不能大于1
  195. //if (Y) X |= 0x40;        //當要顯示第二行時地址碼+0x40;
  196. //X |= 0x80;               // 算出指令碼
  197. //LCD_write_command(X);    //這里不檢測忙信號,發(fā)送地址碼
  198. //LCD_write_data(DData);
  199. //}
復制代碼







歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 亚洲精品电影网在线观看 | 免费在线毛片 | 一区二区电影网 | 九九精品视频在线 | 久久久入口 | 日本一区二区不卡 | av一区在线观看 | 免费观看一级特黄欧美大片 | 久久亚洲天堂 | 欧美一区二区在线 | 成人亚洲性情网站www在线观看 | 黑人巨大精品欧美一区二区免费 | 亚洲欧美精品久久 | 日韩欧美综合在线视频 | 日韩欧美亚洲 | www.99热这里只有精品 | 九九亚洲精品 | 欧美一级欧美一级在线播放 | 福利视频一区 | 亚洲精品乱码久久久久久9色 | 精品二| 99福利网 | 亚洲狠狠| 一区二区三区精品在线 | 亚洲精品视频二区 | 国产精品18hdxxxⅹ在线 | 国产蜜臀 | 日本久久久一区二区三区 | 久久久久久久久久久久久91 | 欧美一区二区 | 亚洲成人高清 | 久久99精品视频 | 污书屋| 欧美专区在线观看 | 国产精品日日摸夜夜添夜夜av | 婷婷开心激情综合五月天 | 91精品国产综合久久久动漫日韩 | 男女羞羞视频网站 | 精品国产三级 | 在线视频 欧美日韩 | 午夜精品视频在线观看 |