📄 display_320_240.c
字号:
#include <reg52.h>
#include <absacc.h>
#include "display_fun.h"
#ifndef uchar
#define uchar unsigned char
#endif
sbit lcd_a0=P3^7;
sbit lcd_cs=P1^3;
sbit lcd_rst=P1^4;
sbit lcd_wr=P3^6;
sbit lcd_rd=P1^2;
#define AP 0x2a
#define LENGTH 0xfa //波形区域宽度250
#define WIDTH 0xc8 //波形区域高度200
uchar code sys[8]={0x30,0x87,0x07,0x27,0x2a,0xef,0x2a,0}; /*P1-P8*/
uchar code scr[10]={0,0,0xef,0x00,0x28,0xef,0x00,0x50,0,0}; /*P1-P10*/
uchar code arr[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
/***************************************************************
*名称:outcode(uchar code_data)
*描述:向液晶屏输出指令代码
*参数:指令代码
*返回:
****************************************************************/
void outcode(uchar code_data)//输出指令代码
{
lcd_cs=0;
lcd_a0=1;
lcd_rd=1;lcd_wr=1;
P0=code_data;
lcd_wr=0;
lcd_wr=1;
lcd_cs=1;
}
/***************************************************************
*名称:outdata(uchar data_data)
*描述:向液晶屏输出指令参数
*参数:指令参数
*返回:
****************************************************************/
void outdata(uchar data_data)//输出指令参数
{
lcd_cs=0;
lcd_a0=0;
lcd_rd=1;
lcd_wr=1;
P0=data_data;
lcd_wr=0;
lcd_wr=1;
lcd_cs=1;
}
/***************************************************************
*名称:uchar indata(void)
*描述:从液晶屏输入数据
*参数:
*返回:输入数据
****************************************************************/
uchar indata(void)//输入数据
{
uchar data_data;
lcd_cs=0;
lcd_a0=1;
P0=0xff;
lcd_wr=1;
lcd_rd=0;
data_data=P0;
lcd_rd=1;
lcd_cs=1;
return data_data;
}
/***************************************************************
*名称:turnoff(void)
*描述:关闭液晶屏
*参数:
*返回:
****************************************************************/
void turnoff(void)
{
outcode(0x58);//off screen
outdata(0x00);
}
/***************************************************************
*名称:turnon(void)
*描述:开启液晶屏
*参数:
*返回:
****************************************************************/
void turnon(void)
{
outcode(0x59);//on screen
outdata(0x55);
}
/***************************************************************
*名称:initram(void)
*描述:清屏(3层)
*参数:
*返回:
****************************************************************/
void initram(void)
{//显示存储器清零
unsigned int i;
outcode(0x4c);
outcode(0x46);
outdata(0x00);
outdata(0x00);
outcode(0x42);//clear screen memory
for(i=0;i<0x7800;)//24478,32768,0x7800,0x58e5
{
outdata(0x00);
i++;
}
}
/***************************************************************
*名称:initram_1(void)
*描述:清屏(first1层)
*参数:
*返回:
****************************************************************/
void initram_1(void)
{//显示存储器清零
unsigned int i;
outcode(0x4c);
outcode(0x46);
outdata(0x00);
outdata(0x00);
outcode(0x42);//clear screen memory
for(i=0;i<0x2800;i++)//24478,32768,0x7800,0x58e5
{
outdata(0x00);
}
}
/***************************************************************
*名称:init(void)
*描述:初始化程序
*参数:
*返回:
****************************************************************/
void init(void)
{
int n;
outcode(0x40); /*SYSTEM SET 指令代码*/
for(n=0;n<8;n++)outdata(sys[n]); /*将参数P1-P8 写入*/
outcode(0x44); /*SCROLL 指令代码*/
for(n=0;n<10;n++)outdata(scr[n]); /*将参数P1-P10 写入*/
outcode(0x5a); /*HDOT SCR——P1 清零复位*/
outdata(0);
outcode(0x5b); /*OVLAY—*/
outdata(0x1c);
}
/***************************************************************
*名称:WriteD(uchar x,uchar y)
*描述:在第一层写一个点
*参数:点的坐标位置(x,y)
*返回:
****************************************************************/
void WriteD(uchar x,uchar y) //write a dot on the 1nd layer
{
unsigned int address;
uchar addh,addl;
uchar m=0,n;
address=0x01f9+x/8+y*AP;
addh=address>>8;//addh=address/256;
addl=(uchar)address;//addl=address%256;
n=x%8;
outcode(0x46);
outdata(addl);
outdata(addh);
outcode(0x43);
m=indata();
m=m|arr[n];
outcode(0x46);
outdata(addl);
outdata(addh);
outcode(0x42);
outdata(m);
}
/***************************************************************
*名称:WriteD2(uchar x,uchar y)
*描述:在第二层写一个点
*参数:点的坐标位置(x,y)
*返回:
****************************************************************/
void WriteD2(uchar x,uchar y) //write a dot on the 2nd layer
{
unsigned int address;
uchar addh,addl;
uchar m=0,n=0;
address=0x29f9+x/8+y*AP;
addh=address>>8;//addh=address/256;
addl=(uchar)address;//addl=address%256;
outcode(0x46);
outdata(addl);
outdata(addh);
outcode(0x43);
m=indata();
n=x%8;
m=m|arr[n];
outcode(0x46);
outdata(addl);
outdata(addh);
outcode(0x42);
outdata(m);//m
}
/***************************************************************
*名称:Hori(uchar y,uchar space)
*描述:在第二层画水平网格线
*参数:网格的行数、空的点数
*返回:
****************************************************************/
void Hori(uchar y,uchar space) //画水平网格线
{
uchar i;
outcode(0x4c);
for(i=space;i<LENGTH;i+=space)WriteD2(i,y);
}
/***************************************************************
*名称:Ver(uchar x,uchar space)
*描述:在第二层画垂直网格线
*参数:网格的列数、空的点数
*返回:
****************************************************************/
void Ver(uchar x,uchar space) //画垂直网格线
{
uchar i=0 ;
outcode(0x4f);
if((x==0)|(x==0xfa))i=0;
else i=space;
for(;i<WIDTH;i+=space)WriteD2(x,i);
}
/***************************************************************
*名称:fixline(uchar y)
*描述:在第二层画横线
*参数:横线的行数
*返回:
****************************************************************/
void fixline(uchar y)
{
unsigned int address;
uchar addh,addl;
uchar i;
address=0x2a18+y*AP;
addh=address>>8;//addh=address/256;
addl=(uchar)address;//addl=address%256;
outcode(0x46);
outdata(addl);
outdata(addh);
outcode(0x4c);
outcode(0x42);
outdata(0x3f);
for(i=1;i<8;i++)outdata(0xff);
}
/***************************************************************
*名称:fixline2(uchar y)
*描述:在第二层右半边画横线
*参数:横线的行数
*返回:
****************************************************************/
void fixline2(uchar y)
{
unsigned int address;
uchar addh,addl;
uchar i;
address=0x29f9+y*AP;
addh=address>>8;//addh=address/256;
addl=(uchar)address;//addl=address%256;
outcode(0x46);
outdata(addl);
outdata(addh);
outcode(0x4c);
outcode(0x42);
outdata(0x3f);
for(i=1;i<31;i++)outdata(0xff);
}
/***************************************************************
*名称:DrawFrame(void)
*描述:在第二层画网格边框
*参数:
*返回:
****************************************************************/
void DrawFrame(void) //画网格边框
{
fixline(0);
fixline(200);
Ver(0,1); //(8,12) --- (8,262)
Ver(LENGTH,1); //(208,12) --- (208,212)
fixline(40);
fixline(80);
fixline(120);
fixline(160);
fixline2(200);
fixline2(0);
}
/***************************************************************
*名称:DrawGrid(void)
*描述:在第二层画网格区内的网格线
*参数:
*返回:
****************************************************************/
void DrawGrid(void) //画网格区内的网格线
{
uchar i;
Hori(1,5);
Hori(2,25);
Hori(WIDTH-2,0x19);
Hori(WIDTH-2,0x05);
Ver(0x02,0x19);
Ver(LENGTH-2,0x19);
for(i=1;i<0x08;i++){
Hori(25*i,5);
if(i==0x04){
Hori(0x19*i-1,5);
Hori(0x19*i+1,5);//
}
}
for(i=0x01;i<0x0a;i++)
{
Ver(0x19*i,5);
if(i==0x05)
{
Ver(0x19*i-1,5);
Ver(0x19*i+1,5);
}
}
}
/***************************************************************
*名称:vector(uchar x,uchar y1,uchar y2)
*描述:两个点之间插入若干点,将点显示转换为矢量显示
*参数:坐标x,坐标y1,坐标y2
*返回:
****************************************************************/
void vector(uchar x,uchar y1,uchar y2)
{
char i=y2-y1;
uchar tempy;
if(i>0){
tempy=y2-1;
for(;i>1;i--){
WriteD(x+1,tempy);
tempy--;
}
}
else if(i<0){
tempy=y2+1;
i=-i;
for(;i>1;i--){
WriteD(x+1,tempy);
tempy++;
}
}
else{}
}
/***************************************************************
*名称:show_123(char array[])
*描述:
*参数:
*返回:
****************************************************************/
void show_123(char flag,char array[])
{
int i;
int tempx=0,tempy=0;
int y;
if(flag)
{
for(i=0;i<250;i++)
{
y=100-array[i];
WriteD(i,y);
if((tempy!=y)&(i!=0))vector(tempx,tempy,y);
tempx=i;tempy=y;
}
}
else
{
for(i=0;i<250;i++)
WriteD(i,100);
}
}
/***************************************************************
*名称:show_tri(void)
*描述:
*参数:
*返回:
****************************************************************/
/*void show_tri(void)
{
int i,j;
int x,y;
for(i=0;i<5;i++)
{
for(j=0;j<50;j++)
{
x=50*i+j;
if(i==0)y=100-i;
else if(i==1)y=i;
else if(i==2)y=i;
else y=300-i;
WriteD(x,y);
}
}
}*/
/***************************************************************
*名称:show_wave(unsigned char mod)
*描述:
*参数:
*返回:
****************************************************************/
/*void show_wave(unsigned char mod)
{
switch(mod)
{
case 0: initram_1();
show_123(sin);
break;
case 1: initram_1();
show_123(tri);
break;
case 2: initram_1();
show_123(pul);
break;
case 3: initram_1();
show_123(clr);
break;
default :break;
}
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -