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

標(biāo)題: stc12c5a60s2單片機(jī)12m晶振1602顯示程序問(wèn)題 [打印本頁(yè)]

作者: maizhi99    時(shí)間: 2019-7-9 08:20
標(biāo)題: stc12c5a60s2單片機(jī)12m晶振1602顯示程序問(wèn)題

  1. #include <STC12C5A60S2.H>
  2. #include <intrins.h>
  3. sbit RS=P4^3;
  4. sbit RW=P4^4;
  5. sbit E=P4^5;

  6. /*********************************************************************************************
  7. 函數(shù)名:毫秒級(jí)CPU延時(shí)函數(shù)
  8. 調(diào)  用:DELAY_MS (?);
  9. 參  數(shù):1~65535(參數(shù)不可為0)
  10. 返回值:無(wú)
  11. 結(jié)  果:占用CPU方式延時(shí)與參數(shù)數(shù)值相同的毫秒時(shí)間
  12. 備  注:應(yīng)用于1T單片機(jī)時(shí)i<600,應(yīng)用于12T單片機(jī)時(shí)i<125
  13. /*********************************************************************************************/
  14. void Delay1602 (unsigned int a){
  15.         unsigned int i;
  16.         while( a-- != 0){
  17.                 for(i = 0; i < 600; i++);
  18.         }
  19. }
  20. /*********************************************************************************************/
  21. //寫(xiě)數(shù)據(jù)函數(shù)

  22. void LCD1602_Write_data(unsigned char databuf)
  23. {
  24.    RS=1;
  25.    RW=0;
  26.    P0=databuf;
  27.    E=1;
  28.    E=0;
  29. }

  30. //寫(xiě)指令函數(shù)

  31. void LCD1602_Write_com(unsigned char combuf)
  32. {
  33.    RS=0;
  34.    RW=0;
  35.    P0=combuf;
  36.    E=1;
  37.    E=0;
  38. }
  39. //忙檢測(cè)函數(shù)
  40. void Lcd1602_busy(void)
  41. {
  42.    RS=0;
  43.    RW=1;
  44.    P0=0xFF;
  45.    E=1;
  46.    while(P0^7==1);
  47.    E=0;
  48. }
  49. //寫(xiě)指令函數(shù)帶忙檢測(cè)
  50. void LCD1602_Write_com_busy(unsigned char combuf)
  51. {
  52.    Lcd1602_busy();
  53.    RS=0;
  54.    RW=0;
  55.    P0=combuf;
  56.    E=1;
  57.    E=0;
  58. }
  59. //寫(xiě)數(shù)據(jù)帶忙檢測(cè)函數(shù)
  60. void LCD1602_Write_data_busy(unsigned char databuf)
  61. {
  62.    Lcd1602_busy();
  63.    RS=1;
  64.    RW=0;
  65.    P0=databuf;
  66.    E=1;
  67.    E=0;
  68. }


  69. //初始化 l
  70. void Lcd1602_init(void)
  71. {
  72.    Delay1602(15);
  73.    LCD1602_Write_com(0x38);
  74.    Delay1602(5);
  75.    LCD1602_Write_com(0x38);
  76.    Delay1602(5);
  77.    LCD1602_Write_com(0x38);
  78.    LCD1602_Write_com_busy(0x38);
  79.    LCD1602_Write_com_busy(0x08);
  80.    LCD1602_Write_com_busy(0x01);
  81.    LCD1602_Write_com_busy(0x06);
  82.    LCD1602_Write_com_busy(0x0c);
  83. }
  84. //寫(xiě)地址函數(shù)
  85. void lcd1602_Write_address(unsigned char x,unsigned char y)
  86. {
  87.     if(y==0)
  88.     LCD1602_Write_com_busy(0x80+x);
  89.         else
  90.         LCD1602_Write_com_busy(0xc0+x);

  91. }
  92. //顯示函數(shù)
  93. void Lcd1602_Disp(unsigned char x,unsigned char y,unsigned char buf)
  94. {
  95.     lcd1602_Write_address(x,y);
  96.         LCD1602_Write_data_busy(buf);
  97. }
  98. void main(void)
  99. {
  100.     Lcd1602_init();
  101.          Lcd1602_Disp(0,1,'1');
  102.          Lcd1602_Disp(1,1,'2');
  103.         while(1)
  104.         {

  105.         }
  106. }
