|
#include "12864.h"
#include "delay.h"
#include
#include
//uint8_t Lcd_Con_X_Y[4][2]={{0x80,0x80},{0x80,0x90},{0x88,0x80},{0x88,0x90}}; //LCD行反白显示坐标
/******************************************************************************
*****************************基本指令集***************************************
*清显示:0x01
*地址归位:0x02 0x03
*
*/
/*****************************************************************************/
//初始化LCM
void LCD_Init(bit Mode)
{
LCD_RST=1; //RST低电平有效
LCD_PSB=Mode; //PSB=0串行模式 PSB=1并行模式
LCM_SWriteDatOrCom (0,0x30); //30---基本指令动作
LCM_SWriteDatOrCom (0,0x01); //清屏,地址指针指向00H
delay_us(100);
LCM_SWriteDatOrCom (0,0x06); //光标的移动方向
LCM_SWriteDatOrCom(0,0x0c); //开显示,关游标
LCD_BL=0;
}
//写指令或数据 (0,指令) (1,数据)串行时序
void LCM_SWriteDatOrCom(bit dat_comm,uint8_t content)
{
uint8_t a,i,j;
delay_us(50);
a=content;
LCD_RS=1;
LCD_EN=0;
LCD_RW=1;
for(i=0;i<5;i++)
{
LCD_EN=1;
LCD_EN=0;
}
LCD_RW=0;
LCD_EN=1;
LCD_EN=0;
if(dat_comm)
LCD_RW=1; //data
else
LCD_RW=0; //command
LCD_EN=1;
LCD_EN=0;
LCD_RW=0;
LCD_EN=1;
LCD_EN=0;
for(j=0;j<2;j++)
{
for(i=0;i<4;i++)
{
a=a<<1;
LCD_RW=CY;
LCD_EN=1;
LCD_EN=0;
}
LCD_RW=0;
for(i=0;i<4;i++)
{
LCD_EN=1;
LCD_EN=0;
}
}
}
/*********************************************************/
/* */
/* 设定显示位置 */
/* */
/*********************************************************/
void LCD_Pos(uint8_t X,uint8_t Y)
{
uint8_t pos;
if (X==1)
{X=0x80;}
else if (X==2)
{X=0x90;}
else if (X==3)
{X=0x88;}
else if (X==4)
{X=0x98;}
pos = X+Y ;
LCM_SWriteDatOrCom(0,pos); //显示地址
}
/*****************************************************************************/
void chn_disp (uint8_t code *chn)
{
uint8_t i,j;
LCM_SWriteDatOrCom (0,0x30);
LCM_SWriteDatOrCom (0,0x80);
for (j=0;j<4;j++) //4行
{
for (i=0;i<16;i++) //16列
LCM_SWriteDatOrCom (1,chn[j*16+i]);
}
}
/*****************************************************************************/
//清屏函数
void LCD_Clr(void)
{
LCM_SWriteDatOrCom (0,0x30);
LCM_SWriteDatOrCom (0,0x01);
delay_us(180);
}
/*****************************************************************************/
//向LCM发送一个字符串,长度64字符之内。
//应用:LCM_WriteString("您好!");
void LCM_WriteString(unsigned char *str)
{
while(*str != '\0')
{
LCM_SWriteDatOrCom(1,*str++);
}
*str = 0;
}
////任意行反白/取消反白
//void con_disp (uint8_t _line,uint8_t enable)
// {
// uint8_t i,j;
// for(j=0;j<16;j++) //每个中文字符占16个点
// {
// for(i=0;i<8;i++) //8个中文字符宽度,即LCD的一行
// {
// LCM_SWriteDatOrCom(0,0x36); //扩充指令集
// LCM_SWriteDatOrCom(0,Lcd_Con_X_Y[_line][1]+j);
// LCM_SWriteDatOrCom(0,Lcd_Con_X_Y[_line][0]+i);
// LCM_SWriteDatOrCom(0,0x30);
// if(enable==1) //使能指定行反白
// {
// LCM_SWriteDatOrCom(1,0xff);
// LCM_SWriteDatOrCom(1,0xff);
// }
// else //还原指定反白行
// {
// LCM_SWriteDatOrCom(1,0x00);
// LCM_SWriteDatOrCom(1,0x00);
// }
// }
// }
// LCM_SWriteDatOrCom(0,0x36);
// LCM_SWriteDatOrCom(0,0x30);
// }
//void con_disp(uint8_t data1,uint8_t data2,uint8_t x0,uint8_t y0,uint8_t xl,uint8_t yl)
// {
// u i,j;
// for(j=0;j
// {
// for(i=0;i
// {
// LCM_SWriteDatOrCom(comm,0x34);//0x34
// LCM_SWriteDatOrCom(comm,y0+j);
// LCM_SWriteDatOrCom(comm,x0+i);
// LCM_SWriteDatOrCom(comm,0x30);//0x30
// LCM_SWriteDatOrCom(dat,data1);
// LCM_SWriteDatOrCom(dat,data2);
// }
// }
// LCM_SWriteDatOrCom(comm,0x36);//0x36
// }
#ifndef __12864_H
#define __12864_H
#include "reg52.h"
#include "integer.h"
#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
/*****************************************************************************/
sbit LCD_PSB = P1^3; //H=并口; L=串口;
sbit LCD_RST = P3^6; //Reset Signal 低电平有效
sbit LCD_RS = P1^0; //RS=1数据 RS=0命令 串行片选CS
sbit LCD_RW = P1^1; //RW=1读取 RW=0写入 串行数据SID
sbit LCD_EN = P1^2; //使能信号 串行同步时钟CLK
sbit LCD_BL = P3^7;
sbit ACC0 = ACC^0;
sbit ACC7 = ACC^7;
/*****************************************************************************/
//函数声明
void LCM_WriteString(unsigned char *str) ; //写字符 例:LCM_WriteString("您好!");
void LCM_SWriteDatOrCom(bit ,uint8_t ); //(0,指令) (1,数据)
void LCD_Init(bit Mode);
void LCD_Clr(void); //清屏
void chn_disp (uint8_t code *chn);
void LCD_Pos(uint8_t X,uint8_t Y);
//void con_disp (uint8_t _line,uint8_t enable);
/*****************************************************************************/
#endif
|
|