/************************************************************
名称:智能型有害气体报警仪
作者:李锦涛,董佩钦,段立立,刘瑾
修改时间:2007.4.22
功能:
2007年04月22日
星期日 温度
00:00:00
A:25 C:67 C:78
连线:1(vss)=“0”,2(vdd)=“1”,3(v0)=+5和18(vee)的分压
4(rs)->P2.0,5(R/W)-> P2.1,6(E)->/(WR&RD)
7-14(DB0-DB7)->P0.0-P0.7,
15(CS1)->P2.2,16(CS2)->P2.3
17(RES)="1",18(VEE),19(LEDA)="0"
20(LEDK)接开关接电源
21 P3.3接DS18B20 22 P3.2接继电器
************************************************************/
#include <reg51.h>
#include <absacc.h>
#include <intrins.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#define write_cmd_addr_1 XBYTE[0x8FFF]//写指令地址(左)
#define read_state_addr_1 XBYTE[0xAFFF]//读状态地址(左)
#define write_data_addr_1 XBYTE[0x9FFF]//写数据地址(左)
#define read_data_addr_1 XBYTE[0xBFFF]//读数据地址(左)
#define write_cmd_addr_2 XBYTE[0x4FFF]//写指令地址(右)
#define read_state_addr_2 XBYTE[0x6FFF]//读状态地址(右)
#define write_data_addr_2 XBYTE[0x5FFF]//写数据地址(右)
#define read_data_addr_2 XBYTE[0x7FFF]//读数据地址(右)
#define Disp_On 0x3f//开显示
#define Disp_Off 0x3e//关显示
#define Col_Add 0x40//列地址
#define Page_Add 0xb8//页地址
#define Start_Line 0xc0//起始行
#define baojing XBYTE[0xf7ff]
unsigned char keey;
unsigned char cn0=0x33;
unsigned char cn1=0x33;
unsigned char cn2=0x33;
unsigned char cn3=0x33;
unsigned char cn4=0x33;
unsigned char cn5=0x33;
unsigned char receiver_0=0x00;//随机单元存储
unsigned char receiver_1=0x00;//通道0存储单元
unsigned char receiver_2=0x00;//通道1存储单元
unsigned char receiver_3=0x00;//通道2存储单元
unsigned char receiver_4=0x00;//通道3存储单元
unsigned char receiver_5=0x00;//通道4存储单元
unsigned char receiver_6=0x00;//通道5存储单元
unsigned char channal_1_ge;
unsigned char channal_1_shi;
unsigned char channal_1;
unsigned char channal_2_ge;
unsigned char channal_2_shi;
unsigned char channal_2;
unsigned char channal_3_ge;
unsigned char channal_3_shi;
unsigned char channal_3;
bit frist_ri0=1;
bit frist_ri=0;
bit second_ri=0;
bit third_ri=0;
bit forth_ri=0;
bit fifth_ri=0;
bit sixth_ri=0;
unsigned char ms=0;//秒计数单元
unsigned char time_miao=0;//秒单元
unsigned char time_miao_1=0;//秒个位
unsigned char time_miao_2=0;//秒十位
unsigned char time_fen=0;//分单元
unsigned char time_fen_1=0;//分个位
unsigned char time_fen_2=0;//分十位
unsigned char time_shi=0;//时单元
unsigned char time_shi_1=0;//时个位
unsigned char time_shi_2=0;//时十位
unsigned char time_day=1;//日单元
unsigned char time_day_1=0;//日个位
unsigned char time_day_2=0;//日十位
unsigned char time_month=1;//月单元
unsigned char time_month_1=0;//月个位
unsigned char time_month_2=0;//月十位
unsigned int time_year=2007;//年单元
unsigned char time_year_1=0;//年个位
unsigned char time_year_2=0;//年十位
unsigned char time_year_3=0;//年百位
unsigned char time_year_4=0;//年千位
sbit dq = P3^3;
sbit led=P2^1;//指示
sbit A2=P2^2; //键盘指示灯
sbit alarm_led=P3^4;//报警指示灯
sbit relay_comparator=P3^2;//继电器控制
unsigned char *p;
unsigned int Temperature;
unsigned char temp_buff[9]; //存储读取的字节,read scratchpad为9字节,read rom ID为8字节
unsigned char temh_d;
unsigned char temm_d;
unsigned char teml_d;
unsigned char w;//返回周
unsigned char m_day;//返回月的最大天数
bit minute_flag=0;//调分判断位
bit hour_flag=0;//调时判断位
bit day_flag=0;//调日判断位
bit month_flag=0;//调月判断位
bit year_flag=0;//调年判断位
bit frist_sure=0;//第一次按下确定键 开始对表 首先调整年
bit second_sure=0;//第二次按下确定键 调整月
bit third_sure=0;//第三次按下确定键 调整日
bit fourth_sure=0;//第四次按下确定键 调整时
bit fifth_sure=0;//第五次按下确定键 调整分
bit leap_flag;//闰平年标志 0:平年 1:闰年
bit key_sure=1;//"确定"功能
bit key_dec=1;//"减一"功能
bit key_inc=1; //"加一"功能
char code number[][16]={
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00
},/*"0",9*/
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00
},/*"1",0*/
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,
0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00
},/*"2",1*/
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,
0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00
},/*"3",2*/
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,
0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00
},/*"4",3*/
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,
0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00
},/*"5",4*/
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,
0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00
},/*"6",5*/
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,
0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00
},/*"7",6*/
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00
},/*"8",7*/
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00
},/*"9",8*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
},/* 白屏*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x0C,0x0C,0x00,0x00,0x00,0x00,0x00
},//小数点 11
{0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
},//温度单位 12
{0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,
0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00
},//C 13
};
char code week[7][32]={
{ 0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x00
},/*日,sunday*/
{ 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
}, /*一",monday*/
{ 0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x06,0x04,0x00,0x00,0x00,
0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x18,0x10,0x00
}, /*二",tusday*/
{ 0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,
0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00
}, /*三",wednesday*/
{ 0x00,0xFE,0x02,0x02,0x02,0xFE,0x02,0x02,0xFE,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,
0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x22,0x7F,0x00,0x00
}, /*四",thursday*/
{ 0x00,0x02,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0xC2,0x82,0x02,0x00,0x00,0x00,
0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x30,0x20,0x00
}, /*五",friday*/
{ 0x10,0x10,0x10,0x10,0x10,0x91,0x12,0x1E,0x94,0x10,0x10,0x10,0x10,0x10,0x10,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x00,0x00,0x01,0x02,0x0C,0x78,0x30,0x00,0x00
}, /*六",saturday*/
};
char code nian[]={
0x40,0x20,0x10,0x0C,0xE3,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0x02,0x00,0x00,
0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00
};/*"年 0*/
char code yue[]={
0x00,0x00,0x00,0x00,0x00,0xFF,0x11,0x11,0x11,0x11,0x11,0xFF,0x00,0x00,0x00,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x01,0x01,0x21,0x41,0x3F,0x00,0x00,0x00,0x00
};/*"月 1*/
char code ri[]={
0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x00
}; /*"日 2*/
char code maohao[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
char code C[]={
0x00,0x00,0x00,0x00,0x0F,0x30,0x40,0x40,0x40,0x40,0x70,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x80,0x60,0x10,0x10,0x10,0x20,0x40,0x00,0x00,0x00,0x00,0x00
};
char code xing[]={/*-- 文字: 星 --*/
0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,
0x00,0x48,0x46,0x41,0x49,0x49,0x49,0x7F,0x49,0x49,0x