復(fù)制代碼
各位看看錯(cuò)在哪里呢?1602沒(méi)有反應(yīng)

作者: shannenhuan    時(shí)間: 2019-7-9 09:48
用示波器對(duì)下波形吧
作者: 鵬博士PBs    時(shí)間: 2019-7-9 10:44
示波器和邏輯分析儀檢測(cè)一下對(duì)應(yīng)波形
作者: maizhi99    時(shí)間: 2019-7-9 12:24
鵬博士PBs 發(fā)表于 2019-7-9 10:44
示波器和邏輯分析儀檢測(cè)一下對(duì)應(yīng)波形

沒(méi)有示波器啊
作者: 周濤1331    時(shí)間: 2019-7-25 10:23
#include <STC12C5A60S2.H>
#include <intrins.h>
sbit RS=P4^3;
sbit RW=P4^4;
sbit E=P4^5;

/*********************************************************************************************
函數(shù)名:毫秒級(jí)CPU延時(shí)函數(shù)
調(diào)  用:DELAY_MS (?);
參  數(shù):1~65535(參數(shù)不可為0)
返回值:無(wú)
結(jié)  果:占用CPU方式延時(shí)與參數(shù)數(shù)值相同的毫秒時(shí)間
備  注:應(yīng)用于1T單片機(jī)時(shí)i<600,應(yīng)用于12T單片機(jī)時(shí)i<125
/*********************************************************************************************/
void Delay1602 (unsigned int a){
        unsigned int i;
        while( a-- != 0){
                for(i = 0; i < 600; i++);
        }
}
/*********************************************************************************************/
//寫(xiě)數(shù)據(jù)函數(shù)

void LCD1602_Write_data(unsigned char databuf)
{
   RS=1;
   RW=0;
   P0=databuf;
   E=1;
   E=0;
}

//寫(xiě)指令函數(shù)

void LCD1602_Write_com(unsigned char combuf)
{
   RS=0;
   RW=0;
   P0=combuf;
   E=1;
   E=0;
}
//忙檢測(cè)函數(shù)
void Lcd1602_busy(void)
{
   RS=0;
   RW=1;                                                          
   P0=0xFF;                                                         //        這個(gè)地方出現(xiàn)了問(wèn)題,P0=0x00;
   E=1;
   while(P0^7==1);                                          //P0^7==0;
   E=0;
}
//寫(xiě)指令函數(shù)帶忙檢測(cè)
void LCD1602_Write_com_busy(unsigned char combuf)
{
   Lcd1602_busy();
   RS=0;
   RW=0;
   P0=combuf;
   E=1;
   E=0;
}
//寫(xiě)數(shù)據(jù)帶忙檢測(cè)函數(shù)
void LCD1602_Write_data_busy(unsigned char databuf)
{
   Lcd1602_busy();
   RS=1;
   RW=0;
   P0=databuf;
   E=1;
   E=0;
}


//初始化 l
void Lcd1602_init(void)
{
   Delay1602(15);
   LCD1602_Write_com(0x38);
   Delay1602(5);
   LCD1602_Write_com(0x38);
   Delay1602(5);
   LCD1602_Write_com(0x38);
   LCD1602_Write_com_busy(0x38);
   LCD1602_Write_com_busy(0x08);
   LCD1602_Write_com_busy(0x01);
   LCD1602_Write_com_busy(0x06);
   LCD1602_Write_com_busy(0x0c);
}
//寫(xiě)地址函數(shù)
void lcd1602_Write_address(unsigned char x,unsigned char y)
{
    if(y==0)
    LCD1602_Write_com_busy(0x80+x);
        else
        LCD1602_Write_com_busy(0xc0+x);

}
//顯示函數(shù)
void Lcd1602_Disp(unsigned char x,unsigned char y,unsigned char buf)
{
    lcd1602_Write_address(x,y);
        LCD1602_Write_data_busy(buf);
}
void main(void)
{
    Lcd1602_init();
         Lcd1602_Disp(0,1,'1');
         Lcd1602_Disp(1,1,'2');
        while(1)
        {

        }
}




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