找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4162|回复: 7
收起左侧

酒精浓度测试仪,lcd1602不显示,rw端口一直是高电平,麻烦大神看下程序那里有问题

[复制链接]
ID:58352 发表于 2014-1-11 19:23 | 显示全部楼层 |阅读模式
#include<reg52.h>
#include<stdio.h>
#include"LCD1602.h"
#include<Ds1302.h>
#include<AT24c02.h>
#include<ADC0832.h>

#define uint unsigned int
#define uchar unsigned char

sbit k0=P1^0;
sbit k1=P1^1;
sbit k2=P1^2;
sbit k3=P1^3;

bit flg=0;

uchar M_time[]={"Time"};
uchar M_Detect[]={"Detect"};
uchar M_Storage[]={"Storage"};
uchar stor[4];

void initial_lcd1602(void);
void delays(unit n)
{

      while(n--);
          }

          void chang_h(void)
          {
          int g;
          if(k0==0)
          {for(g=0;g<20;){delays1(100);g++;}
          if(k0==0)
          {wr_data[4]=readtimeR[4]+1;
          if(wr_data[4]>0x23)wr_data[4]=0x00;
          }
          }
          if(k1==0)
           {for(g=0;g<20;){delays1(100);g++;}
          if(k1==0)
          {wr_data[4]=readtimeR[4]-1;
          if(readtimeR[4]>0x00)wr_data[4]=0x00;
            }
              }  

         DS1302_init();
         showdata();
         Display_List_Char(1,0,lcd_time);
         }

         void chang_m(void)
{
         int g;
         if(k0==0)
        {for(g=0;g<20;){delays1(100);g++;}
          if(k0==0)
          {wr_data[5]=readtimeR[5]+1;
          if(wr_data[5]>0x23)wr_data[5]=0x00;
          }
          }
          if(k1==0)
           {for(g=0;g<20;){delays1(100);g++;}
          if(k1==0)
          {wr_data[5]=readtimeR[5]-1;
          if(readtimeR[5]==0x00)wr_data[5]=0x00;
   }
   }


          DS1302_init();
         showdata();
         Display_List_Char(1,0,lcd_time);
         }

         void chang_s(void)
{
         int g;
         if(k0==0)
        {for(g=0;g<20;){delays1(100);g++;}
          if(k0==0)
          {wr_data[6]=readtimeR[6]+1;
          if(wr_data[6]>0x23)wr_data[6]=0x00;
          }
          }
          if(k1==0)
           {for(g=0;g<20;){delays1(100);g++;}
          if(k1==0)
          {wr_data[6]=readtimeR[6]-1;
          if(readtimeR[6]==0x00)wr_data[6]=0x00;
   }
   }

   DS1302_init();
   showdata();
   Display_List_Char(1,0,lcd_time);
   }


   void main()
   {
   uchar i,dd;
   unit g;
   uchar show[4];
   unsigned int data_temp=0;

   initial_lcd1602();
   DS1302_init();
   delays1(100);
   Display_List_Char(0,0,LCD_Code2);
   for(g=0;g<100;){delays1(100);g++;}

   while(1)
   {
   if(k0==0|k1==0|k2==0|k3==0)
   {
   write_lcd_command(0x01);
   for(g=0;g<100;){delays1(100);g++;}
   Display_List_Char(0,0,M_time);
   Display_List_Char(0,8,M_Detect);
   Display_List_Char(1,0,M_Storage);
   for(g=0;g<10;){delays1(100);g++;}

   if(k0==0)
   {
    write_lcd_command(0x01);
        do
        {if(k3==0) flg=1;
        showdata();
        Display_List_Char(0,0,lcd_dat+3);
        Display_List_Char(1,0,lcd_time);

        if(k2==0)
        {do
        {Display_One_Char(1,10,'H');
        if(k3==0)flg=1;
        chang_h();
        for(g=0;g<100;){delays1(100);g++;}
        if(k2==0)
        {do
        {
        Display_One_Char(1,10,'M');
        if(k3==0)flg=1;
        chang_m();
        for(g=0;g<100;){delays1(100);g++;}

                if(k2==0)
        {do
          {
        Display_One_Char(1,10,'S');
        if(k3==0)flg=1;
        chang_s( );
        }while(flg==0);
        }
        }while(flg==0);
        }
        }while(flg==0);flg=0;
        write_lcd_command(0x01);
        }

        for(g=0;g<500;){delays1(100);g++;}
        }while(flg==0);flg=0;

        }
        if(k1==0)
        {
        write_lcd_command(0x01);
        do
        {
        if(k3==0)flg=1;
        data_temp=ADconv();
        stor[0]=data_temp;
        xs_int(196*data_temp,1);
        }while(flg==0);flg=0;

        }
        if(k2==0)
        {
        write_lcd_command(0x01);
        do
        {
        if(k3==0)flg=1;
        for(i=0;i<3;)
        {
        i2c_writ(0x00+i,0x63+i);
        i2c_writ(0x00+i,stor[0]);
        i++;
        }
        _nop_();
        i=0;
        for(i=0;i<3;)
        {
        dd=i2c_read(0x00+i);
        show[i]=dd;
        i++;
        }
        Display_List_Char(1,0,show);
        }while(flg==0);flg=0;
        for(g=0;g<500;){delays1(100);g++;}
        }
        }
        }
        }


        #include<reg52.h>
        #include<stdio.h>
        #include<string.h>
        #define uchar unsigned char
        #define unit unsigned int

        #define LCDPORT P0

        sbit RS=P2^0;
        sbit RW=P2^1;
        sbit EN=p2^2;

        uchar LCD_Code2[]="Welcome: ";
        uchar LCD_Code[]="0123456789ABCDEF-.";

        void lcd_delay(uchar delaytime)
        {
        while(delaytime)delaytime--;
        }

        vodi write_lcd_command(uchar write_command)
        {
        lcd_delay(40);
        RS=0;
        RW=0;
        LCDPORT=write_command;
        EN=1;
        EN=0;
        }
        void write_lcd_data(uchar write_data)
        {
        lcd_delay(40);
        RS=1;
        RW=0;
        LCDPORT=write_data;
        EN=1;
        EN=0;
        }

        void Display_One_Char(uchar x,uchar y,uchar dat)
        {
        switch(x)
        {
        case0:
        write_lcd_command(0x80+y);
        break;
                case1:
        write_lcd_command(0xc0+y);
        break;
        }
                write_lcd_data(dat);
                }
   void Display_List_Char(uchar x,uchar y,uchar *str)
           {
        switch(x)
        {
        case0:
        write_lcd_command(0x80+y);
        break;
                case1:
        write_lcd_command(0xc0+y);
        break;
        }
        while(*str!='\0')
        {
        write_lcd_data(*str);
        str++;
        }
        }

        void xs_int(unsigned int shuju,bit t)
        {unsigned char huancun[6]={0};
        unsigned char biaozhi=0,i;
        if (shuju<10)biaozhi=1;
        else if(shuju<100)biaozhi=2;
        else if(shuju<1000)biaozhi=3;
        else if(shuju<10000)biaozhi=4;
        else if(shuju<65535)biaozhi=5;
        switch(biaozhi)
        {case5:huancun[5]=shuju/10000;
        case4:huancun[3]=shuju%10000/1000;
        case3:huancun[2]=shuju%1000/100;
        case2:huancun[1]=shuju%100/10;
        case1:huancun[0]=shuju%10;
        break;
        default:break;
        }
        for(i=6;i>1;i--)
        {if(i==5)Display_One_Char(1,10,'.');
        else Display_One_Char(t,15-i,0x30+huancun[i-1]);
        }
        Display_One_Char(t,15,'V');
        }

        void initial_lcd1602(void)
        {
        uchar i;
        EN=0;
        for(i=200;i>0;i--)
        lcd_delay(248);
        write_lcd_command(0x38);
        for(i=4;i>0;i--)
        lcd_delay(248);
        write_lcd_command(0x38);
        for(i=4;i>0;i--)
        lcd_delay(248);
        write_lcd_command(0x0c);
        for(i=4;i>0;i--)
        lcd_delay(248);
        write_lcd_command(0x06);
        for(i=4;i>0;i--)
        lcd_delay(248);
        write_lcd_command(0x01);
        for(i=4;i>0;i--)
        lcd_delay(248);
       
        }

         
         
         #include<reg52.h>
         #include<intrins.h>
       

         sbit CS=P3^1;
         sbit CLK=P3^2;
         sbit Do=P3^3;
         sbit Di=P3^3;
         unsigned char CH=0x02;

         unsigned char ADconv(void)
         {unsigned char i;
         unsigned int data_f=0,data_c=0;
         Di=1;
         CS=1;
         _nop_();
         CS=0;
         Di=1;
         CLK=1;
         _nop_();
         _nop_();
         CLK=0;
         _nop_();
         _nop_();
         CLK=1;
        Di=(bit)(0x02&CH);
    _nop_();
         CLK=0;
        _nop_();
    _nop_();
        CLK=1;
        Di=(bit)(0x01&CH);
        _nop_();
        _nop_();
        CLK=0;
        Di=1;CLK=1;
        _nop_();
        _nop_();
        CLK=0;
        _nop_();
        CLK=1;


        for(i=8;i>0;i--)
        {
        data_f|=Do;
        data_f<<=1;
        CLK=1;
        _nop_();
        _nop_();
        CLK=0;
        _nop_();
        }
        for(i=8;i>0;i--)
        {
        data_c<<=1;
        data_c|=Do;
        _nop_();
        CLK=1;
        _nop_();
        _nop_();
        CLK=0;
        _nop_();
        }
       
        CLK=0;
        _nop_();
        _nop_();
        CLK=1;
        _nop_();
        _nop_();

        CLK=0;
        _nop_();
        _nop_();
        CLK=1;
        _nop_();
        CS=1;
        _nop_();
        _nop_();
        return data_f;
        }

         

         
         #include<reg52.h>
         #include<stdio.h>

         sbitDS1302_CLK=P3^5;
         sbitDS1302_IO=P3^6;
         sbitDS1302_RST=P3^7;


         uchar lcd_dat[]={"2013-12-30    1"}
         uchar lcd_time[]={"15:12:30"}
         uchar wr_data[8]={0x09,0x09,0x26,0x06,0x22,0x59,0x50};
         uchar readtimeR[8];
         void delays(unit n)
         {
         while(n--);
         }



         void sendbyte(uchar a)
         {
          uchar i,temp;
          temp=a;
          for(i=8;i>0;i--)
          {
          if(temp&0x01)
          DS1302_IO=1;
          else
          DS1302_IO=0;
          temp=temp>>1;
          DS1302_CLK=1
          delays(5);
          DS1302_CLK=0
          delays(5);
          }
          
         }


          uchar readbyte(void)
          {
          uchar i,dat=0;
          for(i=8;i>0;i--)
          {
          DS1302_IO=1;
          dat>>=1;
          if(DS1302_IO)
          dat|=0x80;
          DS1302_CLK=1;
          delays(5);
          DS1302_CLK=0;
          }
          return dat;
          }



          void writ_DS1302(uchar address,uchar dat)
          {
          DS1302_RST=0;
          DELAYS(10);
           DS1302_CLK=0;
          DELAYS(10);
           DS1302_RST=1;
          DELAYS(5);
          sendbyte(address);
          delays(5);
          sendbyte(dat);
           DS1302_RST=0;
           DS1302_CLK=0;
           }

           uchar red_DS1302(uchar address)
           {
           uchar timer;
           DS1302_RST=0;
          DELAYS(2);
           DS1302_CLK=0;
          DELAYS(2);
           DS1302_RST=1;
           sendbyte(address);
           timer=readbyte();
           DS1302_RST=0;
           DS1302_CLK=0;
           return timer;
           }



           void DS1302_init()
           {
           write_DS1302(0xbe,0x00);
           write_DS1302(0x8e,0x00);
           write_DS1302(0x8c,wr_data[0]);
           write_DS1302(0x88,wr_data[1]);
           write_DS1302(0x86,wr_data[2]);
           write_DS1302(0x8A,wr_data[3]);
           write_DS1302(0x84,wr_data[4]);
           write_DS1302(0x82,wr_data[5]);
           write_DS1302(0x80,wr_data[6]);
           write_DS1302(0x8e,0x80);
           }

           void red_time(void)
           {
           readtimeR[0]=read_DS1302(0x8d);
           readtimeR[1]=read_DS1302(0x89);
           readtimeR[2]=read_DS1302(0x87);
           readtimeR[3]=read_DS1302(0x8b);
           readtimeR[4]=read_DS1302(0x85);
           readtimeR[5]=read_DS1302(0x83);
           readtimeR[6]=read_DS1302(0x81);
           }


           void showdata()
           {
           read_time();
           lcd_dat[3]=(readtimeR[0]>>4)+0x30;
            lcd_dat[4]=(readtimeR[0]&0x0f)+0x30;
                 lcd_dat[6]=(readtimeR[1]>>4)+0x30;
                  lcd_dat[7]=(readtimeR[1]&0x0f)+0x30;
                   lcd_dat[9]=(readtimeR[2]>>4)+0x30;
                    lcd_dat[10]=(readtimeR[2]&0x0f)+0x30;
                         lcd_dat[14]=(readtimeR[3]&0x0f)+0x30;
                          lcd_dat[0]=(readtimeR[4]>>4)+0x30;
                           lcd_dat[1]=(readtimeR[4]&0x0f)+0x30;
                            lcd_dat[3]=(readtimeR[5]>>4)+0x30;
                                 lcd_dat[4]=(readtimeR[5]&0x0f)+0x30;
                                  lcd_dat[6]=(readtimeR[6]>>4)+0x30;
                                   lcd_dat[7]=(readtimeR[6]&0x0f)+0x30;
                                   }

          






