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

📄 lcddrv.c

📁 spce061A驱动的128*64点阵液晶程序
💻 C
字号:
#include"lcddrv.h"

void chk_busy();
void write_com(unsigned char cmdcode);
void write_data(unsigned char Dispdata);

void cur_on()//开光标
{
 write_com(0x0f);
}

void cur_off()//关光标
{
 write_com(0x0a);
}
void location(unsigned char x,unsigned char y)//设置光标位置
{
  unsigned char com = 0x80;

  if(1 == (y & 0x03))
      y = 2;
  else if((y & 0x03) == 2)
      y = 1;
  com |= (y & 0x03) << 3;
  com += x & 0x07;
  write_com(com);
}
void print(unsigned char *str)//打印字串,不换行
{
 while(*str>0){
      write_data(*str);
      str++;
 }
}
void inv_line(unsigned char lin,unsigned char datav)//反白一行
{
 unsigned short i,j;
 write_com(0x36);
 if(lin == 0){
     for(i = 0;i < 8;i++)
           for(j = 0;j < 16;j++){
                 write_com(j+0x80);        //行地址
                 write_com(i+0x80);     //列地址
                 write_data(datav);
                 write_data(datav);
            }
 }
 if(lin == 1){
      for(i = 0;i < 8;i++)
           for(j = 16;j < 32;j++){
                 write_com(j+0x80);        //行地址
                 write_com(i+0x80);     //列地址
                 write_data(datav);
                 write_data(datav);
            }
 }
 if(lin == 2){
      for(i = 8;i < 16;i++)
           for(j = 0;j < 16;j++){
                 write_com(j+0x80);        //行地址
                 write_com(i+0x80);     //列地址
                 write_data(datav);
                 write_data(datav);
            }
 }
 if(lin == 3){
        for(i = 8;i < 16;i++)
           for(j = 16;j < 32;j++){
                 write_com(j+0x80);        //行地址
                 write_com(i+0x80);     //列地址
                 write_data(datav);
                 write_data(datav);
            }
 }
 write_com(0x30);
}

void lin(unsigned char x1,unsigned char x2,unsigned char y1,unsigned char y2)
{}
void point(unsigned char x,unsigned char y)//画点
{
 unsigned char xx,tmp;
 //计算点所在字节坐标
 xx = x / 8;
 y = y & 0x7f;
 //读取字节
 write_com(0x36);
 write_com(0x80 | y);
 write_com(0x80 | xx);
 write_com(0x80);
 E = 1;
 E = 0;
 E = 1;
 RS = 1;
 RW = 1;
 Lcd_Bus=0xff;
 tmp = Lcd_Bus;
 E = 0;
 //计算位
 tmp += 0x01 << (7 - x % 8);
 tmp = 0xff;
 //开始画点
 xx = x;
 write_com(0x36);
 write_com(0x80 | y);
 write_com(0x80 + xx);
 write_com(0x30);
 write_data(tmp);
 write_data(tmp);
 write_data(tmp);
}

void cls()//清屏
{
     unsigned char x,y;
     for(y=0;y<64;y++)
        for(x=0;x<16;x++){
           write_com(0x34);
           write_com(y+0x80);        //行地址
           write_com(x+0x80);     //列地址
           write_com(0x30);
           write_data(0x00);
           write_data(0x00);
        }
     write_com(0x01);
}


/*------------------检查忙位-----------------------------*/
void chk_busy()
{
   RS=0;
   RW=1;
   E=1;
   Lcd_Bus=0xff;
   while((Lcd_Bus&0x80)==0x80);
   E=0;
}
/*------------------写命令到LCD------------------------------*/
void write_com(unsigned char cmdcode)
{
	chk_busy();
	RS=0;
	RW=0;
	E=1;
	Lcd_Bus=cmdcode;
	E=0;
}
/*-------------------写数据到LCD----------------------------*/
void write_data(unsigned char Dispdata)
{
	chk_busy();
	RS=1;
	RW=0;
	E=1;
	Lcd_Bus=Dispdata;
	E=0;
}
/*------------------初始化LCD屏--------------------------*/
void lcd_init()
{
   write_com(0x30);       //选择基本指令集
   write_com(0x30);       //选择8bit数据流
   write_com(0x0c);       //开显示(无游标、不反白)
   write_com(0x01);       //清除显示,并且设定地址指针为00H
   write_com(0x06);       //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位
}

⌨️ 快捷键说明

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