|
这是lcd的一些函数
void delay(unsigned int xms) //延时//
{
unsigned char i,j;
for(j = 0; j < xms; j++)
{
for(i = 0;i < 110;i++);
}
}
bit LcdBusyCheck(){
bit result;
LCD12864_RS = 0;
LCD12864_RW = 1;
LCD12864_EN = 1;
delay(1);
result = (bit)(DATA_PORT&0x80);
LCD12864_EN = 0;
return result;
}
void WriteCmdToLCD(unsigned char cmd)
{
while(LcdBusyCheck());
// delay(10);
LCD12864_RS = 0;
LCD12864_RW = 0;
LCD12864_EN = 1;
delay(1);
DATA_PORT = cmd;
// delay(5);
LCD12864_EN = 0;
// delay(5);
// LCD12864_EN = 1;
}
void WriteDatToLcd(unsigned char dat)
{
while(LcdBusyCheck());
// delay(10);
LCD12864_RS = 1;
LCD12864_RW = 0;
LCD12864_EN = 1;
delay(1);
DATA_PORT = dat;
// delay(5);
LCD12864_EN = 0;
// delay(5);
// LCD12864_EN = 1;
}
void WriteStrToLcd(unsigned char *str)
{
while(*str != '\0')
{
WriteDatToLcd(*str++);
delay(5);
}
}
unsigned char ReadLcd(void)
{
unsigned char dat;
//DATA_PORT=0xff;
while(LcdBusyCheck());
LCD12864_RS=1;
LCD12864_RW=1;
LCD12864_EN=0;
LCD12864_EN=1;
dat=DATA_PORT;
LCD12864_EN=0;
return dat;
}
void DrawDots(unsigned char i,unsigned char j)//打点函数 //x,y为128*64 点阵的坐标
{
unsigned char row,xlabel,xlabel_bit,x,y;
unsigned char Read_H=0,Read_L=0;
x = i+6;
y = 64-j-5;
WriteCmdToLCD(0x34); //扩充指令
WriteCmdToLCD(0x36); //绘图指令
xlabel=x>>4; //确定水平坐标地址
xlabel_bit=x & 0x0F; // 细分水平坐标中的第几位
if(y<32) row=y;
else { row=y-32; xlabel+=8; }
WriteCmdToLCD(row+0x80);
WriteCmdToLCD(xlabel+0x80);
ReadLcd();
Read_H=ReadLcd();
Read_L=ReadLcd();
WriteCmdToLCD(row+0x80);
WriteCmdToLCD(xlabel+0x80); //水平坐标地址+基址=显示的水平地址
if(xlabel_bit<8)
{
// Read_H &=(~(0x01<<(7-xlabel_bit))); //变暗
Read_H |=(0x01<<(7-xlabel_bit)); //变亮
// Read_H = Read_H;
WriteDatToLcd(Read_H);
WriteDatToLcd(Read_L);
}
else
{
//Read_L &=(~(0x01<<(15-xlabel_bit))); //变暗
Read_L |=(0x01<<(15-xlabel_bit)); //变亮
// Read_L=Read_L;
WriteDatToLcd(Read_H);
WriteDatToLcd(Read_L);
}
// WriteDatToLcd(Read_H);
// WriteDatToLcd(Read_L);
WriteCmdToLCD(0x30);//恢复正常模式
}
void Clear_GDRAM() //清除GDRAM
{
unsigned char x,y;
for(y=0;y<64;y++)
{
for(x=0;x<16;x++)
{
WriteCmdToLCD(0x34);
WriteCmdToLCD(y+0x80); //先送垂直地址
WriteCmdToLCD(x+0x80); //后送水平地址
WriteCmdToLCD(0x30); //基本指令
WriteDatToLcd(0x00); //写入数据0
WriteDatToLcd(0x00);
}
}
}
这是主函数里面的循环打点
for(i=5;i<50;i++)
{
DrawDots(i,i);
delay(100);
}
|
|