1.jpg
回复

使用道具 举报

ID:18297 发表于 2014-1-13 16:29 | 显示全部楼层
你的程序还有语法错误,估计没有完成编译。更不要说功能正不正常了。
建议可以分成模块调试,lcd1602模块,ds1302模块,最后再汇总。
回复

使用道具 举报

ID:58352 发表于 2014-1-15 18:02 | 显示全部楼层
zjjhtony 发表于 2014-1-13 16:29
你的程序还有语法错误,估计没有完成编译。更不要说功能正不正常了。
建议可以分成模块调试,lcd1602模块 ...

我编译显示0错误2警告,并生成了hex文件了的,但是就是没显示,
回复

使用道具 举报

ID:18297 发表于 2014-1-15 19:22 | 显示全部楼层
sbit RS=P2^0;
        sbit RW=P2^1;
        sbit EN=p2^2;   //这个P应该大写,不知道你贴出来的是否是源码?
回复

使用道具 举报

ID:58352 发表于 2014-1-17 11:19 | 显示全部楼层
zjjhtony 发表于 2014-1-15 19:22
sbit RS=P2^0;
        sbit RW=P2^1;
        sbit EN=p2^2;   //这个P应该大写,不知道你贴出来的是否 ...

我看了一下,我写的是大写的P,不知道能否留下QQ等联系方式,小弟现在急于解决这个问题然后回家过年啊,万分感激了。
回复

使用道具 举报

ID:18297 发表于 2014-1-17 13:46 | 显示全部楼层
QQ:12226405
回复

使用道具 举报

ID:79182 发表于 2015-5-7 13:06 | 显示全部楼层
亲,求源码和仿真
回复

使用道具 举报

ID:148094 发表于 2016-11-16 18:01 | 显示全部楼层
还有没有仿真和源程序??
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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