#include<reg52.h>
#include <intrins.h>
#include "Lcd.H"
#define uchar unsigned char
#define uint unsigned int
unsigned char flag;
sbit CS = P2^7;
sbit SID= P2^6;
sbit CLK= P2^5;
uchar code addr[]={ 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f };//DDRAM地址
uchar code datshu[]={ 0x30,/*0*/ 0x31,/*1*/0x32,/*2*/0x33,/*3*/ //数字库:0123456789.
0x34,/*4*/ 0x35,/*5*/0x36,/*6*/0x37,/*7*/
0x38,/*8*/ 0x39,/*9*/0x2e,/*.*/0x41,/*A*/0x56 /*V*/};
/*********************************************************/
/*Header:Lcd.h
/*File Name:Lcd.c
/*Author: 陈培炜,杨帆
/*Data;2007
/*Function:程序内部调用的函数
/*********************************************************/
void Send(unsigned char senddata);
void WriteCmd( uchar cmd );
void WriteData( uchar Data );
void displayChar( uchar *x_add, uchar *dat );
void HanZiString(uchar x,uchar *p);
void DispOrder(unsigned char x);
void WriteRAM( uchar Data );
void delay(unsigned int t);
/*****************************初始化子程序******************************/
void InitLcd(void)
{
CS = 1;
WriteCmd( 0x30 );
delay( 150 );//延时150us
WriteCmd(0x30);
delay( 45 );//延时45us
WriteCmd( 0x0C );
delay( 150 );//延时150us
WriteCmd( 0x01 );
delay( 15000 );//延时12MS
WriteCmd(0x06);
}
/*********************************************/
/*Header:Lcd.h
/*File Name:Lcd.c
/*Author: 陈培炜,杨帆
/*Data;2007
/*Function:
/*********************************************/
void cls(void)
{
WriteCmd( 0x01 );
delay( 15000 );//延时12MS
}
/*****************************延时子程序***************************/
void delay( uint t )
{
while( t-- );
}
/***********************************************************
/*Header:Lcd.h
/*File Name:Lcd.c
/*Author: 陈培炜,杨帆
/*Data;2007
/*Function:
***********************************************************/
void DelayUS(unsigned int n) //N us延时函数
{
unsigned int i=0;
for (i=0;i<n;i++)
_nop_();
}
/***********************************************************
/*Header:Lcd.h
/*File Name:Lcd.c
/*Author: 陈培炜,杨帆
/*Data;2007
/*Function:
***********************************************************/
void Send(unsigned char senddata)
{
unsigned char i;
for(i=0;i<8;i++)
{
if((senddata)&0x80)
SID = 1;
else
SID = 0;
CLK = 1;
_nop_();
CLK = 0;
senddata<<=1;
}
}
/*******************************写指令子程序***************************/
void WriteCmd( uchar cmd )
{
Send(0xf8);
Send(cmd&0xf0);
Send(cmd<<4);
DelayUS(20);
}
/***********************************写数据子程序****************************/
void WriteData(unsigned char Data)
{
Send(0xfa);
Send(Data&0xf0);
Send(Data<<4);
DelayUS(20);
}
/***************************************************************/
void WriteRAM( uchar Data )
{
Send(0xfa); //11111010
Send(Data&0xf0); //xxxx0000
Send(Data<<4); //xxxx0000
delay(20);
}
/********************显示字符*************************************/
void displayChar( uchar *x_add, uchar *dat )
{
WriteCmd( *x_add );//1xxx,xxxx 设定DDRAM 7位地址xxx,xxxx到地址计数器AC
WriteData( *dat );
}
/***************************显示字符串**************************************/
void HanZiString(uchar x,uchar *p)
{
uchar ad;
ad = addr[x];
WriteCmd(ad);
while (*p!='\0')
{
WriteRAM(*(p++));
}
}
/*********************************************************/
/*Header:Lcd.h
/*File Name:Lcd.c
/*Author: 陈培炜,杨帆
/*Data;2007
/*Function:温度与占空比的显示函数
/*********************************************************/
void disp(unsigned char tempreture,unsigned int high)
{
unsigned char a,b;
unsigned int z;
HanZiString(0,"温度 ℃");
a = tempreture/10;
b = tempreture%10;
displayChar( &addr[3],&datshu[a] );
displayChar( &addr[4],&datshu[b] );
z = high/100;
a = z/10;
b = z%10;
HanZiString(8,"占空比 /100 ");
displayChar( &addr[12],&datshu[a] );
displayChar( &addr[13],&datshu[b] );
}
/*********************************************/
/*
/* 设定温度范围显示函数
/*********************************************/
void disp2(unsigned char dt,unsigned char ut,unsigned char flag)
{
unsigned char t,d;
HanZiString(0,"设定温度范围:");
HanZiString(11,"——");
if(flag == 0)
{
HanZiString(17,"__");
HanZiString(21," ");
}
else
{
HanZiString(17," ");
HanZiString(21,"__");
}
t = dt/10;
d = dt%10;
displayChar( &addr[9],&datshu[t] );
displayChar( &addr[10],&datshu[d] );
t = ut/10;
d = ut%10;
displayChar( &addr[13],&datshu[t] );
displayChar( &addr[14],&datshu[d] );
}
/*********************************************/
/*********************************************/