求问我这个1602程序为什么无法输出AD转换的值

qq_38593962 2017-08-11 03:22:44
# include<reg51.h>
# define uint unsigned int
# define uchar unsigned char
uchar code table[]="0123456789";
sbit START=P3^0;
sbit EOC=P3^1;
sbit OE=P3^2;
sbit lcden=P3^4;
sbit lcdrs=P3^5;
uchar num;


void delay(uint z)
{ /*uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--); */
z--;
}
void write_com(uchar com)
{lcdrs=0;
P2=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(uchar date)
{
lcdrs=1;
P2=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{lcden=1;
write_com(0x38);
write_com(0x0e);
write_com(0x06);
write_com(0x01);
write_com(0x80+0x1);}
void main () {
uint temp;
START=0;
OE=0;
START=1;
START=0;
while(1)
{if(EOC==1)
{OE=1;
temp=P0;
temp=temp*1.0/255*500;
OE=0;
init();
delay(100);
write_com(0x80+0x1);
write_data(table[temp%10+0x30]);
write_com(0x80+0x2);
write_data(table[temp/10%10+0x30]);
write_com(0x80+0x3);
write_data(table[temp/100%10+0x30]);

delay(500);
START=1;
START=0;

}
}} 显示没有错误,但就是无法输出,lcd亮但是没有输出
...全文
229 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
依然冷暖 2017-08-13
  • 打赏
  • 举报
回复
显示器亮只是背光电源有而已 对照下1602的引脚和你io口引脚是否对应吧
tianxj001 2017-08-13
  • 打赏
  • 举报
回复
给你一个我自己调试通过的1602程序,用的是四线数据
// ************************************************
// *** LCD_4BIT Driver V1.1 ***
// *** LCD.C ***
// ************************************************
#define LCD_C
#include "includes.h"

// *** Set port for LCD Data Bus 8 bit mode *** //
#define LCD_WD_PORT PORTB //Bit0-3
#define LCD_RD_PORT PINB  //Bit0-3
#define LCD_RW_PORT DDRB  //Bit0-3
#define SET_LCD_IN DDRB&=0XF0
#define SET_LCD_OUT DDRB|=0X0F
/****************************************************************/
#define LCD_RS (PORTD_Bit5)       //引脚定义
#define LCD_RW (PORTD_Bit6)
#define LCD_EN (PORTB_Bit4)     

#define LCD_SET_EN()    (LCD_EN=1)   //置位与清零
#define LCD_SET_RS()   	(LCD_RS=1)
#define LCD_SET_RW()   	(LCD_RW=1)
#define LCD_CLEAR_EN()  (LCD_EN=0)
#define LCD_CLEAR_RS() 	(LCD_RS=0)
#define LCD_CLEAR_RW() 	(LCD_RW=0)

// *******常量数据***********************

#define LCD_ON 				0x0C
#define LCD_CURS_ON 		0x0D
#define LCD_OFF 			0x08
#define LCD_HOME 			0x02
#define LCD_CLEAR 			0x01
#define LCD_NEW_LINE 		0xC0
#define LCD_FUNCTION_SET 	0x28
#define LCD_MODE_SET  		0x06

// ***********LED初始化**********************
void LCD_INIT(void)
  {
      SET_LCD_OUT;          	// LCD port output
      LCD_WD_PORT = 0x03;   	// Load high-data to port
      LCD_SET_EN();          	// Write data to LCD
      asm("nop");
      asm("nop");
      asm("nop");
      asm("nop");
      LCD_CLEAR_EN();       	// Disable LCD
      delay_us(40);
      LCD_CLEAR_RW() ;      	// Set LCD to write
      LCD_CLEAR_RS();       	// Set LCD to command
      LCD_SET_EN();          	// Write data to LCD
      asm("nop");
      asm("nop");
      asm("nop");
      asm("nop");
      LCD_CLEAR_EN();        	// Disable LCD
      delay_us(40);
      LCD_SET_EN();          	// Write data to LCD
      asm("nop");
      asm("nop");
      asm("nop");
      asm("nop");
      LCD_CLEAR_EN();        	// Disable LCD
      delay_us(40);
      LCD_WD_PORT = 0x02;
      LCD_SET_EN();          	// Write data to LCD
      asm("nop");
      asm("nop");
      asm("nop");
      asm("nop");
      LCD_CLEAR_EN();        	// Disable LCD
      delay_us(40);
  }
// *************************************** //
//          下面是LCD空闲测试程序          //
// *************************************** //
void LCD_Busy ( void )
  {
      SET_LCD_IN;      			//设置端口为输入
unsigned char tmp;
      do                        //进入读LCD忙标志循环,直到LCD忙标志结束
        {
            LCD_SET_RW();       // 设置LCD为读模式
            LCD_CLEAR_RS();     // 设置RS=0
            LCD_SET_EN();        
//读LCD忙标志(RS=0 RW=1 E=1时候,内部BF传送到D7,BF=0时LCD空闲)
            delay_us(3);       	//延时等待数据
            tmp=LCD_RD_PORT;	//输入数据转TMP暂存.
            LCD_CLEAR_EN();     //这里下面的有点看迷糊,反正外国人资料是这样写的
            LCD_SET_EN();       //不是这样写函数就不能正常
            asm("nop");
            asm("nop");
            LCD_CLEAR_EN();  
        } while(tmp & 0X08);        //BF为0才退出循环等待//while(high & 0x80);
      delay_us(20);
  }
// ************************** //
// *** 写控制指令CMD到LCD *** //
// ************************** //
void LCD_WriteControl (unsigned char CMD)
  {
      LCD_Busy();           	// 测试LCD空闲
      SET_LCD_OUT;          	// LCD 端口定义为输出
      LCD_WD_PORT=(CMD >>4);	// 输出高四位数据到LCD数据端口
      LCD_CLEAR_RW();       	// 设置LCD为写模式
      LCD_CLEAR_RS();       	// 设置LCD为命令模式
      LCD_SET_EN();          	// 激活片选,写命令数据到LCD
      asm("nop");
      asm("nop");
      asm("nop");
      asm("nop");
      LCD_CLEAR_EN();        	// 关闭LCD片选
      LCD_WD_PORT=(CMD&0x0f);	// 输出低四位数据到LCD数据端口
      LCD_CLEAR_RW();       	// 设置LCD为写模式
      LCD_CLEAR_RS();       	// 设置LCD为命令模式
      LCD_SET_EN();          	// 激活片选,写命令数据到LCD
      asm("nop");
      asm("nop");
      asm("nop");
      asm("nop");
      LCD_CLEAR_EN();        	// 关闭LCD片选
  }
// **************************** //
// ***八位数据分2次写入 LCD *** //
// **************************** //
void LCD_WriteData (unsigned char Data)
  {
      LCD_Busy();           	// 测试LCD空闲
      SET_LCD_OUT;          	// LCD 端口定义为输出
      LCD_WD_PORT=(Data >>4); 	// 输出高四位数据到LCD数据端口
      LCD_CLEAR_RW() ;      	// 设置LCD为写模式
      LCD_SET_RS();         	// 设置LCD为数据模式
      LCD_SET_EN();          	// 激活片选,写数据到LCD
      asm("nop");
      asm("nop");
      asm("nop");
      asm("nop");
      LCD_CLEAR_EN();        	// 关闭LCD片选
      LCD_WD_PORT=(Data&0x0f);	// 出低四位数据到LCD数据端口
      LCD_CLEAR_RW() ;      	// 设置LCD为写模式
      LCD_SET_RS();         	// 设置LCD为数据模式
      LCD_SET_EN();          	// 激活片选,写数据到LCD
      asm("nop");
      asm("nop");
      asm("nop");
      asm("nop");
      LCD_CLEAR_EN();        	// 关闭LCD片选
  }
// ********************************* //
// *** Initialize the LCD driver *** //
// ********************************* //
void Init_LCD(void)
  {
      LCD_INIT();
      LCD_WriteControl (LCD_FUNCTION_SET);
      LCD_WriteControl (LCD_OFF);
      LCD_WriteControl (LCD_CLEAR);
      LCD_WriteControl (LCD_MODE_SET);
      LCD_WriteControl (LCD_ON);
      LCD_WriteControl (LCD_HOME);
      //LCD_WriteControl (0x90);
      
  }
// ************************************************ //
// *** Clear the LCD screen (also homes cursor) *** //
// ************************************************ //
void LCD_Clear(void)
  {
      LCD_WriteControl(0x01);
  }
// *********************************************** //
// *** Position the LCD cursor at row 1, col 1 *** //
// *********************************************** //
void LCD_Home(void)
  {
      LCD_WriteControl(0x02);
  }
// ****************************************************************** //
// *** Display a single character, at the current cursor location *** //
// ****************************************************************** //
void LCD_DisplayCharacter (char Char)
  {
      LCD_WriteData (Char);
  }
// ********************************************************************* //
// *** Display a string at the specified row and column, using FLASH *** //
// ********************************************************************* //
void LCD_DisplayString_F (char row, char column , unsigned char __flash *string)
  {
      LCD_Cursor (row, column);
      while (*string)
        {
            LCD_DisplayCharacter (*string++);
        }
  }
// ******************************************************************* //
// *** Display a string at the specified row and column, using RAM *** //
// ******************************************************************* //
void LCD_DisplayString (char row, char column , unsigned char *string)
  {
      LCD_Cursor (row, column);
      while (*string)
          LCD_DisplayCharacter (*string++);
  }
// *************************************************** //
// *** Position the LCD cursor at "row", "column". *** //
// *************************************************** //
void LCD_Cursor (char row, char column)
  {
      switch (row) {
      case 1: LCD_WriteControl (0x80 + column - 1); break;
      case 2: LCD_WriteControl (0xc0 + column - 1); break;
      case 3: LCD_WriteControl (0x94 + column - 1); break;
      case 4: LCD_WriteControl (0xd4 + column - 1); break;
      default: break;
      }
  }
// ************************** //
// *** Turn the cursor on *** //
// ************************** //
void LCD_Cursor_On (void)
  {
      LCD_WriteControl (LCD_CURS_ON);
  }
// *************************** //
// *** Turn the cursor off *** //
// *************************** //
void LCD_Cursor_Off (void)
  {
      LCD_WriteControl (LCD_ON);
  }
// ******************** //
// *** Turn Off LCD *** //
// ******************** //
void LCD_Display_Off (void)
  {
      LCD_WriteControl(LCD_OFF);
  }
// ******************* //
// *** Turn On LCD *** //
// ******************* //
void LCD_Display_On (void)
  {
      LCD_WriteControl(LCD_ON);
  }
大米粥哥哥 2017-08-11
  • 打赏
  • 举报
回复
建议先试着驱动一下lcd 随便让它显示一个值 再显示ad转换的值 网上例程很多 可以对照着看一看

27,381

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 单片机/工控
社区管理员
  • 单片机/工控社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