为什么我的模数转换后lcd上不显示东西啊

2019-07-18 09:33发布

为什么我的模数转换后lcd上不显示东西啊,网上照搬了好几个例子都是这样.毕设要弄这个,第一次接触
12.png
程序:
#include<reg51.h>
#include<intrins.h>
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - 初始化接口
# define LCD_DB   P0  // - - P0   = DB0~DB7
sbit     LCD_RS=P2^0; // - - p2.0 = RS
sbit     LCD_RW=P2^1; // - - p2.1 = RW
sbit     LCD_E=P2^2;  // - - p2.2 = E
sbit          rd=P3^6; //IO口定义
sbit          wr=P3^5;
sbit          cs=P3^7;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - 定义函数
# define uchar unsigned char
# define uint unsigned int
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - 定义子程序函数
void LCD_init(void); // - - 初始化LCD1602函数
void LCD_write_command(uchar command); // - - 向LCD1602写指令函数
void LCD_write_data(uchar dat); // - - 向LCD1602写数据函数
void LCD_set_xy(uchar x,uchar y); // - - 设置LCD1602显示位置 X(0-16),y(1-2)
void LCD_disp_char(uchar x,uchar y,uchar dat); // - - 在LCD1602上显示一个字符
void LCD_disp_string(uchar X,uchar Y,uchar *s); // - - 在LCD1602上显示一个字符串
void LCD_delay_10us(uint n); // - - 10微秒的延时子程序
void LCD_delay_50us(uint n); // - - 50微秒的延时子程序
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - 初始化LCD1602
void LCD_init(void)
{
LCD_delay_10us(20);
LCD_write_command(0x38); // - - 设置8位格式,2行,5x7
LCD_delay_10us(5);
LCD_write_command(0x0c); // - - 整体显示,关光标,不闪烁
LCD_delay_10us(5);
LCD_write_command(0x06); // - - 设定输入方式,增量不移位
LCD_delay_10us(5);
LCD_write_command(0x01); // - - 清除屏幕显示
LCD_delay_50us(40);
}
//********************************

// - - 向LCD1602写指令
void LCD_write_command(uchar dat)
{
LCD_delay_10us(5);
LCD_RS=0; // - - 指令
LCD_RW=0; // - - 写入
LCD_DB=dat;
LCD_delay_10us(5);
LCD_E=1; // - - 允许
LCD_delay_10us(5);
LCD_E=0;
}

// - - 向LCD1602写数据
void LCD_write_data(uchar dat)
{
LCD_delay_10us(5);
LCD_RS=1;// - - 数据
LCD_RW=0;// - - 写入
LCD_DB=dat;
LCD_delay_10us(5);
LCD_E=1;// - - 允许
LCD_delay_10us(5);
LCD_E=0;
}

// - - 设置显示位置
void LCD_set_xy(uchar x,uchar y)
{
  uchar address;
  if(y==1)
  {
    address=0x80+x; // - - 第一行位置
  } else {
    address=0xc0+x; // - - 第二行位置
  }
    LCD_delay_10us(5);
    LCD_write_command(address);
}

// - - 显示一个字符函数
void LCD_disp_char(uchar x,uchar y,uchar dat) // - - LCD_disp_char(0,1,0x38); // - - 显示8
{
    LCD_set_xy(x,y);
    LCD_delay_10us(5);
    LCD_write_data(dat);
}

// - - 显示一个字符串函数
void LCD_disp_string(uchar x,uchar y,uchar *s)
{
  LCD_set_xy(x,y);
  LCD_delay_10us(5);
  while(*s!='')
  {
    LCD_write_data(*s);
    s++;
  }
}

//********************************

void LCD_delay_10us(uint n) // - - 10微秒的延时子程序
{
  uint i,j;
  for(i=n;i>0;i--)
    for(j=2;j>0;j--);  
}

void LCD_delay_50us(uint n) // - - 50微秒的延时子程序
{
  uint i,j;
  for(i=n;i>0;i--)
    for(j=22;j>0;j--);  
}
//
void display(uchar bai,uchar shi,uchar ge)
{
LCD_write_command(0x80);
LCD_write_data(0x30+bai);
LCD_write_data(0x30+shi);
LCD_write_data(0x30+ge);
}

//---------------------------------显示
void show(uchar DATA)      //显示
{
uchar a1,a2,a3,b1,b2,b3,i;/*定义变量*/
//读取P1口之前先给其写全1
//选通ADCS*/         
//使AD读输入点使能
i=DATA;         //把AD数据读取的数据赋给P1口
a1 = i%16 ;         //分出数据的高位和低位转换成是进制
a2 = i/16*16 ;
a3 = a2+a3;         //得到十进制的数据
b1=a3/100;         //分出百,十,个位
b2=a3%100/10;
b3=a3%10;
display(b1,b2,b3);
}
//--------------------------
void read_adc0804()//控制并读取adc0804转换好的数据
{
uchar a;          //写入控制命令,启动转换
cs=1;
wr=1;
cs=0;
wr=0;
_nop_();
wr=1;

P1=0xff;         //读取已转换好的数据
rd=1;
rd=0;
_nop_();
a=P1;
rd=1;
cs=1;

return a;
}


//--------------------------主函数
void main(void)
{
uchar a;
LCD_init();
while(1)
{
a=read_adc0804();
show(a);
}
}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。