PIC單片機(jī)實(shí)例四:溫度測(cè)量系統(tǒng)的設(shè)計(jì)與仿真
引言
網(wǎng)上有很多一線總線的產(chǎn)品,我覺(jué)得這項(xiàng)技術(shù)的前景不錯(cuò),自己用C也寫(xiě)了一個(gè)測(cè)溫的程序.
并通過(guò)PROTEUS進(jìn)行了仿真.
搞了很多天,終于搞出來(lái)了,心里高興的很,拿出來(lái)曬一下!
一. 原理介紹
說(shuō)明:
1.單片機(jī)采用PIC16F877A,主要是由于液晶顯示需要自己寫(xiě)字庫(kù),所以需要大容量的EEPROM,而他有8K字節(jié).
2.液晶使用的是KS0108控制器系列,他的指令比較簡(jiǎn)單,性價(jià)比較高.
3.溫度傳感器采用的是1-WIRE總線技術(shù)的DS18B20,測(cè)的溫度分辨率高.
附另外兩張效果圖
二. 器件介紹
DS18B20的相關(guān)資料
讀寫(xiě)時(shí)序復(fù)位時(shí)序操作ROM的指令內(nèi)部框圖讀出數(shù)據(jù)說(shuō)明
KS0108控制器相關(guān)資料:
三. 程序
/*************************************************************
* 標(biāo)題:溫度測(cè)量系統(tǒng) *
* 作者:Wujieflash *
* 日期:2008年1月8日 *
* 版本:V1.0 *
*說(shuō)明:①單片機(jī):PIC16F877A*
* ②液晶; KS0108控制器*
* ③傳感器:DS18B20 *
*******************************************************************/
#include
__CONFIG(0x1832);
//芯片配置字,看門(mén)狗關(guān),上電延時(shí)開(kāi),掉電檢測(cè)關(guān),低壓編程關(guān),加密,4M晶體HS振蕩
#define E RC0//液晶使能端
#define RW RC1//讀寫(xiě)控制端
#define DI RC2//數(shù)據(jù)/指令通道
#define CSA RC3//片選
#define CSB RC4//片選
#define nop() asm("nop")
#define uch unsigned char //給unsigned char起別名 uch
# define DQ RA0 //定義18B20數(shù)據(jù)端口
# define DQ_DIR TRISA0 //定義18B20D口方向寄存器
# define DQ_HIGH() DQ_DIR =1 //設(shè)置數(shù)據(jù)口為輸入
# define DQ_LOW() DQ = 0; DQ_DIR = 0 //設(shè)置數(shù)據(jù)口為輸出
uch TLV=0 ; //采集到的溫度高8位
uch THV=0; //采集到的溫度低8位
uch TZ=0; //轉(zhuǎn)換后的溫度值整數(shù)部分
int val1=35,val2=10;
//字庫(kù)
/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
const unsigned char wen[]={0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00,0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00};//溫
const unsigned char du[]={0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00,0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00};/*"度"*/
const unsigned char ce[]={0x08,0x31,0x86,0x60,0x00,0xFE,0x02,0xF2,0x02,0xFE,0x00,0xF8,0x00,0x00,0xFF,0x00,0x04,0xFC,0x03,0x00,0x80,0x47,0x30,0x0F,0x10,0x67,0x00,0x07,0x40,0x80,0x7F,0x00};/*"測(cè)"*/
const unsigned char liang[]={0x40,0x40,0x40,0xDF,0x55,0x55,0x55,0xD5,0x55,0x55,0x55,0xDF,0x40,0x40,0x40,0x00,0x40,0x40,0x40,0x57,0x55,0x55,0x55,0x7F,0x55,0x55,0x55,0x57,0x50,0x40,0x40,0x00};/*"量"*/
const unsigned char xi[]={0x00,0x00,0x02,0x22,0xB2,0xAA,0x66,0x62,0x22,0x11,0x4D,0x81,0x01,0x01,0x00,0x00,0x00,0x40,0x21,0x13,0x09,0x05,0x41,0x81,0x7F,0x01,0x05,0x09,0x13,0x62,0x00,0x00};/*"系"*/
const unsigned char tong[]={0x20,0x30,0x2C,0xA3,0x60,0x10,0x84,0xC4,0xA4,0x9D,0x86,0x84,0xA4,0xC4,0x84,0x00,0x20,0x22,0x23,0x12,0x12,0x92,0x40,0x30,0x0F,0x00,0x00,0x3F,0x40,0x41,0x70,0x00};/*"統(tǒng)"*/
const unsigned char zuo[]={0x80,0x40,0x20,0xF8,0x07,0x22,0x18,0x0C,0xFB,0x48,0x48,0x48,0x68,0x48,0x08,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0xFF,0x04,0x04,0x04,0x04,0x06,0x04,0x00};//作
const unsigned char zhe[]={0x00,0x20,0x24,0x24,0x24,0x24,0xA4,0xBF,0x64,0x24,0x34,0x28,0x26,0x24,0x20,0x00,0x04,0x04,0x04,0x02,0x02,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00};//者
const unsigned char ban[]={0x00,0xFE,0x90,0x90,0x9E,0x10,0x10,0xFE,0xE2,0x22,0x22,0x21,0xE1,0x21,0x00,0x00,0x40,0x3F,0x00,0x00,0x5F,0x20,0x98,0x47,0x20,0x13,0x0C,0x1B,0x60,0xC0,0x40,0x00};//版
const unsigned char ben[]={0x08,0x08,0x08,0x08,0x08,0xC8,0x38,0xFF,0x18,0x68,0x88,0x08,0x08,0x08,0x08,0x00,0x08,0x08,0x04,0x02,0x05,0x04,0x04,0x7F,0x04,0x04,0x04,0x03,0x06,0x0C,0x04,0x00};//本
const unsigned char zheng[]={0x00,0x02,0x02,0xC2,0x02,0x02,0x02,0x02,0xFE,0x82,0x82,0x82,0x82,0x82,0x02,0x00,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x00};//正
const unsigned char zai[]={0x00,0x04,0x04,0xC4,0x64,0x9C,0x87,0x84,0x84,0xE4,0x84,0x84,0x84,0x84,0x04,0x00,0x04,0x02,0x01,0x7F,0x00,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x00};//在
const unsigned char chu[]={0x00,0x08,0x88,0xC9,0x2E,0x98,0x48,0x00,0x08,0x08,0xF8,0x08,0x08,0xFC,0x08,0x00,0x02,0x01,0x00,0x7F,0x01,0x02,0x44,0x20,0x10,0x0C,0x03,0x20,0x40,0x3F,0x00,0x00};//初
const unsigned char shi[]={0x10,0x90,0x70,0x1F,0x12,0xF0,0x00,0x20,0x70,0x28,0x27,0x22,0x28,0x70,0x20,0x00,0x40,0x21,0x12,0x0C,0x06,0x09,0x30,0x00,0x7F,0x21,0x21,0x21,0x21,0x7F,0x00,0x00};//使
const unsigned char hua[]={0x80,0x40,0x20,0xF8,0x07,0x02,0x00,0x00,0xFF,0xC0,0x60,0x30,0x1C,0x08,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x04,0x02,0x01,0x3F,0x40,0x40,0x40,0x40,0x78,0x00,0x00};//化
const unsigned char shang[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x60,0x40,0x00};//上
const unsigned char xia[]={0x00,0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0x22,0x62,0xC2,0x82,0x02,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00};//下
const unsigned char xian[]={0xFE,0x02,0x32,0x4E,0x82,0x00,0xFE,0x4A,0xCA,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0xFF,0x00,0x02,0x04,0x03,0x00,0xFF,0x40,0x20,0x03,0x0C,0x12,0x21,0x60,0x20,0x00};//限
const unsigned char zhu[]={0x10,0x60,0x01,0x86,0x60,0x08,0x08,0x08,0x09,0xFE,0x08,0x08,0x08,0x08,0x08,0x00,0x04,0x04,0xFE,0x01,0x40,0x40,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00};//注
const unsigned char yi[]={0x10,0x10,0x12,0xD2,0x56,0x5A,0xD2,0x53,0x52,0x5A,0x56,0xD2,0x12,0x12,0x10,0x00,0x00,0x20,0x38,0x03,0x3A,0x42,0x42,0x4B,0x52,0x42,0x42,0x63,0x08,0x30,0x00,0x00};//意
const unsigned char she[]={0x40,0x41,0xCE,0x04,0x00,0x80,0x40,0xBE,0x82,0x82,0x82,0xBE,0xC0,0x40,0x40,0x00,0x00,0x00,0x7F,0x20,0x90,0x80,0x40,0x43,0x2C,0x10,0x10,0x2C,0x43,0xC0,0x40,0x00};//設(shè)
const unsigned char zhi[]={0x00,0x20,0x2F,0xA9,0xA9,0xAF,0xE9,0xB9,0xA9,0xAF,0xA9,0xA9,0x2F,0x20,0x00,0x00,0x80,0x80,0x80,0xFF,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xFF,0x80,0x80,0x80,0x00};//置
const unsigned char dang[]={0x00,0x00,0x40,0x42,0x5C,0x48,0x40,0x40,0x7F,0x40,0x50,0x4E,0x44,0xC0,0x00,0x00,0x00,0x00,0x20,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x7F,0x00,0x00};//當(dāng)
const unsigned char qian[]={0x08,0x08,0xE8,0xA8,0xA9,0xAE,0xEA,0x08,0x08,0xC8,0x0C,0x0B,0xEA,0x08,0x08,0x00,0x00,0x00,0x7F,0x04,0x24,0x44,0x3F,0x00,0x00,0x1F,0x40,0x80,0x7F,0x00,0x00,0x00};//前
const unsigned char fang[]={0x00,0xFE,0x22,0x5A,0x86,0x02,0x08,0x08,0xF9,0x8E,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0xFF,0x04,0x08,0x47,0x20,0x18,0x07,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00};//防
const unsigned char shu[]={0x00,0x00,0x40,0x5F,0x55,0x55,0xF5,0x55,0x55,0x55,0xD5,0x5F,0x40,0x00,0x00,0x00,0x11,0x11,0x09,0x09,0xFD,0x55,0x57,0x57,0x55,0x55,0x55,0xFD,0x01,0x01,0x01,0x00};//暑
const unsigned char bao[]={0x40,0x20,0xF8,0x17,0x82,0x80,0xBE,0xA2,0xA2,0xE2,0xA2,0xA2,0xBE,0x80,0x80,0x00,0x00,0x00,0x7F,0x00,0x20,0x10,0x08,0x06,0x01,0x7F,0x03,0x0C,0x18,0x30,0x10,0x00};//保
const unsigned char nuan[]={0x00,0xFC,0x44,0x44,0xFC,0x80,0xA6,0xAA,0xE2,0xA6,0xAA,0xA1,0xA9,0xA5,0x80,0x00,0x00,0x0F,0x04,0x04,0x4F,0x20,0x58,0x46,0x27,0x2A,0x12,0x1A,0x26,0x62,0x20,0x00};//暖
const unsigned char nononono[]={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,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//
const unsigned char danwei_c[]={0x00,0x02,0x05,0xE2,0x18,0x04,0x02,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x40,0x40,0x40,0x40,0x40,0x20,0x18,0x00,0x00};//單位
const unsigned char maohao[]={0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00};//':'
const unsigned char dian[]={0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00};//'.'
const unsigned chardw[]={0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00};//‘W'
const unsigned char uu[]={0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20};//'u'
const unsigned char jj[]={0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00};//'j'
const unsigned char ii[]={0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};//'i'
const unsigned char ee[]={0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00};//'e'
const unsigned char ff[]={0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};//'f'
const unsigned char ll[]={0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};//'l'
const unsigned char aa[]={0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20};//'a'
const unsigned char ss[]={0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00};//'s'
const unsigned char hh[]={0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20};//'h'
const unsigned char vv[]={0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00};//'v'
const unsigned char zhenghao1[]={0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00};//'+'
const unsigned char fuhao1[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01};//'-'
const unsigned char xinghao[]={0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00};//"*'
const unsigned char s1[]={0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};//'1'
const unsigned char s0[]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00};//'0'
const unsigned char s2[]={0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00};/*"2",0*/
const unsigned chars3[]={0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00};/*"3",1*/
const unsigned char s4[]={0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00};/*"4",2*/
const unsigned char s5[]={0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00};/*"5",3*/
const unsigned char s6[]={0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00};/*"6",4*/
const unsigned char s7[]={0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00};/*"7",5*/
const unsigned char s8[]={0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00};/*"8",6*/
const unsigned chars9[]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00};/*"9",7*/
const unsigned char nono[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//空的
const unsigned char juhao[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00};//'.'
const unsigned char zhenghao[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0xFF,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//'+'
const unsigned char fuhao[]={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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//'-'
const unsigned char ss0[]={0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x40,0x40,0x40,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xFE,0x0F,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0xFE,0xF0,0x00,0x00,0x00,0x1F,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x06,0x04,0x04,0x04,0x06,0x03,0x01,0x00,0x00,0x00};//0
const unsigned char ss1[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x06,0x07,0x07,0x06,0x04,0x04,0x04,0x00,0x00,0x00};//1
const unsigned char ss2[]={0x00,0x00,0x00,0x00,0x80,0x40,0x40,0x40,0x40,0x40,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1E,0x19,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC1,0x7F,0x3E,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x07,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x07,0x01,0x00,0x00};//2
const unsigned char ss3[]={0x00,0x00,0x00,0x80,0x80,0x40,0x40,0x40,0x40,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x80,0x80,0x80,0xC0,0x61,0x3F,0x1E,0x00,0x00,0x00,0x00,0x00,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0xFE,0x78,0x00,0x00,0x00,0x00,0x01,0x03,0x02,0x04,0x04,0x04,0x04,0x04,0x02,0x03,0x01,0x00,0x00,0x00};//3
const unsigned char ss4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x30,0x0C,0x02,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x10,0x1C,0x12,0x11,0x10,0x10,0x10,0x10,0xFF,0xFF,0xFF,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x0F,0x0F,0x0F,0x08,0x08,0x08,0x00};//4
const unsigned char ss5[]={0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0xF8,0x87,0x40,0x20,0x20,0x20,0x20,0x60,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0xE0,0x61,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0x7E,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x04,0x04,0x04,0x04,0x04,0x02,0x03,0x01,0x00,0x00,0x00};//5
const unsigned char ss6[]={0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x40,0x40,0x40,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0xE0,0xFC,0x0E,0x81,0x80,0x40,0x40,0x40,0x40,0xC0,0x83,0x03,0x00,0x00,0x00,0x00,0x3F,0xFF,0xC3,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0x7E,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x06,0x04,0x04,0x04,0x04,0x02,0x03,0x01,0x00,0x00};//6
const unsigned char ss7[]={0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x0F,0x03,0x01,0x00,0x00,0x00,0x80,0x60,0x18,0x06,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFC,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//7
const unsigned char ss8[]={0x00,0x00,0x00,0x00,0x80,0xC0,0x40,0x40,0x40,0x40,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x3F,0x71,0xE0,0xC0,0x80,0x80,0x80,0x80,0x61,0x3F,0x1E,0x00,0x00,0x00,0xF8,0xFC,0x06,0x03,0x01,0x00,0x01,0x01,0x03,0x07,0x0E,0xFC,0xF8,0x00,0x00,0x00,0x00,0x01,0x03,0x02,0x04,0x04,0x04,0x04,0x04,0x02,0x03,0x01,0x00,0x00,0x00};//8
const unsigned char ss9[]={0x00,0x00,0x00,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0xFE,0xF8,0x00,0x00,0x00,0x00,0x81,0x83,0x06,0x04,0x04,0x04,0x04,0x02,0x83,0xF1,0x7F,0x0F,0x00,0x00,0x00,0x00,0x03,0x03,0x04,0x04,0x04,0x04,0x06,0x03,0x01,0x00,0x00,0x00,0x00,0x00};//9
const unsigned char nonono[]={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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//9
const unsigned char danwei_c1[]={0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x10,0x10,0xF0,0x00,0x00,0x00,0x80,0xc0,0x60,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x00,0xfC,0xff,0x07,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x7f,0xf0,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x03};//℃
const unsigned char danwei_c2[]={0x30,0x30,0x10,0x10,0x10,0x20,0x20,0x20,0x40,0x80,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x02,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00};
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
////////////////////////基本子函數(shù)///////////////////////
//延時(shí)
void delay(char x,char y)
{
char z;
do{
z=y;
do{;}while(--z);
}while(--x);
}
//其指令時(shí)間為:7+(3*(Y-1)+7)*(X-1)如果再加上函數(shù)調(diào)用的call 指令、頁(yè)面設(shè)定、傳遞參數(shù)花掉的7 個(gè)指令。
//則是:14+(3*(Y-1)+7)*(X-1)。
//--------------------------------------------------
//系統(tǒng)初始化函數(shù)
void init()
{
ADCON1=0X07; //設(shè)置A口為普通數(shù)字口
TRISA=0X00; //設(shè)置A口方向?yàn)檩敵?br /> TRISD=0X00; //設(shè)置D口方向?yàn)檩敵?br />}
//-----------------------------------------------
//復(fù)位DS18B20函數(shù)(*一定要注意延時(shí),我曾經(jīng)在這上差點(diǎn)搞暈*)
reset(void)
{
char presence=1;
while(presence)
{
DQ_LOW() ; //主機(jī)拉至低電平
delay(2,90); //延時(shí)>480503us
DQ_HIGH(); //釋放總線等電阻拉高總線,并保持15~60us
delay(2,8); //延時(shí)>60us
if(DQ==1) presence=1; //沒(méi)有接收到應(yīng)答信號(hào),繼續(xù)復(fù)位
else presence=0; //接收到應(yīng)答信號(hào)
delay(2,70); //延時(shí)>240us
}
}
//-----------------------------------------------
//寫(xiě)18b20寫(xiě)字節(jié)函數(shù)
void write_byte(uch val)
{
uch i;
uch temp;
for(i=8;i>0;i--)
{
temp=val&0x01; //最低位移出
DQ_LOW();
NOP();
NOP();
NOP();
NOP();
NOP(); //從高拉至低電平,產(chǎn)生寫(xiě)時(shí)間隙
if(temp==1) DQ_HIGH(); //如果寫(xiě)1,拉高電平
delay(2,7); //延時(shí)>60us
DQ_HIGH();
NOP();
NOP();
val=val>>1; //右移一位
}
}
//------------------------------------------------
//18b20讀字節(jié)函數(shù)
uch read_byte(void)
{
uch i;
uch value=0; //讀出溫度
static bit j;
for(i=8;i>0;i--)
{
value>>=1;
DQ_LOW();
NOP();
NOP();
NOP();
NOP(); //6us
DQ_HIGH(); //拉至高電平
NOP();
NOP();
NOP(); //4us
j=DQ;
if(j) value|=0x80;
delay(2,7); //63us
}
return(value);
}
//-------------------------------------------------
//啟動(dòng)溫度轉(zhuǎn)換函數(shù)
void get_temp()
{
int i;
DQ_HIGH();
reset(); //復(fù)位等待從機(jī)應(yīng)答
write_byte(0XCC); //忽略ROM匹配
write_byte(0X44); //發(fā)送溫度轉(zhuǎn)化命令
for(i=10;i>0;i--)
{
delay(201,132);
}
reset(); //再次復(fù)位,等待從機(jī)應(yīng)答
write_byte(0XCC); //忽略ROM匹配
write_byte(0XBE); //發(fā)送讀溫度命令
TLV=read_byte(); //讀出溫度低8
THV=read_byte(); //讀出溫度高8位
DQ_HIGH(); //釋放總線
TZ=(TLV>>4)|(THV<<4); //溫度整數(shù)部分
}
//--------------------------------------------------
void LCDdelay()
{
unsigned int i=500;
while(i--)
{;}
}
/*----------------------------------------------------*/
//狀態(tài)檢查
void CheckState()
{
unsigned int dat;
RW=1; //讀狀態(tài)
DI=0;
TRISB=0xff; //設(shè)置口為輸入
while(1)
{
E=1; //高電平讀數(shù)據(jù)
dat=PORTB&0x90; //當(dāng)4、7位為0時(shí)為正常狀態(tài)
E=0;
if(dat==0x00)break;
}
TRISB=0x00; //恢復(fù)口為輸出
}
/*----------------------------------------------------*/
//寫(xiě)顯示數(shù)據(jù)
//dat:顯示數(shù)據(jù)
void WriteData(unsigned char dat)
{
CheckState();
DI=1; //寫(xiě)數(shù)據(jù)
RW=0;
PORTB=dat;
E=1;
E=0;
}
/*---------------------------------------------------*/
//寫(xiě)指令
//command:操作LCD的指令
void WriteCommand(unsigned char dat)
{
CheckState();
RW=0; //寫(xiě)指令
PORTB=dat;
E=1;
E=0;
}
/*---------------------------------------------------*/
//設(shè)定頁(yè)地址----X:0--7
void SetLine(unsigned char line)
{
line=line&0x07; //0<=line<=7
line=line|0xb8;
WriteCommand(line);
}
/*---------------------------------------------------*/
//設(shè)定列地址----Y:0--63
void SetColumn(unsigned char column)
{
column=column&0x3f; //0<=column<=63
column=column|0x40;
WriteCommand(column);
}
/*--------------------------------------------------*/
//設(shè)定開(kāi)始行
void SetStartLine(unsigned char startline)
{
startline=startline&0x3f; //0<=startline<=63
startline=startline|0xc0;
WriteCommand(startline);
}
/*--------------------------------------------------*/
//開(kāi)關(guān)顯示
//1:開(kāi)顯示 0:關(guān)顯示
void SetOnOff(unsigned char state)
{
state=state|0x3e;
WriteCommand(state);
}
/*--------------------------------------------------*/
//選擇屏幕
//screen: 1:左屏 2:右屏
void SlectScreen(unsigned char screen)
{
switch(screen)
{
case 1: CSA=0;
CSB=1;//左屏
break;
case 2: CSA=1;
CSB=0;//右屏
break;
}
}
/*--------------------------------------------------*/
//清屏
//screen: 1:左屏 2:右屏
void ClearScreen(unsigned char screen)
{
unsigned char i,j;
SlectScreen(screen);
for(i=0;i<8;i++)
{
SetLine(i);
for(j=0;j<64;j++)
{
WriteData(0x00);
WriteData(0x00);
}
}
}
/*---------------------------------------------------*/
//顯示一個(gè)16X16的漢字
void Show16X16(unsigned char line,unsigned char column,const unsigned char *pt)
{
unsigned char i,column_temp;
column_temp=column;
SlectScreen(1); //選通左屏
SetColumn(column); //設(shè)置起始列
SetLine(line); //設(shè)置行
for(i=0;i<16;i++)
{
if(column>=64) //如果列>=64,則選通右屏
{
SlectScreen(2);
column=column%64; //設(shè)置右屏起始列
SetColumn(column);
SetLine(line);
}
WriteData(*pt); //寫(xiě)數(shù)據(jù)
*pt++;
column++;
}
SlectScreen(1);
SetLine(line+1); //設(shè)置漢字下半部分顯示頁(yè)
column=column_temp;
SetColumn(column);
for(i=0;i<16;i++)
{
if(column>=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+1);
}
WriteData(*pt);
*pt++;
column++;
}
}
/*-------------------------------------------------------*/
//顯示一個(gè)8X16的字符
void Show8X16(unsigned char line,unsigned char column,const unsigned char *pt)
{
unsigned char i,column_temp;
column_temp=column;
SlectScreen(1); //選通左屏
SetColumn(column); //設(shè)置起始列
SetLine(line); //設(shè)置行
for(i=0;i<8;i++)
{
if(column>=64) //如果列>=64,則選通右屏
{
SlectScreen(2);
column=column%64; //設(shè)置右屏起始列
SetColumn(column);
SetLine(line);
}
WriteData(*pt); //寫(xiě)數(shù)據(jù)
*pt++;
column++;
}
SlectScreen(1);
SetLine(line+1); //設(shè)置漢字下半部分顯示頁(yè)
column=column_temp;
SetColumn(column);
for(i=0;i<8;i++)
{
if(column>=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+1);
}
WriteData(*pt);
*pt++;
column++;
}
}
/*-------------------------------------------------------*/
//顯示一個(gè)16X32的字符
void Show16X32(unsigned char line,unsigned char column,const unsigned char *pt)
{
unsigned char i,column_temp1,column_temp2,column_temp3;
column_temp1=column;
column_temp2=column;
column_temp3=column;
SlectScreen(1); //選通左屏
SetColumn(column); //設(shè)置起始列
SetLine(line); //設(shè)置行
for(i=0;i<16;i++)
{
if(column>=64) //如果列>=64,則選通右屏
{
SlectScreen(2);
column=column%64; //設(shè)置右屏起始列
SetColumn(column);
SetLine(line);
}
WriteData(*pt); //寫(xiě)數(shù)據(jù)
*pt++;
column++;
}
SlectScreen(1);
SetLine(line+1);
column=column_temp1;
SetColumn(column);
for(i=0;i<16;i++)
{
if(column>=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+1);
}
WriteData(*pt);
*pt++;
column++;
}
SlectScreen(1);
SetLine(line+2);
column=column_temp2;
SetColumn(column);
for(i=0;i<16;i++)
{
if(column>=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+2);
}
WriteData(*pt);
*pt++;
column++;
}
SlectScreen(1);
SetLine(line+3);
column=column_temp3;
SetColumn(column);
for(i=0;i<16;i++)
{
if(column>=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+3);
}
WriteData(*pt);
*pt++;
column++;
}
}
/*-------------------------------------------------------*/
//寫(xiě)入變化的參數(shù)子程序
void ChangeTemp1(int val)
{
int D_ge,D_shi,D_bai;
if(val>0)
{
Show8X16(2,72,zhenghao1); //如果大于0,顯示正號(hào)
}
if(val<0)
{
val=0-val;//去除負(fù)號(hào)
Show8X16(2,72,fuhao1); //如果小于0,顯示負(fù)號(hào)
}
if(val==0)
{
Show8X16(2,72,nono); //等于0不顯示符號(hào)
}
D_ge=val%10; //取個(gè)位
D_shi=val%100/10; //取十位
D_bai=val/100; //取百位
switch(D_ge)
{
case 0:{Show8X16(2,96,s0);break;}
case 1:{Show8X16(2,96,s1);break;}
case 2:{Show8X16(2,96,s2);break;}
case 3:{Show8X16(2,96,s3);break;}
case 4:{Show8X16(2,96,s4);break;}
case 5:{Show8X16(2,96,s5);break;}
case 6:{Show8X16(2,96,s6);break;}
case 7:{Show8X16(2,96,s7);break;}
case 8:{Show8X16(2,96,s8);break;}
case 9:{Show8X16(2,96,s9);break;}
}
switch(D_shi)
{
case 0:{Show8X16(2,88,s0);break;}
case 1:{Show8X16(2,88,s1);break;}
case 2:{Show8X16(2,88,s2);break;}
case 3:{Show8X16(2,88,s3);break;}
case 4:{Show8X16(2,88,s4);break;}
case 5:{Show8X16(2,88,s5);break;}
case 6:{Show8X16(2,88,s6);break;}
case 7:{Show8X16(2,88,s7);break;}
case 8:{Show8X16(2,88,s8);break;}
case 9:{Show8X16(2,88,s9);break;}
}
switch(D_bai)
{
case 0:{Show8X16(2,80,s0);break;}
case 1:{Show8X16(2,80,s1);break;}
case 2:{Show8X16(2,80,s2);break;}
case 3:{Show8X16(2,80,s3);break;}
case 4:{Show8X16(2,80,s4);break;}
case 5:{Show8X16(2,80,s5);break;}
case 6:{Show8X16(2,80,s6);break;}
case 7:{Show8X16(2,80,s7);break;}
case 8:{Show8X16(2,80,s8);break;}
case 9:{Show8X16(2,80,s9);break;}
}
}
/*-------------------------------------------------------*/
void ChangeTemp2(int val)
{
int D_ge,D_shi,D_bai;
if(val>0)
{
Show8X16(4,72,zhenghao1);
}
if(val<0)
{
val=0-val;
Show8X16(4,72,fuhao1);
}
if(val==0)
{
Show8X16(4,72,nono);
}
D_ge=val%10;
D_shi=val%100/10;
D_bai=val/100;
switch(D_ge)
{
case 0:{Show8X16(4,96,s0);break;}
case 1:{Show8X16(4,96,s1);break;}
case 2:{Show8X16(4,96,s2);break;}
case 3:{Show8X16(4,96,s3);break;}
case 4:{Show8X16(4,96,s4);break;}
case 5:{Show8X16(4,96,s5);break;}
case 6:{Show8X16(4,96,s6);break;}
case 7:{Show8X16(4,96,s7);break;}
case 8:{Show8X16(4,96,s8);break;}
case 9:{Show8X16(4,96,s9);break;}
}
switch(D_shi)
{
case 0:{Show8X16(4,88,s0);break;}
case 1:{Show8X16(4,88,s1);break;}
case 2:{Show8X16(4,88,s2);break;}
case 3:{Show8X16(4,88,s3);break;}
case 4:{Show8X16(4,88,s4);break;}
case 5:{Show8X16(4,88,s5);break;}
case 6:{Show8X16(4,88,s6);break;}
case 7:{Show8X16(4,88,s7);break;}
case 8:{Show8X16(4,88,s8);break;}
case 9:{Show8X16(4,88,s9);break;}
}
switch(D_bai)
{
case 0:{Show8X16(4,80,s0);break;}
case 1:{Show8X16(4,80,s1);break;}
case 2:{Show8X16(4,80,s2);break;}
case 3:{Show8X16(4,80,s3);break;}
case 4:{Show8X16(4,80,s4);break;}
case 5:{Show8X16(4,80,s5);break;}
case 6:{Show8X16(4,80,s6);break;}
case 7:{Show8X16(4,80,s7);break;}
case 8:{Show8X16(4,80,s8);break;}
case 9:{Show8X16(4,80,s9);break;}
}
}
/*-------------------------------------------------------*/
void ChangeTemp3(int val)
{
int D_ge,D_shi,D_bai,sign;
sign=val&0x80;
val=val&0x7f;
if(sign==0)
{
Show16X32(2,20,zhenghao);
}
if(sign)
{
val=(~val+1)&0x7f;
Show16X32(2,20,fuhao);
}
if(val==0)
{
Show16X32(2,20,nonono);
}
D_ge=val%10;
D_shi=val%100/10;
D_bai=val/100;
switch(D_ge)
{
case 0:{Show16X32(2,68,ss0);break;}
case 1:{Show16X32(2,68,ss1);break;}
case 2:{Show16X32(2,68,ss2);break;}
case 3:{Show16X32(2,68,ss3);break;}
case 4:{Show16X32(2,68,ss4);break;}
case 5:{Show16X32(2,68,ss5);break;}
case 6:{Show16X32(2,68,ss6);break;}
case 7:{Show16X32(2,68,ss7);break;}
case 8:{Show16X32(2,68,ss8);break;}
case 9:{Show16X32(2,68,ss9);break;}
}
switch(D_shi)
{
case 0:{Show16X32(2,52,ss0);break;}
case 1:{Show16X32(2,52,ss1);break;}
case 2:{Show16X32(2,52,ss2);break;}
case 3:{Show16X32(2,52,ss3);break;}
case 4:{Show16X32(2,52,ss4);break;}
case 5:{Show16X32(2,52,ss5);break;}
case 6:{Show16X32(2,52,ss6);break;}
case 7:{Show16X32(2,52,ss7);break;}
case 8:{Show16X32(2,52,ss8);break;}
case 9:{Show16X32(2,52,ss9);break;}
}
switch(D_bai)
{
case 0:{Show16X32(2,36,ss0);break;}
case 1:{Show16X32(2,36,ss1);break;}
case 2:{Show16X32(2,36,ss2);break;}
case 3:{Show16X32(2,36,ss3);break;}
case 4:{Show16X32(2,36,ss4);break;}
case 5:{Show16X32(2,36,ss5);break;}
case 6:{Show16X32(2,36,ss6);break;}
case 7:{Show16X32(2,36,ss7);break;}
case 8:{Show16X32(2,36,ss8);break;}
case 9:{Show16X32(2,36,ss9);break;}
}
if(val>=val1)
{
Show16X16(6,32,zhu);
Show16X16(6,48,yi);
Show16X16(6,64,fang);
Show16X16(6,80,shu);
}
if(val<=val2)
{
Show16X16(6,32,zhu);
Show16X16(6,48,yi);
Show16X16(6,64,bao);
Show16X16(6,80,nuan);
}
if((val>val2)&&(val
Show16X16(6,32,nononono);
Show16X16(6,48,nononono);
Show16X16(6,64,nononono);
Show16X16(6,80,nononono);
}
}
/*-------------------------------------------------------*/
//顯示第一頁(yè)的內(nèi)容
void LCDShow1()
{
Show16X16(0,16,wen);//溫
Show16X16(0,32,du);//度
Show16X16(0,48,ce);//測(cè)
Show16X16(0,64,liang);//量
Show16X16(0,80,xi);//系
Show16X16(0,96,tong);//統(tǒng)
Show16X16(2,1,zuo);//作
Show16X16(2,17,zhe);//者
Show8X16(2,33,maohao);//’:‘
Show8X16(2,41,dw);//'w'
Show8X16(2,49,uu);//'u'
Show8X16(2,57,jj);//'j'
Show8X16(2,65,ii);//'i'
Show8X16(2,73,ee);//'e'
Show8X16(2,81,ff);//'f'
Show8X16(2,89,ll);//'l'
Show8X16(2,97,aa);//'a'
Show8X16(2,105,ss);//'s'
Show8X16(2,113,hh);//'h'
Show16X16(4,1,ban);//版
Show16X16(4,17,ben);//本
Show8X16(4,33,maohao);//':’
Show8X16(4,41,vv);//‘v'
Show8X16(4,49,s1);//'1'
Show8X16(4,57,juhao);//'.'
Show8X16(4,65,s0);//'0'
Show16X16(6,20,zheng);//正
Show16X16(6,36,zai);//在
Show16X16(6,52,chu);//初
Show16X16(6,68,shi);//使
Show16X16(6,84,hua);//化
Show8X16(6,100,dian);//’。‘
Show8X16(6,108,dian);//’。‘
Show8X16(6,116,dian);//’。‘
}
/*----------------------------------------------------------*/
//顯示第二頁(yè)子程序
void LCDShow2()
{
Show16X16(0,32,dang);//當(dāng)
Show16X16(0,48,qian);//前
Show16X16(0,64,wen);//溫
Show16X16(0,80,du);//度
//Show16X32(2,20,zhenghao);
//Show16X32(2,52,ss0);
//Show16X32(2,68,ss0);
Show16X32(2,84,danwei_c1);//單位
Show16X32(2,100,danwei_c2);
}
/*----------------------------------------------------------*/
//顯示第三頁(yè)子程序
void LCDShow3()
{
Show16X16(0,48,she);//設(shè)
Show16X16(0,64,zhi);//置
Show16X16(2,0,shang);//上
Show16X16(2,16,xian);//限
Show16X16(2,32,wen);//溫
Show16X16(2,48,du);//度
Show8X16(2,64,maohao);//“:”
ChangeTemp1(val1);//參數(shù)
Show16X16(2,104,danwei_c);//單位
Show16X16(4,0,xia);//下
Show16X16(4,16,xian);//限
Show16X16(4,32,wen);//溫
Show16X16(4,48,du);//度
Show8X16(4,64,maohao);//“:”
ChangeTemp2(val2);//參數(shù)
Show16X16(4,104,danwei_c);//單位
}
/*---------------------------------------------------------*/
//LCD初始化子程序
void LCDinit()
{
int i;
PORTD=0x00;
TRISB=0x00;
PORTB=0x00;
TRISC=0x80;
PORTC=0x00;
TRISC5=1;
TRISC6=1;
SetOnOff(1);//開(kāi)顯示
LCDShow1();//初始畫(huà)面
for(i=30;i>0;i--)//延時(shí)
{
delay(201,132);
}
}
/*----------------------------------------------------------*/
//主函數(shù)
void main()
{
init(); //調(diào)用系統(tǒng)初始化函數(shù)
LCDinit();
ClearScreen(1);//清屏
ClearScreen(2);
LCDShow2();//顯示第二頁(yè)
while(1)
{
get_temp(); //調(diào)用溫度轉(zhuǎn)換函數(shù)
PORTD=TZ;
ChangeTemp3(TZ);
if(RC5==0)
{
while(1)
{
ClearScreen(1);
ClearScreen(2);
LCDShow3();
while(1)//等待RC5鍵松開(kāi)
{
if(RC5==1)break;
}
Show8X16(4,120,nono);
Show8X16(2,120,xinghao);//顯示星號(hào),作指示
while(1)
{
if(RC6==0)
{
val1++;
if(val1>=128)
{
val1=128;
}
ChangeTemp1(val1);
}
if(RC7==0)
{
val1--;
if(val1<=-55)
{
val1=-55;
}
ChangeTemp1(val1);
}
while(1)
{
if((RC6==1)&&(RC7==1))break;//等待鍵松開(kāi)
}
if(RC5==0)break;
}
while(1)
{
if(RC5==1)break;
}
Show8X16(2,120,nono);
Show8X16(4,120,xinghao);
while(1)
{
if(RC6==0)
{
val2++;
if(val2>=128)
{
val2=128;
}
ChangeTemp2(val2);
}
if(RC7==0)
{
val2--;
if(val2<-55)
{
val2=-55;
}
ChangeTemp2(val2);
}
while(1)
{
if((RC6==1)&&(RC7==1))break;
}
if(RC5==0)break;
}
ClearScreen(1);
ClearScreen(2);
LCDShow2();
break;
}
}
}
}
四. 總結(jié)
曾經(jīng)因?yàn)橐痪€總線檢測(cè)存在脈沖的子程序的延時(shí)不對(duì),低電平持續(xù)不到480uS,所以程序一直沒(méi)有進(jìn)展,且找不到問(wèn)題原因,耽擱了好多天,昨天偶然中發(fā)現(xiàn)了這個(gè)原因,一下就成功了,看來(lái)還是不夠仔細(xì).
通過(guò)這個(gè)例子,我掌握了KS0108系列液晶的編程及DS18B20溫度傳感器的使用.但還是有很多不夠完善的地方,如1.程序按鍵不是很靈敏,2.還可以多加些功能,3.有些子程序?qū)懙煤軣?但不管怎么樣,總算寫(xiě)出來(lái)了,有興趣的朋友可以看一下.