找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1916|回复: 4
收起左侧

stc12c5a60s2单片机12m晶振1602显示程序问题

[复制链接]
ID:56694 发表于 2019-7-9 08:20 | 显示全部楼层 |阅读模式

  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. 函数名:毫秒级CPU延时函数
  8. 调  用:DELAY_MS (?);
  9. 参  数:1~65535(参数不可为0)
  10. 返回值:无
  11. 结  果:占用CPU方式延时与参数数值相同的毫秒时间
  12. 备  注:应用于1T单片机时i<600,应用于12T单片机时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. //写数据函数

  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. //写指令函数

  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. //忙检测函数
  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. //写指令函数带忙检测
  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. //写数据带忙检测函数
  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. //写地址函数
  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. //显示函数
  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. }
复制代码
各位看看错在哪里呢?1602没有反应
回复

使用道具 举报

ID:580470 发表于 2019-7-9 09:48 | 显示全部楼层
用示波器对下波形吧
回复

使用道具 举报

ID:282095 发表于 2019-7-9 10:44 | 显示全部楼层
示波器和逻辑分析仪检测一下对应波形
回复

使用道具 举报

ID:56694 发表于 2019-7-9 12:24 | 显示全部楼层
鹏博士PBs 发表于 2019-7-9 10:44
示波器和逻辑分析仪检测一下对应波形

没有示波器啊
回复

使用道具 举报

ID:480680 发表于 2019-7-25 10:23 | 显示全部楼层
#include <STC12C5A60S2.H>
#include <intrins.h>
sbit RS=P4^3;
sbit RW=P4^4;
sbit E=P4^5;

/*********************************************************************************************
函数名:毫秒级CPU延时函数
调  用:DELAY_MS (?);
参  数:1~65535(参数不可为0)
返回值:无
结  果:占用CPU方式延时与参数数值相同的毫秒时间
备  注:应用于1T单片机时i<600,应用于12T单片机时i<125
/*********************************************************************************************/
void Delay1602 (unsigned int a){
        unsigned int i;
        while( a-- != 0){
                for(i = 0; i < 600; i++);
        }
}
/*********************************************************************************************/
//写数据函数

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

//写指令函数

void LCD1602_Write_com(unsigned char combuf)
{
   RS=0;
   RW=0;
   P0=combuf;
   E=1;
   E=0;
}
//忙检测函数
void Lcd1602_busy(void)
{
   RS=0;
   RW=1;                                                          
   P0=0xFF;                                                         //        这个地方出现了问题,P0=0x00;
   E=1;
   while(P0^7==1);                                          //P0^7==0;
   E=0;
}
//写指令函数带忙检测
void LCD1602_Write_com_busy(unsigned char combuf)
{
   Lcd1602_busy();
   RS=0;
   RW=0;
   P0=combuf;
   E=1;
   E=0;
}
//写数据带忙检测函数
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);
}
//写地址函数
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);

}
//显示函数
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)
        {

        }
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表