#include "12864head.h"
#include "18b20.h"
#include "hs1101.h"
//ds18b20相关程序
/**************************************************************************
功能:用于K毫秒延时
**************************************************************************/
unsigned char dat[8]={0}; //显示数组//
unsigned char i,j;
unsigned int t;
void delaykms(unsigned char k)
{
unsigned char n,s;
for(n=2*k;n>0;n--)
for(s=248;s>0;s--);
}
/**************************************************************************
功能:用于i微秒延时
**************************************************************************/
void delay1(int z)//ms延时函数
{
int x,y;
for(x=z; x>0; x--)
for(y=110;y>0;y--);
}
void delay(int us)
{
int s;
for(s=0;s<us;s++);
}
//****************************************************************************
// 18B20温度采集模块
//****************************************************************************
unsigned char read(void)
{
unsigned char i,dat=0;
for(i=8;i>0;i--)
{
DQ=0;
dat>>=1;
DQ=1;
if(DQ)
dat|=0x80;
delay(4);
}
return (dat);
}
void write(unsigned char dat)
{
unsigned char i;
for(i=8;i>0;i--)
{
DQ=0;
DQ=dat&0x01;
delay(5);
DQ=1;
dat>>=1;
}
}
void readtemperature(void)
{
unsigned char temp;
int temperature;
reset();
write(0xcc);
write(0x44);
delay1(850);
reset();
write(0xcc);
write(0xbe);
temperature=read();
temp=read();
temperature=temperature|(temp<<8);
dat[4]=9;
if(temperature<0)
{temperature=~ temperature+1;
dat[4]=8;
}
dat[0]=10;
dat[1]=(temperature*10/16)/100;
dat[2]=((temperature*10/16)%100)/10;
dat[3]=((temperature*10/16)%100)%10;
}
unsigned char reset(void)
{
unsigned char presence;
DQ=0;
delay(29);
DQ=1;
delay(3);
presence=DQ;
delay(25);
return(presence);
}
//12864相关程序
#define GDM12864ADataPort P1 //LCD数据线
/*--------函数列表-------*/
/*----------------------------------------------------------------------------------------------------*/
//状态检查
void CheckState()
{
unsigned char dat;
DI=0;
RW=1;
do{
GDM12864ADataPort=0x00;
EN=1;
dat=GDM12864ADataPort;
EN=0;
dat=0x80 & dat; //仅当第7位为0时才可操作(判别busy信号)
}while(!(dat==0x00));
}
/*-----------------------------------------------------------------------------------------------------*/
//向LCD发送命令
//command :命令
SendCommandToLCD(unsigned char command)
{
CheckState();
RW=0;
GDM12864ADataPort=command;
EN=1;
EN=0;
}
/*----------------------------------------------------------------------------------------------------*/
//写显示数据
//dat:显示数据
void WriteByte(unsigned char dat)
{
CheckState();
DI=1;
RW=0;
GDM12864ADataPort=dat;
EN=1;
EN=0;
}
/*----------------------------------------------------------------------------------------------------*/
//读显示数据
unsigned char ReadByte()
{
unsigned char dat;
CheckState();
DI=1;
RW=1;
GDM12864ADataPort=0xff;
EN=1;
dat=GDM12864ADataPort;
EN=0;
return(dat);
}
/*----------------------------------------------------------------------------------------------------*/
//设定行地址(页)--X 0-7
void SetLine(unsigned char line)
{
line=line & 0x07; // 0<=line<=7
line=line|0xb8; //1011 1xxx
SendCommandToLCD(line);
}
/*----------------------------------------------------------------------------------------------------*/
//设定列地址--Y 0-63
void SetColumn(unsigned char column)
{
column=column &0x3f; // 0=<column<=63
column=column | 0x40; //01xx xxxx
SendCommandToLCD(column);
}
/*----------------------------------------------------------------------------------------------------*/
//设定显示开始行--XX
void SetStartLine(unsigned char startline) //0--63
{
startline=startline & 0x07;
startline=startline|0xc0; //1100 0000
SendCommandToLCD(startline);
}
/*----------------------------------------------------------------------------------------------------*/
//开关显示
void SetOnOff(unsigned char onoff)
{
onoff=0x3e | onoff; //0011 111x
SendCommandToLCD(onoff);
}
/*---------------------------------------------------------------------------------------------------*/
//选择屏幕
//screen: 0-全屏,1-左屏,2-右屏
void SelectScreen(unsigned char screen)
{ //cs1: 1--左; cs2: 1--右
switch(screen)
{ case 0: cs1=0;//全屏
_nop_(); _nop_(); _nop_();
cs2=0;
_nop_(); _nop_(); _nop_();
break;
case 1: cs1=0;//左屏
_nop_(); _nop_(); _nop_();
cs2=1;
_nop_(); _nop_(); _nop_();
break;
case 2: cs1=1;//右屏
_nop_(); _nop_(); _nop_();
cs2=0;
_nop_(); _nop_(); _nop_();
break;
}
}
/*---------------------------------------------------------------------------------------------------*/
//延时
GDM12864delay()
{
unsigned int i=500;
while(i--) {;}
}
/*---------------------------------------------------------------------------------------------------*/
//清屏
//screen: 0-全屏,1-左屏,2-右
void ClearScreen(unsigned char screen)
{ unsigned char i,j;
SelectScreen(screen);
for(i=0;i<8;i++){
SetLine(i);
for(j=0;j<128;j++){
WriteByte(0x00);
}
}
}
/*---------------------------------------------------------------------------------------------------*/
//初始化LCD
void InitLCD()
{
unsigned char i=250; //延时
while(i--);
SelectScreen(0);
SetOnOff(0); //关显示
ClearScreen(0);//清屏
SelectScreen(0);
SetOnOff(1); //开显示
SelectScreen(0);
SetStartLine(0); //开始行:0
}
/*----------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------*/
unsigned char code ASC[]={
/*'/'--0x2F
0x00,0x00,0x00,0x80,0xC0,0x60,0x30,0x00,
0x0C,0x06,0x03,0x01,0x00,0x00,0x00,0x00,
/*0--0x30 */
0xF8,0xFC,0x04,0xC4,0x24,0xFC,0xF8,0x00,
0x07,0x0F,0x09,0x08,0x08,0x0F,0x07,0x00,
/*1--0x31 */
0x00,0x10,0x18,0xFC,0xFC,0x00,0x00,0x00,
0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00,
/*2--0x32 */
0x08,0x0C,0x84,0xC4,0x64,0x3C,0x18,0x00,
0x0E,0x0F,0x09,0x08,0x08,0x0C,0x0C,0x00,
/*3--0x33 */
0x08,0x0C,0x44,0x44,0x44,0xFC,0xB8,0x00,
0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00,
/*4--0x34 */
0xC0,0xE0,0xB0,0x98,0xFC,0xFC,0x80,0x00,
0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,
/*5--0x35 */
0x7C,0x7C,0x44,0x44,0xC4,0xC4,0x84,0x00,
0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00,
/*6--0x36 */
0xF0,0xF8,0x4C,0x44,0x44,0xC0,0x80,0x00,
0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00,
/*7--0x37 */
0x0C,0x0C,0x04,0x84,0xC4,0x7C,0x3C,0x00,
0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,
/*8--0x38 */
0xB8,0xFC,0x44,0x44,0x44,0xFC,0xB8,0x00,
0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00,
/*9--0x39 */
0x38,0x7C,0x44,0x44,0x44,0xFC,0xF8,0x00,
0x00,0x08,0x08,0x08,0x0C,0x07,0x03,0x00,
/*.--0x2E*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00,
};
/*----------------------------------------------------------------------------------------------*/
/*本文件为16×16点阵中文字库文件,字的纵向8点构成一字节,上方的点在字节的低位
,字符点阵四角按左上角→右上角→左下角→右下角取字*/
unsigned char code hzdot[]= {
/*现 CCFD6 */
0x04,0x84,0x84,0xFC,0x84,0x84,0x00,0xFE,0x02,0x02,0xF2,0x02,0x02,0xFE,0x00,0x00,
0x20,0x60,0x20,0x1F,0x10,0x90,0x40,0x23,0x18,0x06,0x01,0x7E,0x80,0x83,0xE0,0x