欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 單片機按鍵控制LCD1602,實現數值加減的源程序 [打印本頁]

作者: 王冰珂    時間: 2019-4-17 19:54
標題: 單片機按鍵控制LCD1602,實現數值加減的源程序
電路原理圖如下:


/*不知道,為什莫上傳不了,壓縮包,有圖,自己畫吧,我感覺注釋詳細啦。本人也是剛開始學。有更好的方法請評論,有需要的直接拿走*/

  1. #include <reg52.h>
  2. typedef unsigned char uchar;
  3. typedef unsigned int uint;
  4. uchar code table[] = {"Welcome!"};
  5. uchar code ren[] = {"RenShu:"};
  6. uchar code dat[2];
  7. sbit RS = P3^5;         //RS端
  8. sbit RW = P3^6;
  9. sbit EN = P3^4;         //EN端
  10. sbit du=P2^6;
  11. sbit we=P2^7;
  12. sbit k1=P3^0;
  13. sbit k2=P3^1;
  14. uint num,i,c;
  15. void delay(uint z)
  16. {
  17.         uint x,y;
  18.         for(x = z; x > 0; x--)
  19.                 for(y = 114; y > 0 ; y--);
  20. }
  21. void Read_Busy()
  22. {
  23.         uchar busy;
  24.         P0 = 0xff;
  25.         RS = 0;
  26.         RW = 1;
  27.         do
  28.         {
  29.                 EN = 1;
  30.                 busy = P0;
  31.                 EN = 0;
  32.         }while(busy & 0x80);
  33. }
  34. void Write_Cmd(uchar cmd)
  35. {
  36.         Read_Busy();//判斷忙
  37.         RS = 0;
  38.         RW = 0;
  39.         P0 = cmd;
  40.         EN = 1;
  41.         EN = 0;
  42. }
  43. //寫一個字節數據
  44. void Write_Dat(uchar dat)
  45. {
  46.         Read_Busy();
  47.         RS = 1;
  48.         RW = 0;
  49.         P0 = dat;
  50.         EN = 1;
  51.         EN = 0;
  52. }
  53. void Init_LCD1602()
  54. {
  55.         du=0;
  56.         we=0;
  57.         EN=0;
  58.         Write_Cmd(0x38); //        設置16*2顯示,5*7點陣,8位數據接口
  59.         Write_Cmd(0x0c);        
  60.         Write_Cmd(0x06); //讀寫一字節后地址指針加1
  61.         Write_Cmd(0x01); //清除顯示
  62. }
  63. void key()
  64. {
  65.          if(k1==0)
  66.                    {
  67.                                    delay(5);
  68.                                 if(k1==0)
  69.                                 {                        
  70.                 c++;
  71.                                 }
  72.                                 while(!k1);
  73.                    }
  74.         if(k2==0)
  75.                    {
  76.                                    delay(5);
  77.                                 if(k2==0)
  78.                                 {
  79.                 c--;
  80.                                 }
  81.                                 while(!k2);
  82.                    }
  83. }
  84. void main()
  85. {
  86. Init_LCD1602();//1602初始化
  87.         c=0;        
  88. while(1)
  89. {
  90.         Write_Cmd(0x80 | 0x00);//顯示地址
  91.         for(num=0;num<8;num++)
  92.         {
  93.                  Write_Dat(table[num]);
  94.                  delay(5);        
  95.         }
  96.         Write_Cmd(0x80 | 0x40);//顯示地址
  97.         for(i=0;i<7;i++)
  98.         {
  99.                  Write_Dat(ren[i]);
  100.                  delay(5);        
  101.         }
  102.     Write_Cmd(0x80 | 0x48);//設置顯示地址0x00,第一行從第一個字符開始顯示
  103.         key();
  104.         Write_Dat(c/10+0x30);
  105.     Write_Dat(c%10+0x30);
  106.         }
  107. }
復制代碼


作者: YUKIAd0w    時間: 2023-4-24 21:04
在51開發板上不可以誒
作者: sonique0371    時間: 2023-4-25 09:20
sbit du=P2^6;
sbit we=P2^7;
請問一下,這兩個語句有什么作用?
作者: qwerdfzxc    時間: 2024-6-18 17:23
怎么把那個減到零后就不減了呢

作者: cy009    時間: 2024-6-19 08:56
qwerdfzxc 發表于 2024-6-18 17:23
怎么把那個減到零后就不減了呢

方式一:先執行后判斷
c--;
if(c==0) c=0;

方式二:先判斷后執行
if(c>0) c--;
作者: zya112233    時間: 2025-4-14 18:25
sonique0371 發表于 2023-4-25 09:20
sbit du=P2^6;
sbit we=P2^7;
請問一下,這兩個語句有什么作用?

定義引腳





歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1