⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.c

📁 430 单片机控制产生正玄波输出 周期频率可以调节
💻 C
📖 第 1 页 / 共 2 页
字号:
void LCD_PutStr2( int row, int col,unsigned char *puts) 
{
     unsigned char temp1=0xff;
     unsigned char temp2=1;
     LCD_WriteCommand(0x30);      //8BitMCU,基本指令集合
     if ((row==-1)||(col==-1))//若row=-1和col=-1,接着上次显示完的地方开始显示
     	{
          row=GlobeRow;
     	  col=GlobeCol;
     	 }
     LCD_WriteCommand(AC_TABLE[8*row+col]);      //起始位置
     
     while(*puts != '\0')      //判断字符串是否显示完毕
     {
           if(col==8)            //判断换行
           {            //若不判断,则自动从第一行到第三行
                 col=0;
                 row++;
           }
           if(row==2) 
           {
                row=0;
           	LCD_PutStr(0,0,"                \0");
           	LCD_PutStr(1,0,"                \0");
           	
            }     //一屏显示完,回到屏左上角
           
           if(temp1)     {   //如果是第一个位置输入
               LCD_WriteCommand(AC_TABLE[8*row+col]);//写入待显示字符地址
               if((*puts)>=0xA1)  temp2=1;else temp2=0; //temp2=1为输入的是中文
           }else if((temp2==0)&&(*puts)>=0xA1)  {    //如果是第二个位置输入而且是中文字符的第一个字节,则写入一空格
                    LCD_WriteData(0x20);
                    col++; 
                    temp1=~temp1;
                     continue;
             }
           LCD_WriteData(*puts);      //一个汉字要写两次
           puts++;
           temp1=~temp1;
           if(temp1)  col++; 
         
       }
     if(temp1=~temp1)  col++;
     GlobeRow=row; GlobeCol=col; //记录当前位置
     
}

//显示一个字符串,row=-1和col=-1,接着上次显示完的地方开始显示,满三行清屏
void LCD_PutStr3( int row, int col,unsigned char *puts) 
{
     unsigned char temp1=0xff;
     unsigned char temp2=1;
     LCD_WriteCommand(0x30);      //8BitMCU,基本指令集合
     if ((row==-1)||(col==-1))//若row=-1和col=-1,接着上次显示完的地方开始显示
     	{
          row=GlobeRow;
     	  col=GlobeCol;
     	 }
     LCD_WriteCommand(AC_TABLE[8*row+col]);      //起始位置
     
     while(*puts != '\0')      //判断字符串是否显示完毕
     {
           if(col==8)            //判断换行
           {            //若不判断,则自动从第一行到第三行
                 col=0;
                 row++;
           }
           if(row==3) 
           {
                row=0;
           	LCD_PutStr(0,0,"                \0");
           	LCD_PutStr(1,0,"                \0");
           	LCD_PutStr(2,0,"                \0");
            }     //一屏显示完,回到屏左上角
           
           if(temp1)     {   //如果是第一个位置输入
               LCD_WriteCommand(AC_TABLE[8*row+col]);//写入待显示字符地址
               if((*puts)>=0xA1)  temp2=1;else temp2=0; //temp2=1为输入的是中文
           }else if((temp2==0)&&(*puts)>=0xA1)  {    //如果是第二个位置输入而且是中文字符的第一个字节,则写入一空格
                    LCD_WriteData(0x20);
                    col++; 
                    temp1=~temp1;
                     continue;
             }
           LCD_WriteData(*puts);      //一个汉字要写两次
           puts++;
           temp1=~temp1;
           if(temp1)  col++; 
         
       }
     if(temp1=~temp1)  col++;
     GlobeRow=row; GlobeCol=col; //记录当前位置
     
}
//显示一个字节的数据,row=-1和col=-1,接着上次显示完的地方开始显示,满4行翻屏
void LCD_PutChar (  int row, int col,unsigned char put) 
{
     LCD_WriteCommand(0x30);      //8BitMCU,基本指令集合
	   if ((row==-1)||(col==-1))//若row=-1和col=-1,接着上次显示完的地方开始显示
     	{
          row=GlobeRow;
     	  col=GlobeCol;
     	
     	 }
     if(col==8)    //判断换行
        {          //若不判断,则自动从第一行到第三行
           col=0;
           row++;
        }
     if(row==4) {row=0;LCD_LcmClearTXT();}      //一屏显示完,回到屏左上角,并清屏
     LCD_WriteCommand(AC_TABLE[8*row+col]);
     LCD_WriteData(put); 

     GlobeRow=row; GlobeCol=col+1;	//记录当前位置   **** 
}

