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

📄 lcd_tri_12864.c

📁 FPGA应用如sd卡控制
💻 C
字号:

#include "alt_types.h"
#include "distable.h"
#include "lcd_tri_12864.h"
#include "lcd_tri_12864_regs.h"
//#include "ziku.h"
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include <string.h>
#include <stdio.h>
#include <unistd.h>
//#define LCD_CS *( unsigned char *)LCD12864_CS_BASE
alt_u8  busy;

static void LCD_CS(unsigned char data)
{
 IOWR_ALTERA_AVALON_PIO_DATA(LCD12864_CS_BASE, data);
}

unsigned char LcdChkBusy(unsigned int base)
 {
    alt_u32 i = 1000000;
   while (IORD_LCD_STATUS(base) & 0x80)//_8DIRECT(LCD_12864_0_BASE,0x1) & 0x80)
    if (--i == 0)
    {
      busy=1;
      return 1;
    } 
    busy=0;
    return 0;
  }
 
static void lcd_write_cmd(unsigned int base, unsigned char command)
 {
  //if(LcdChkBusy(base))
   if(busy)
   return;
   usleep(20);
   IOWR_LCD_COMMAND(base,command);
 }
 
 static void lcd_write_data(unsigned int base, unsigned char data)
 { 
// if(LcdChkBusy(base))
   if(busy)
   return;
   usleep(20);
 IOWR_LCD_DATA(base, data);
 }
 

 
//*************12864LCD***********
 
 
 
 void Lcd12864Init(unsigned int base)//初始化.
 {
  LCD_CS(0x3);
  LcdChkBusy(base);
  lcd_write_cmd(base,0xc0);
  usleep(20);
  lcd_write_cmd(base,0x3f);
   usleep(200);
 }
 
 /*带字库LCD清屏
 void Lcd12864Clear(unsigned int base)//清屏
 {
  lcd_write_cmd(base,0x01);
  usleep(2000);
  }
 */
 
 
  void Lcd12864Clear(unsigned int base)//清屏
 {
  unsigned char PageTmp,ColumnTmp,CmdTmp;
  LCD_CS(0x3);
   for(PageTmp=0;PageTmp<8;PageTmp++)
    {
    CmdTmp=PageTmp|0xb8;   //页地址
      lcd_write_cmd(base,CmdTmp);  
      lcd_write_cmd(base,0x40);
     for(ColumnTmp=0x0;ColumnTmp<0x40;ColumnTmp++)//64行
         {
        lcd_write_data(base,0);
      }    
   }
  }
 
 
void DisChar(unsigned int base,unsigned char PageAddrP,unsigned char RowAddrP,
unsigned int DisDatP,unsigned char cs)
 {
   unsigned char cc,PageTmp,RowTmp;
   unsigned int  TabTmp;
   LCD_CS(cs);
   PageTmp=PageAddrP|0xb8;//0xb8为设置页地址,如果为0xc0则是设置行地址,如果是行,总共有64行。
   RowTmp =RowAddrP+0x40;
   TabTmp =DisDatP-0x20;
   TabTmp*=5;
   lcd_write_cmd(base,PageTmp);
   lcd_write_cmd(base,RowTmp);
   for(cc=0;cc<5;cc++)  //写入5列地址,第个字符占5列
    { 
       lcd_write_data(base,ziku[TabTmp+cc]);
     }
    
  }
  
void Disstring(unsigned int base,unsigned char *str,unsigned int len, unsigned char PageAddrP,unsigned char RowAddrP,unsigned char cs)
 {
   unsigned char i,OffSetTmp;
   for(i=0;i<len;i++)       //共12个字符
    {
       OffSetTmp=i*5;  //一个字符用了5列
       DisChar(base,PageAddrP,OffSetTmp+RowAddrP,str[i],cs);
      }
  }
  
  

  
  
   //Dishaizi(PageAddrP:LCD页数0~7页,RowAddrP:起始列即从第几列开始显示,DisDatP:显示数组中的第N+1个字,
  //CS:1为选择左屏2为右屏,haizi[]:要显示的汉字数组名) 
void Dishaizi1(unsigned int base ,unsigned char PageAddrP,unsigned char RowAddrP,unsigned int DisDatP,
    unsigned char cs  ,unsigned char haizi[])
 {
  LCD_CS(cs);
   unsigned char cc,PageTmp,RowTmp;
   unsigned int  TabTmp;//列数存储变量
   PageTmp=PageAddrP|0xb8;//0xb8为设置页地址指令,每8行一页,如果为0xc0则是设置行地址,如果是行,总共有64行。
   RowTmp =RowAddrP+0x40;//0x40为设置列地址指令
   TabTmp=DisDatP*32;//DisDatP为数组中是第N+1个籽,每个汉字占32列,所以显示完一个汉字后,TabTmp+32
   lcd_write_cmd(base,PageTmp);//写入页地址
   lcd_write_cmd(base,RowTmp);//写入列地址
    for(cc=0;cc<15;cc++)  //一个汉字32列,使用字模提取V2.1获取的字模
    {    
       lcd_write_data(base,haizi[TabTmp+cc]);  //读取数组中的汉字
     }
  }
 
void Dishaizi2(unsigned int base ,unsigned char PageAddrP,unsigned char RowAddrP,unsigned int DisDatP,
    unsigned char cs  ,unsigned char haizi[])
 {
  LCD_CS(cs);
   unsigned char cc,PageTmp,RowTmp;
   unsigned int  TabTmp;//列数存储变量
   PageTmp=PageAddrP|0xb8;//0xb8为设置页地址指令,每8行一页,如果为0xc0则是设置行地址,如果是行,总共有64行。
   RowTmp =RowAddrP+0x40;//0x40为设置列地址指令
   TabTmp=DisDatP*32;//DisDatP为数组中是第N+1个籽,每个汉字占32列,所以显示完一个汉字后,TabTmp+32
   lcd_write_cmd(base,PageTmp);//写入页地址
   lcd_write_cmd(base,RowTmp);//写入列地址
    for(cc=16;cc<31;cc++)  //一个汉字32列,使用字模提取V2.1获取的字模
    {    
       lcd_write_data(base,haizi[TabTmp+cc]);  //读取数组中的汉字
     }
     // LCD_CS=0;
  }

void Dishaizi(unsigned int base ,unsigned char PageAddrP,unsigned char RowAddrP,unsigned int DisDatP,
    unsigned char cs  ,unsigned char haizi[])
   {
    Dishaizi1(base,PageAddrP  ,RowAddrP,DisDatP,cs,haizi);
    Dishaizi2(base,PageAddrP+1,RowAddrP,DisDatP,cs,haizi);
   }

void Disstring_line(unsigned int base,unsigned char *str,unsigned char len, unsigned char PageAddrP)
 {
   unsigned char i,OffSetTmp;
 //  unsigned int len=strlen(str);
    if(len<12)
     for(i=0;i<len;i++)       
      {
       OffSetTmp=i*5;  //一个字符用了5列
       DisChar(base,PageAddrP,OffSetTmp,str[i],1);
      }
     else {   
          for(i=0;i<12;i++)       //左半屏
             {
             OffSetTmp=i*5;  //一个字符用了5列
             DisChar(base,PageAddrP,OffSetTmp+2,str[i],1);
             }
          for(i=12;i<len;i++)       //右半屏
             {
              OffSetTmp=(i-12)*5;  //
              DisChar(base,PageAddrP,OffSetTmp,str[i],2);
             }
            }
               
  }







⌨️ 快捷键说明

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