weixin_55648640
飞飞飞797
采纳率0%
2021-03-01 12:43

keil3+Proteus7.7,帮孩子改改代码,实现电压值能显示在LCD上,要附带注释。

50
已结题

太折磨了,不知道问题出在哪

  1. 程序段
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint  unsigned int
void delay( );
void delayms( uchar  );
void Busy_Check();
void lcd_wdat( uchar );
void lcd_wcmd (uchar );
void SetLine(uchar );
void SetColumn(uchar );
void SetStartLine(uchar );
void disOn_Off( uchar );
void SelectScreen(uchar );
void ClearScreen(uchar );
void Disp_Sinogram(uchar ss,uchar page,uchar column,uchar number );
void Disp_digital(uchar ss,uchar page,uchar column,uchar number );
void lcd_reset(); 
void lcd_init();
void volt_result();
void ADC_read(uint CH);
void delay( uchar  ); 
void operation (uint);
void display(  );
sbit rs=P2^0;
sbit rw=P2^1;
sbit ep=P2^2;
sbit cs1=P2^3;
sbit cs2=P2^4;
sbit rst=P2^5;
sbit cs=P1^0;
sbit clk=P1^3;
sbit SDI=P1^4;
sbit SDO=P1^5;
sbit bit7=B^7;
sbit a=P2^6;
bit  cy;
uint adval,c,d;
float volt;
uchar b;
uchar temp;
char temp_bit;
uchar code Hzk[100];
uchar code Ezk[100];
char str_show[6]={0,1,2,3,4,5};
char str[6]={0};
uchar tab[]={0xC9,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
void main(void)
{
   			
    lcd_init();			 //lcd初始化
    ClearScreen(0);		 //lcd清屏
    SetStartLine(0);	 //开始行
    while(1)
     {
      ADC_read(0);
	  delayms(1);
	  display();
	  }
}
void display()
{
  uint i;
  if(a==1)
        
        for(i=0;i<4;i++)
      {
       Disp_Sinogram(2,0,i*16,i);
       _nop_();
       Disp_Sinogram(2,0+2,i*16,i+4);
       _nop_();
       Disp_Sinogram(2,0+2+2,i*16,i+8);
       _nop_();
	   Disp_digital(1,0,i*8,i); 
       }
  else      
		for(i=0;i<4;i++)
      {
       Disp_Sinogram(2,0,i*16,i+12);
       _nop_();
       Disp_Sinogram(2,0+2,i*16,i+16);
       _nop_();
       Disp_Sinogram(2,0+2+2,i*16,i+20);
       _nop_();	   
      } 
}
void Disp_digital(uchar ss,uchar page,uchar column,uchar number )  // ss  选屏幕 page  选页数column  选列数 number	选第几个数字
{
    uint i;
    SelectScreen( ss );		  //选屏幕
    column=column&0x3f;
    SetLine( page );		  //选页函数
    SetColumn( column );	  //选列数
    for(i=0;i<8;i++)
    {
     lcd_wdat(str_show[i+16*number]);  //字符上半部分输出
    }
	 SetLine(page+1);          //下半部分输出
    SetColumn( column );
    for(i=0;i<8;i++)
     {
      lcd_wdat(str_show[i+16*number+8]);
     }
    
}
void Disp_Sinogram( uchar ss,uchar page,uchar column,uchar number )	  //显示汉字
{
    int i;
    SelectScreen( ss );
    column=column&0x3f;
    SetLine( page );
    SetColumn( column );
    for(i=0;i<16;i++)
    {
     lcd_wdat(Hzk[i+32*number]);
    }
    SetLine(page+1);
    SetColumn( column );
    for(i=0;i<16;i++)
     {
      lcd_wdat(Hzk[i+32*number+16]);
     }
    }
void ADC_read(uint CH)  //TLC2543转换
{
   uchar i;
   clk=0;
   cs=1;
   delay();
   cs=0;
   B=CH;
  for(i=8;i>0;i--)
    {
       cy=SDO;
       SDI=bit7;
       clk=1;
       B=B<<1;
       clk=0;
       temp=temp<<1;
       if(cy==1)
           temp++;
       
    }
   adval=temp;
   adval=adval<<4;
     for(i=4;i>0;i--)
       {
           cy=SDO;
           temp=temp<<1;
           if(cy==1)
                  temp++;
             clk=1;
             clk=0; 
       }
   cs=1;
   adval=adval+temp; 
  volt=(adval*5.0)/4095;
  temp=volt*1000;//浮点电压为了保存3位小数,乘以1000.
  temp_bit=0;         //用来每次取模得到的数暂存
  temp_bit=temp%10;					   
  temp=temp/10;
  str[5]=temp_bit;					 //千分
  temp_bit=temp%10;
  temp=temp/10;
  str[4]=temp_bit;					//百分
  temp_bit=temp%10;
  temp=temp/10;
  str[3]=temp_bit;					//十分
  temp_bit=temp%10;
  temp=temp/10;
  str[2]='.';
  str[1]=temp_bit;				   //个位
  temp_bit=temp%10;
  str[0]=temp_bit;
                                //把str[i]中的数字值转换成ascii码,存入str_show[]这个数组
for(i=0;i<6;i++)
{
if(str[i]!='.')
str_show[i]=str[i]+'0';
else
str_show[i]=str[i];
}

}
void delay( )					//小延时
{
  uint i=5;
  while(i--);
}
 void delayms(uchar ms)			 //延时
{
     uchar i;
	 while(ms--)
	 {
	   for(i=0;i<120;i++);
	 }
}
void Busy_Check()				//检查LCD是否忙碌
{
      uchar LCD_Status;			//状态信息检查
	  rs=0;					    //rs=0,指令数据
      rw=1;					    //rw=0,读状态,当ep=1是数据被读到DB7-DB0
	  do{
        P0=0x00;
        ep=1;
        _nop_();				//时钟延时
        LCD_Status=P0;
        ep=0;
        LCD_Status=0X80&LCD_Status;		 //第七位为0时才能操作
        }while(!(LCD_Status==0x00));
}
void lcd_wcmd (uchar cmd) 		 //写入指令数据到LCD
{
      Busy_Check();				 //等待空闲
      rs=0;						 //rs=0写指令
      rw=0;						 //rw=0,ep由1变0指令写入
      ep=0;
      _nop_();
      _nop_();
      P0=cmd;					 //数据传输至P0
      _nop_();
      _nop_();
      _nop_();
      _nop_();
      ep=1;						 //ep=1,ep=0,一个脉冲
      _nop_();
      _nop_();
      _nop_();
      _nop_();
      ep=0;
}
void lcd_wdat( uchar dat)		 //写显示数据
{
      Busy_Check();				 //等待LCD空闲
      rs=1;						 //rs=1写数据
      rw=0;						 //rw=0写
      P0=dat;
      _nop_();
      _nop_();
      _nop_();
      _nop_();
      ep=1;
      _nop_();
      _nop_();
      _nop_();
      _nop_();
      ep=0;
}
void SetLine(uchar page)		//设置LCD页地址
{
page=0xb8|page;				   //格式1011 1xxx,xxx为页数共八页
lcd_wcmd(page);				 //写入
}
void SetStartLine(uchar startline)	  //写行地址
{
startline=0xc0|startline;			  //格式 11xx xxxx 	   64行
lcd_wcmd(startline);
}
void SetColumn(uchar column)		 //设置列地址
{
    column=column&0x3f;				 //格式 01xx xxxx       64列
    column=0x40|column;
    lcd_wcmd(column);
}
void disOn_Off( uchar onoff)	//开关显示程序 0X3E关闭 0X3F开启
{
    onoff =0x3e|onoff;
    lcd_wcmd(onoff);
}
void SelectScreen(uchar NO)	   // 屏幕选择
{
    switch (NO)
     {
      case 0:				   //全屏 cs1,cs2=0
        cs1=0;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        cs2=0;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        break;
      case 1:
        cs1=1;				  //左屏 cs2=0
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        cs2=0;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        break;
        case 2:				  //右屏幕 CS1=0
        cs1=0;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        cs2=1;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        break;
        default:
        break;
  }
}
void ClearScreen(uchar screen)	 // 清理屏幕
{
        uchar i,j;
        SelectScreen(screen);
        for(i=0;i<8;i++)		 // 选择页数
        {
         SetLine(i);
         SetColumn(0);
          for(j=0;j<64;j++)		// 选择列数
          {
           lcd_wdat(0x00);		 //列地址加一
           }
         }
}

void lcd_reset()		   // lcd复位
{
    rst=0;
    delayms(20);
    rst=1;
    delayms(20);
}
void lcd_init()			  // LCD初始化
{
    lcd_reset();		  //复位
    Busy_Check();		  //等待lcd空闲
    SelectScreen(0);	  //选择屏幕
    disOn_Off(0);		  //关闭全屏
    SelectScreen(0); 
    disOn_Off(1);  		  //开启全屏
    SelectScreen(0);
    ClearScreen(0);		  //清屏
    SetStartLine(0);	  //设置初始行
}
uchar code Hzk[ ]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",1*/
0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,
0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,
0x00,0x00,0x0F,0x08,0x08,0x08,0x08,0xFF,
0x88,0x88,0x88,0x88,0x8F,0x80,0xF0,0x00,/*"电",2*/
0x00,0x00,0xFE,0x02,0x82,0x82,0x82,0x82,
0xFA,0x82,0x82,0x82,0x82,0x82,0x02,0x00,
0x00,0x70,0x1F,0x40,0x40,0x40,0x40,0x40,
0x7F,0x40,0x40,0x44,0x48,0x50,0x40,0x00,/*"压",3*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",4*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",5*/
0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,
0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,
0x00,0x00,0x0F,0x08,0x08,0x08,0x08,0xFF,
0x88,0x88,0x88,0x88,0x8F,0x80,0xF0,0x00,/*"电",6*/
0x10,0x60,0x02,0x8C,0x00,0x44,0x64,0x54,
0x4D,0x46,0x44,0x54,0x64,0xC4,0x04,0x00,
0x04,0x04,0x7E,0x01,0x00,0x40,0x7E,0x00,
0x00,0x7E,0x00,0x00,0x7E,0x40,0x60,0x00,/*"流",7*/
0x04,0x04,0x04,0x04,0x84,0xE4,0x3C,0x27,
0x24,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,
0x00,0x04,0x02,0x01,0x00,0xFF,0x09,0x09,
0x09,0x09,0x49,0x89,0xFF,0x00,0x00,0x00,/*"有",8*/
0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x10,
0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,
0x20,0x30,0x10,0x1F,0x08,0x88,0x48,0x30,
0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,/*"功",9*/
0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x10,
0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,
0x20,0x30,0x10,0x1F,0x08,0x88,0x48,0x30,
0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,/*"功",10*/
0x00,0x28,0x48,0x88,0x48,0x69,0x5A,0xCC,
0x48,0x28,0x08,0x88,0x48,0x28,0x00,0x00,
0x00,0x12,0x11,0x10,0x12,0x12,0x13,0xFA,
0x12,0x13,0x16,0x10,0x11,0x12,0x10,0x00,/*"率",11*/
0x10,0x10,0x12,0xDC,0x30,0x00,0x00,0xFC,
0x04,0x04,0xE4,0x04,0x04,0xFC,0x00,0x00,
0x04,0x02,0x01,0xFF,0x01,0x06,0x80,0x47,
0x30,0x0C,0x03,0xFC,0x80,0x87,0xC0,0x00,/*"视",12*/
0x08,0x08,0x88,0xC8,0x38,0x0C,0x0B,0x08,
0x08,0xE8,0x08,0x08,0x08,0x08,0x08,0x00,
0x02,0x01,0x00,0xFF,0x40,0x41,0x41,0x41,
0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00,/*"在",13*/
0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x10,
0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,
0x20,0x30,0x10,0x1F,0x08,0x88,0x48,0x30,
0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,/*"功",14*/
0x00,0x28,0x48,0x88,0x48,0x69,0x5A,0xCC,
0x48,0x28,0x08,0x88,0x48,0x28,0x00,0x00,
0x00,0x12,0x11,0x10,0x12,0x12,0x13,0xFA,
0x12,0x13,0x16,0x10,0x11,0x12,0x10,0x00,/*"率",15*/
0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x10,
0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,
0x20,0x30,0x10,0x1F,0x08,0x88,0x48,0x30,
0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,/*"功",16*/
0x00,0x28,0x48,0x88,0x48,0x69,0x5A,0xCC,
0x48,0x28,0x08,0x88,0x48,0x28,0x00,0x00,
0x00,0x12,0x11,0x10,0x12,0x12,0x13,0xFA,
0x12,0x13,0x16,0x10,0x11,0x12,0x10,0x00,/*"率",17*/
0x00,0xFE,0x02,0x42,0x42,0x42,0x42,0xFA,
0x42,0x42,0x42,0x42,0x02,0xFE,0x00,0x00,
0x00,0xFF,0x40,0x50,0x48,0x44,0x43,0x40,
0x41,0x42,0x44,0x58,0x40,0xFF,0x00,0x00,/*"因",18*/
0x90,0x52,0x34,0x10,0xFF,0x10,0x34,0x52,
0x80,0x70,0x8F,0x08,0x08,0xF8,0x08,0x00,
0x02,0x9A,0xD6,0x63,0x22,0x52,0x0E,0x00,
0x80,0x40,0x33,0x0C,0x33,0x40,0x80,0x00,/*"数",19*/
0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,
0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,
0x00,0x00,0x0F,0x08,0x08,0x08,0x08,0xFF,
0x88,0x88,0x88,0x88,0x8F,0x80,0xF0,0x00,/*"电",20*/
0x08,0xCC,0x4A,0x49,0x48,0x4A,0xCC,0x18,
0x00,0x7F,0x88,0x88,0x84,0x82,0xE0,0x00,
0x00,0xFF,0x12,0x12,0x52,0x92,0x7F,0x00,
0x00,0x7E,0x88,0x88,0x84,0x82,0xE0,0x00,/*"能",21*/
0x10,0x60,0x02,0x0C,0xC0,0x00,0xE2,0x2C,
0x20,0x3F,0x20,0x28,0xE6,0x00,0x00,0x00,
0x04,0x04,0xFC,0x03,0x00,0x00,0xFF,0x09,
0x09,0x09,0x49,0x89,0xFF,0x00,0x00,0x00,/*"消",22*/
0x88,0xA8,0xA8,0xFF,0xA8,0xA8,0x88,0x00,
0x44,0x44,0xFC,0x22,0x23,0x22,0x00,0x00,
0x20,0x18,0x06,0xFF,0x02,0x0C,0x00,0x04,
0x04,0x04,0xFF,0x82,0x82,0x82,0xF2,0x00};/*"耗",23*/

Proteus运行问题图

 

  • 点赞
  • 收藏
  • 复制链接分享

2条回答

  • bill20100829 歇歇 1月前
    点赞 评论 复制链接分享
  • niushaolongniuniu niushaolongniuniu 1月前

    只有汉字库,没有字符库,做个字符库。

    点赞 评论 复制链接分享

为你推荐