📄 sed1335.c.bak
字号:
/*******************************************************************************
1...RESET..... 复位信号,低电平有效,阻容式复位电路
2.../RD..... RD 读有效
3.../WR..... WR 写有效
4.../CS......P2^7 片选通信号,低电平有效
5...A0 ..... P2.0 寄存器选择信号,命令数据方式选择
6...D0 ..... P0.0 数据总线 D0
7...D1 ..... P0.1 数据总线 D1
8...D2 ..... P0.2 数据总线 D2
9.. D3 ..... P0.3 数据总线 D3
10..D4 ..... P0.4 数据总线 D4
11..D5 ..... P0.5 数据总线 D5
12..D6 ..... P0.6 数据总线 D6
13..D7 ..... P0.7 数据总线 D7
14..VDD +5V
15..VSS GND
16..VEE -Vout 逆变-22.5V 负电压输出
17..VO ..... -Vadj Input 对比度负压调整输入
18..RV GND
19..NC
20..NC
21..NC
22..NC
23..NC
24..NC
******************************************************************************/
//#include <reg51.h>
#include <stdlib.h>
#include <intrins.h>
#include <C8051F020.H>
#include <stdio.h>
#define Uchar unsigned char
#define Uint unsigned int
//============================ 1335 常用指令列表 ===============================
//初始化设置。A0=1..写指令/0...读写参数。后续8字节参数串ParaSysTable8[]
#define SystemSet 0x40 // 时序要求:/WR=0;/RD=1
Uchar code ParaSysTable8[]= {
0x30,0x87,0x07,0x27,0x42,0xf0,0x28,0x00 // P1-P8参数
};
#define Scroll 0x44 // 时序要求:/WR=0;/RD=1
#define BasePart1 0x00
#define BasePart2 0x40
#define BasePart3 0x80
#define BasePart4 0x00
Uchar code ParaScrTableA[]= {
0x00,BasePart1,0xF0,0x00,BasePart2,0xF0,0x00,BasePart3,0x00,BasePart4
};
#define SleepIn 0x53
//显示状态设置。A0=1..ON/0..OFF;/WR=0;/RD=1.
#define DispOn 0x59
#define DispOff 0x58
#define Ovlay 0x5b
#define HdotScr 0x5a
//光标移动方向设置。A0=1;/WR=0;/RD=1.
#define CsrDirR 0x4c
#define CsrDirL 0x4d
#define CsrDirU 0x4e
#define CsrDirD 0x4f
#define CsrW 0x46
//读取光标指针。A0=1..写指令/0...读写参数;/WR=0;/RD=1.
#define CsrR 0x47
/* 该指令代码写入后,计算机将从SED1335等数据通道读出当前的光标指针值。光标指针读
出的顺序是先CSRL再CSRH.
*/
//数据写入设置。A0=1..写指令/0...读写参数;/WR=0;/RD=1.
#define mWrite 0x42
//数据读取设置。A0=1..写指令/0...读写参数;/WR=0;/RD=1.
#define mRead 0x43
// 程序参数定义,根据用户选择的LCM型号修改
#define Busy 0x40
#define paraP9 0x28
//sbit LCD_WR=P3^6; /*写信号*/
//sbit LCD_RD=P3^7; /*读信号*/
//sbit CS=P2^7; /*偏选信号*/
//sbit A0=P2^0; /*命令数据方式选择*/
sbit A0 = P3^0; //P6.0
sbit LCD_WR = P3^1; //P6.1
sbit LCD_RD = P3^2; //P6.2
sbit CS = P3^3; //P6.3
sbit RST = P3^4; //Not connected.
bit secflag=0;
Uchar click=0;
extern char code ASC_MSK[96*16]; /*asc码库*/
extern char code HZ16_16[];
extern char code HZ32_32[];
extern char code HZ32_32[];
extern char code Logo[];
void System(void);/*系统初始化*/
void LcmInition( void );/*液晶显示初始化*/
void WriteCommand( Uchar CommandByte ) ;/*写指令*/
void WriteData( Uchar dataW );/*写参数及显示数据*/
void LcmClear( void );/*清屏函数*/
void Delay( Uint tt );/*延时函数*/
void Delayms(int n);//1ms
void Locatexy(Uchar x,Uchar y, Uchar attribs);/*定位光标*/
void Point(Uint Px, Uchar Py, Uchar attr );/*描点*/
void Linexy(Uint x0,Uchar y0,Uint xt,Uchar yt,Uchar att);/*划线*/
void Putstr(Uchar x,Uchar y, Uchar *pstr,Uchar flag);/*输出16*16汉字字符串*/
void PutHz_32(Uchar x,Uchar y, Uchar *pstr,Uchar flag);/*输出32*32汉字字符串*/
void PutLogo(Uchar x,Uchar y, Uchar flag);/*输出公司标志*/
void circle(Uint Ox,Uchar Oy,Uchar Rx,Uchar attr);/*画圆*/
void send_int(Uchar wei,Uchar *str,Uint shu);/*整数输出到字符串*/
void SPutf(Uchar *format,Uchar *str,float fvar);/*浮点数输出到字符串*/
void put_uint(Uchar x,Uchar y,Uchar weishu,Uint shu,Uchar attribte);/*显示整数*/
//void Putf(Uchar x,Uchar y,Uchar *p,float fbuf,Uchar attribte);/*显示浮点数*/
Uchar ReadDataLcm( void );
extern void Init_Device(void);
void Main( void ) {
Uchar k;
Uint cc=0;
float aa=-800.43;
float bb=700.20;
WDTCN = 0xde; // disable watchdog timer
WDTCN = 0xad;
Init_Device();
Delay(32768); // 足够的延时确保lcm已经准备好
// System();
LcmInition();
LcmClear();
Delayms(40);
PutLogo(2,10,0);
// PutLogo(0,0,0);
Putstr(16,60,"FDJJ-1型",0);
PutHz_32(0,104,"发动机检测仪检定装置",0);
// Putstr(5,40,"转速闭合角重叠角加速时间提前角电压电流电阻频率/请输入值/按键/确认/返回/开始/停止/转分/度/毫秒/伏特/安培/欧姆/赫兹",0);
Putstr(4,180,"深圳市安车科技有限公司济南分公司",0);
Linexy(0,0,0,239,1);
Linexy(0,0,319,0,1);
Linexy(0,239,319,239,1);
Linexy(319,0,319,239,1);
/* for(k=0;k<100;k++)
{ Linexy(k+1,k+5,k+10,k+30,1);}
Linexy(0,0,0,239,1);
circle(60,40,30,1);
//Delayms(300);
circle(120,40,30,1);
//Delayms(300);
circle(180,40,30,1);
//Delayms(300);
circle(240,40,30,1);
//Delayms(300);
circle(300,40,15,1);
//Delayms(300);
circle(60,120,30,1);
//Delayms(300);
circle(120,120,30,1);
//Delayms(300);
circle(180,120,30,1);
//Delayms(300);
circle(240,120,30,1);
//Delayms(300);
circle(300,120,15,1);
//Delayms(300);
circle(60,200,30,1);
Delayms(300);
circle(120,200,30,1);
//Delayms(300);
circle(180,200,30,1);
//Delayms(300);
circle(240,200,30,1);
//Delayms(300);
circle(300,200,15,1);
//Delayms(300);
// circle(60,40,30,0);
//Delayms(300);
//circle(120,40,30,0);
//Delayms(300);
//circle(180,40,30,0);
////Delayms(300);
//circle(240,40,30,0);
//Delayms(300);
// circle(300,40,15,0);
//Delayms(300);
//circle(60,120,30,0);
//Delayms(300);
//circle(120,120,30,0);
//Delayms(300);
//circle(180,120,30,0);
//Delayms(300);
//circle(240,120,30,0);
//Delayms(300);
//circle(300,120,15,0);
//Delayms(300);
// circle(60,200,30,0);
// Delayms(300);
// circle(120,200,30,0);
// Delayms(300);
// circle(180,200,30,0);
//Delayms(300);
//circle(240,200,30,0);
//Delayms(300);
//circle(300,200,15,0);
Delayms(400);
Delayms(400);
Delayms(400);
Delayms(400);
LcmClear(); */
while(1)
{
// if(secflag)
// {
// secflag=0;
// put_uint(20,120,2,cc,0);
// Putf (10,40,"+52",aa,0);
// Putf(10,80,"+52",bb,0);
// cc=cc+1;
// aa=aa+1;
// bb=bb+2;
// if(cc>59)
// cc=0;
// }
}//while
// while(1);
}
/*************************************
函数说明:初始化
*************************************/
void System(void)
{
// TMOD=0x01;
// TH0=0x4c;
//TL0=0x00;
EA=1;
ET0=1;
TR0=1;
}
/*----------------------------------
函数说明:LCM初始化
-----------------------------------*/
void LcmInition( void ) {
Uchar i;
RST = 0;
RST = 1;
WriteCommand( SystemSet ); // 系统参数设置
for (i=0;i<8;i++) {
WriteData( ParaSysTable8[i] ); //
}
WriteCommand( Scroll ); //设定显示区域起始地址
for (i=0;i<10;i++) {
WriteData( ParaScrTableA[i] );
}
WriteCommand( HdotScr ); // 写入点位移指令代码
WriteData( 0 ); // 写入P1参数
WriteCommand( Ovlay ); // 显示合成方式设置
WriteData( 4 ); // 0000 0100 显示一区图形,三区文本属性,二重"或"合成
WriteCommand( DispOn ); // 写入指令代码
WriteData( 0x54 ); // 显示 1~4 区开显示,光标关显示
Delayms(5);
}
/*---------------------------
// 写指令代码子程序pr
______________________________*/
void WriteCommand( Uchar CommandByte )
{
P74OUT = 0x0c;
// Delay(2);
CS=0;
A0=1;
LCD_WR=1;
LCD_RD=1;
// P5=CommandByte;
// Delay(2);
LCD_WR=0;
// Delay(2);
P5=CommandByte;
// Delay(2);
LCD_WR=1;
CS=1;
}
/*---------------------------
// 写参数及显示数据子程序
-----------------------------*/
void WriteData( Uchar dataW )
{
P74OUT = 0x0c;
// Delay(2);
CS=0;
A0=0;
LCD_WR=1;
LCD_RD=1;
// Delay(5);
// P5=dataW;
LCD_WR=0;
// Delay(2);
P5=dataW;
// Delay(3);
LCD_WR=1;
CS=1;
}
/*---------------------------
// 读参数及显示数据子程序
-----------------------------*/
Uchar ReadDataLcm( void ) {
Uchar cbuf;
P74OUT = 0x00;
P5=0xff;
// Delay(5);
CS=0;
A0=1;
LCD_WR=1;
// Delay(3);
LCD_RD=0;
// Delay(2);
cbuf=P5;
// Delay(2);
LCD_RD=1;
CS=1;
return cbuf;
}
/*======================== 清显示 32K RAM区(清屏)子程序 ======================*/
void LcmClear( void )
{
Uint i=32768;
// Uchar j;
WriteCommand( CsrDirR ); // 光标移动方向定义:自动右移
WriteCommand( CsrW ); // 光标Locate,定位
WriteData( 0 ); // 写入参数CSRL设置参数光标指针低8位
WriteData( 0 ); // 写入参数CSRH设置参数光标指针高8位
WriteCommand( mWrite ); // 数据写入指令,代码0x42
while(i--) {
WriteData(0X00); // 写入数据0
}
/* WriteCommand( 0x4d );
i=32768;
WriteCommand( mRead );
while(i--) {
Delay(10);
j=ReadDataLcm();
}
*/
}
//--------延时子程序--------------------------
void Delay( Uint tt ) {
while( tt-- );
}
/*----------------------------------------
函数功能:延时1ms左右
函数名称:Delayms(uchar n)
------------------------------------------*/
void Delayms(int n)
{int j;
while(n>0)
{for(j=0;j<=110;j++);
n--;
}
}
/*---------------------------------------------------------------------------
光标位定位,用于在1区图形方式下。
输入参数约定: x...水平方向字节单位坐标,即可以以半个汉字宽度设定水平坐标。
y...垂直方向以行线定位的坐标,可以定位到点单位。
左上角约定坐标为( 0, 0 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -