#include <absacc.h>
#include <reg51.h>
#include <stdlib.h>
#include <math.h>
#include <intrins.h>
//#include "display_fun.h"
#include "ziku.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 _Nop() _nop_() /*定义空指令*/
sbit SCL=P3^4;/*假设由P3.4和P3.5控制*/
sbit SDA=P3^5;
bit ack; /*应答标志位*/
/*P1口用作LED显示线*/
sbit LED_CLK=P1^0; //LED时钟线
sbit LED_DAT=P1^1; //LED数据线
const uchar code LED_FONT[11]={ //
0xFC, //0
0x60, //1
0xDA, //2
0xF2, //3
0x66, //4
0xB6, //5
0xBE, //6
0xE0, //7
0xFE, //8
0xF6, //9
0x00 //不显示
};
void led_display(uchar i)
{
uchar j,mask;
mask=0x01;
for(j=0;j<8;j++){
LED_CLK=0;
LED_DAT=( (LED_FONT[i]) & mask);
mask<<=1;
LED_CLK=1; //上升沿移位
}
}
void refresh_led(unsigned char value[])
{
led_display(10);
led_display(10);
led_display(10);
led_display(value[0]);
led_display(value[1]);
led_display(value[2]);
}
/*
void refresh_led(unsigned char value)
{
unsigned char temp;
led_display(10);
led_display(10);
led_display(10);
temp = value/100;
led_display(temp);
temp = (value%100)/10;
led_display(temp);
temp = value%10 ;
led_display(temp);
}*/
#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++;
}
}
/***************************************************************
*名称: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)
*描述:
- 1
- 2
前往页