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

📄 signal_show.c

📁 使用51系列单片机实现LCD的驱动显示
💻 C
📖 第 1 页 / 共 2 页
字号:
//波形显示在第一层,网格坐标显示在第二层,汉字菜单显示在第三层.
#include <reg51.h>
#include <absacc.h>
#include <math.h>
#include "constant.h"
#include "iCf.h"
#include "rCf.h"
#include "ziku.h"
#include "f_define.h"//函数定义
//输入频率92Hz
/***************************************************************
*名称:outcode(uchar code_data)
*描述:向液晶屏输出指令代码
*参数:指令代码
*返回:
****************************************************************/
void outcode(uchar code_data)//输出指令代码
{
	lcd_cs=0;
	lcd_a0=1;
	lcd_rd=1;lcd_wr=1;lcd_rst=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;
	Ram_cs = 1 ;
	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;)//24478,32768,0x7800,0x58e5
	{
		outdata(0x00);
		i++;
	}
}

/***************************************************************
*名称: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/256;
	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/256;
	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/256;
	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/256;
	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{}
}
/***************************************************************

⌨️ 快捷键说明

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