//显示一个字节的数据,row=-1和col=-1,接着上次显示完的地方开始显示,满3行翻屏
void LCD_PutChar3 (  int row, int col,unsigned char put) 
{
     LCD_WriteCommand(0x30);      //8BitMCU,基本指令集合
     if ((row==-1)||(col==-1))//若row=-1和col=-1,接着上次显示完的地方开始显示
       {
         row=GlobeRow;
     	 col=GlobeCol;
        }
    if(col==8)    //判断换行
       {          //若不判断,则自动从第一行到第三行
          col=0;
          row++;
       }
     if(row==3)  //一屏显示完,回到屏左上角,清空前三行 
     {
          row=0;
          LCD_PutStr(0,0,"                \0");
          LCD_PutStr(1,0,"                \0");
          LCD_PutStr(2,0,"                \0");
     }      
     LCD_WriteCommand(AC_TABLE[8*row+col]);
     LCD_WriteData(put); 

     GlobeRow=row; GlobeCol=col+1;//记录当前位置    
}


void LCD_PutBMP(unsigned char *puts)
{
     unsigned int x=0;
     unsigned char i,j;
     LCD_WriteCommand(0x34);      //8Bit扩充指令集,即使是36H也要写两次
     LCD_WriteCommand(0x36);      //绘图ON,基本指令集里面36H不能开绘图
     for(i=0;i<32;i++)            //128x64实际为256x32
     {
           LCD_WriteCommand(0x80|i);      //行位置
           LCD_WriteCommand(0x80);      //列位置
           for(j=0;j<32;j++)      //256/8=32 byte
           {            //列位置每行自动增加
                 LCD_WriteData(puts[x]);
                 x++;
           }
     }
}

//电子测试用点阵显示
void LCD_DisplayDots(unsigned char DotByte)
{
     unsigned char i,j;
     LCD_WriteCommand(0x34);      //8Bit扩充指令集,即使是36H也要写两次
     LCD_WriteCommand(0x36);      //绘图ON,基本指令集里面36H不能开绘图
     for(i=0;i<32;i++)            //12864实际为256x32
     {
           LCD_WriteCommand(0x80|i);      //行位置
           LCD_WriteCommand(0x80);      //列位置
           for(j=0;j<32;j++)      //256/8=32 byte
           {            //列位置每行自动增加
                 LCD_WriteData(DotByte);                  
           }
           DotByte=~DotByte;
     }
}

//显示一个INT型的数据,row=-1和col=-1,接着上次显示完的地方开始显示,满4行翻屏
void LCD_PutNum (  int row, int col,unsigned int num) 
{
	
	unsigned char numbuff[]={"      "};

  char i,j;

  numbuff[5]='\0';
  for (i=5;i>0;i--)
  {
  	numbuff[i-1]=num-num/10*10+0x30;
  	num=num/10;
  }
  j=0;
  while(numbuff[j]==0X30)
   j++;
  for (i=0;i<(5-j)+1;i++)
    numbuff[i]=numbuff[i+j];
  for (;i<6;i++)
    numbuff[i]='\0';
   LCD_PutStr(row ,col,numbuff);

	
}

/***************************************************************
显示一个无符号 长整型 数据
*****************************************************************/
void LCD_PutNum_l (  int row, int col,unsigned long num) 
{
	
	unsigned char numbuff[]={"            "};

  unsigned char i,j;

  numbuff[8]='\0';
  for (i=8;i>0;i--)
  {
  	numbuff[i-1]=num-num/10*10+0x30;
  	num=num/10;
  }
  j=0;
  while(numbuff[j]==0X30)
   j++;
  for (i=0;i<(8-j)+1;i++)
    numbuff[i]=numbuff[i+j];
  for (;i<9;i++)
    numbuff[i]='\0';
   LCD_PutStr(row ,col,numbuff);

	
}

/********************************************************************************************
     初始化液晶
**********************************************************************************************/
void LCD_LcmInit( void )
{   
     PSB_OUT;   //设置PSB为低电平
     PSB_L;
     LCD_WriteCommand(0x30);      //8BitMCU,基本指令集合
     LCD_WriteCommand(0x03);      //AC归0,不改变DDRAM内容
     LCD_WriteCommand(0x0C);      //显示ON,游标OFF,游标位反白OFF
     LCD_WriteCommand(0x01);      //清屏,AC归0
     LCD_WriteCommand(0x06);      //写入时,游标右移动
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -