求液晶显示大屏c51原代码
发布网友
发布时间:2022-08-18 00:33
我来回答
共1个回答
热心网友
时间:2023-10-15 00:53
#include <reg52.h>
#include <math.h>
#include <stdio.h>
#include <absacc.h>
#include <intrins.h>
#include "math.h"
#include <time.h>
#include <stdlib.h>
#define uchar unsigned char
#define uint unsigned int
#define lcd_com XBYTE[0x8fff] // 定义液晶写命令的地址 1000 1111
#define lcd_data XBYTE[0x87ff] // 定义液晶也数据的地址 1000 0111
void delay(uint); //延时函数
void check();//查忙程序
void write_com(uchar);
void write_data(uchar);
void write_data_com(uchar,uchar);
void write_data2_com(uchar,uchar,uchar);
void init();//液晶初始化函数
void show_point(uchar,uchar);//显示坐标为(x,y)的点
uchar read_data();//读取屏幕当前地址的数据
void init()
{
uint i;
write_com(0x9c);//显示开关设置
write_com(0xa0);//光标形状设置
write_com(0x80);//显示方式设置
write_data2_com(0x00,0x00,0x40);
write_data2_com(0x10,0x00,0x41);
write_data2_com(0x00,0x04,0x42); //图形显示区首地址
write_data2_com(0x10,0x00,0x43); //图形显示区宽度
write_data2_com(0x00,0x00,0x24);
write_com(0xb0);
for(i=0;i<254;i++)
write_data(0);
write_com(0xb2);
write_data2_com(0x00,0x04,0x24);
write_com(0xb0);
for(i=0;i<1024;i++)
write_data(0x00);
write_com(0xb2);
write_data2_com(0,0x00,0x21);
}
void show_point(uchar x,uchar y)//显示坐标为(x,y)的点,左上角为(0,0),右下角为(127,63)
{
uchar temp,temp_old;
switch(x%8)
{
case 0:
temp=0x80;
break;
case 1:
temp=0x40;
break;
case 2:
temp=0x20;
break;
case 3:
temp=0x10;
break;
case 4:
temp=0x08;
break;
case 5:
temp=0x04;
break;
case 6:
temp=0x02;
break;
case 7:
temp=0x01;
break;
}
write_data2_com(y%16*16+x/8,y/16+4,0x24);
temp_old=read_data();
write_com(0xb0);
write_data(temp|temp_old);
write_com(0xb2);
}
uchar read_data()//读取屏幕当前地址的数据
{
uchar temp;
write_com(0xe0);
write_com(0xc5);
check();
temp=lcd_data;
return temp;
}
void write_com(uchar my_com)
{
check();
lcd_com=my_com;
}
void write_data(uchar my_data)
{
check();
lcd_data=my_data;
}
void write_data_com(uchar my_data,uchar my_com)
{
write_data(my_data);
write_com(my_com);
}
void write_data2_com(uchar my_data_1,uchar my_data_2,uchar my_com)
{
write_data(my_data_1);
write_data(my_data_2);
write_com(my_com);
}
void check() //液晶查忙函数
{
uchar a;
do
{
a=lcd_com;
a=a&0x03;
}while(a!=0x03);
}
void delay(uint x) //延时函数
{ uchar k;
while(x--)
{
for(k=0;k<=125;k++)
{;}
}
}
128*64点阵的,以前写的。
参考资料:http://hi.baidu.com/wqfantexi/blog/item/f2dfdb08a20276930a7b828e.html