打印

1602为什么 第二行 乱码。。。。。

[复制链接]
3086|15
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
TLC, AD, CD, LCD, tmp
显示如图:


程序:           
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit eoc=P3^2;
sbit ale=P2^0;
sbit start=P2^1;
sbit oe=P3^3;

sbit adda=P2^2;
sbit addb=P2^3;
sbit addc=P2^4;
sbit lcdrs=P2^7;
sbit lcdrw=P2^6;
sbit lcden=P2^5;
int tmp1,tmp2,num;
uchar code table1[]="Alcohol  content";
uchar  table2[5];
void delayms(int z)
{ int x,y;
for(x=z;x<0;x--)
  for(y=110;y<0;y--);
}
bit busy()  
{  
   P0 = 0xff ;  
   lcdrs = 0 ;  
   lcdrw = 1 ;  
   lcden = 0 ;  
   lcden = 1 ;  
   return (bit)(P0 & 0x80) ;  
}

void write_com(uchar com)
{
while(busy());
lcdrs=0;
P0=com;
    lcdrw=0;
delayms(5);
lcden=1;
delayms(5);
lcden=0;

}
void write_date(uchar date)
{
lcdrs=1;
P0=date;
lcdrw=0;
delayms(5);
lcden=1;
delayms(5);
lcden=0;
}
void init()//初始化
{
lcdrw=0;
lcden=0;
write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
delayms(10);
write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
delayms(10);
write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
delayms(10);
write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
delayms(10);

write_com(0x08);
write_com(0x01);//显示消0,数据指针清零
write_com(0x06);
write_com(0x0c);//设置开显示,不显示光标
}


void ad_init()
{
start=0;
ale=0;
oe=0;
}
void channel(int x)
{
adda=x&0x01;
addb=x&0x02;
addc=x&0x04;
}
void addata_reverse(uint tmp1)//电路连反了
//AD采集数据后数据处理函数 将采集到的数的最高位和最低位对调
{
tmp2=
   ((tmp1&0x01)<<7)
  |((tmp1&0x02)<<5)
  |((tmp1&0x04)<<3)
  |((tmp1&0x08)<<1)
  |((tmp1&0x10)>>1)
  |((tmp1&0x20)>>3)
  |((tmp1&0x40)>>5)
  |((tmp1&0x80)>>7);
}


void ad_process(int tmp2) //255*4=1000
{
tmp2=tmp2<<2; //乘4
table2[0]=0x35;
table2[1]=0x33;
table2[2]=0x30;
table2[3]=0x34;
table2[4]=0x37;
/*
table2[0]=tmp2/100+0x30;
table2[1]=tmp2%100/10+0x30;
table2[2]=0x2e;
table2[3]=tmp1%10+0x30;
table2[4]=0x25;*/
}

void main()
{
init();
while(1)
{/*
  ad_init();  //初始化
  ale=1;   
  start=1;
  channel(0);
  ale=0;
  start=0;
  delayms(1);

/* if(eoc == 1)    //查询法
  {
   oe=1;      //开使能端,输出数据
   delayms(1);
   tmp1=P1;
   oe=0;   //关断
   delayms(1);
  }
   addata_reverse(tmp1);
   ad_process(tmp2);*/
           // init();
   write_com(0x80);
   delayms(5);
  
   for(num=0;num<16;num++)
   {
    write_date(table1[num]);
    delayms(5);
   }
   write_com(0xc0);
   delayms(5);
   for(num=0;num<5;num++)
   {
    write_date(table2[num]);
    delayms(5);
   }
   while(1);
  
}
}

相关帖子

沙发
CATA_LYST|  楼主 | 2012-4-7 11:22 | 只看该作者
dinng

使用特权

评论回复
板凳
CATA_LYST|  楼主 | 2012-4-7 11:23 | 只看该作者
端个板凳 在线等。。。。。。。

使用特权

评论回复
地板
CATA_LYST|  楼主 | 2012-4-7 11:31 | 只看该作者
那位银,看下,,,问题在哪里??????程序很简单的,,,不胜感激啊啊啊啊啊啊!!!!!!

使用特权

评论回复
5
CATA_LYST|  楼主 | 2012-4-7 11:33 | 只看该作者
只是 ,,显示部分的 ,,

顶顶
顶顶顶顶

使用特权

评论回复
6
lvvdong| | 2012-4-7 11:41 | 只看该作者
那是因为你设置显示循环的数值太多造成的。你第二行不显示内容,却写了地址当然会出现乱码了,把它删除就行了。

使用特权

评论回复
7
CATA_LYST|  楼主 | 2012-4-7 12:38 | 只看该作者
table2[0]=0x35;
table2[1]=0x33;
table2[2]=0x30;
table2[3]=0x34;
table2[4]=0x37;
不会吧,num=5,循环了5次,我只让显示五个char!却还是乱码
那肯定要让第二行显示的,那该怎么改
求教???????

使用特权

评论回复
8
dirtwillfly| | 2012-4-7 12:59 | 只看该作者
有可能是1602是坏的。我年前买过一个,只有第一行可以正常显示,第二行不显示。遍历显示内置字符,字符只有部分是正确的,其他字符全是乱码或者重复

使用特权

评论回复
9
CATA_LYST|  楼主 | 2012-4-7 13:16 | 只看该作者
1602好着呢 我改了一下程序,位置在最后
                                write_com(0xc0);
                        delayms(5);
                        for(num=0;num<16;num++)
                        {
                                write_date(0x38);
                                delayms(5);
                        }
                        while(1);
               
        }
}

使用特权

评论回复
10
CATA_LYST|  楼主 | 2012-4-7 13:18 | 只看该作者

使用特权

评论回复
11
CATA_LYST|  楼主 | 2012-4-7 13:21 | 只看该作者
求RP,,,求回复,,,,,,,,,,,

使用特权

评论回复
12
CATA_LYST|  楼主 | 2012-4-7 13:28 | 只看该作者
我找到原因了 ,我对这五个数赋值,是在一个函数中,但是却没有调用,自然乱码了

使用特权

评论回复
13
joyme| | 2012-4-7 13:33 | 只看该作者
你table2是在ad_process里赋值的,但这个语句被注释了,所以是乱码也不稀奇呀

使用特权

评论回复
14
mage心寒| | 2012-4-7 14:45 | 只看该作者
贴代码就不要贴初始化那块了,直接上问题那块,看的我晕乎乎的。。。

使用特权

评论回复
15
nongfuxu| | 2012-4-8 09:17 | 只看该作者
我找到原因了 ,我对这五个数赋值,是在一个函数中,但是却没有调用,自然乱码了

;P

使用特权

评论回复
16
海川先生| | 2012-4-9 09:44 | 只看该作者
呵呵

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

18

主题

126

帖子

1

粉丝