?? lcd128645.c
字號(hào):
//實(shí)驗(yàn)?zāi)康模菏煜?2864LCD的使用
//12864LCD帶中文字庫(kù)
//編程讓12864LCD顯示
//硬件設(shè)置:
//關(guān)斷所有撥碼開(kāi)關(guān)。
#include<pic.h>
#include<pic168xa.h>
__CONFIG(0x1832);
//芯片配置字,看門(mén)狗關(guān),上電延時(shí)開(kāi),掉電檢測(cè)關(guān),低壓編程關(guān),加密,4M晶體HS振蕩
//---------------------液晶顯示相關(guān)定義--------------------------------------
#define rs RC5 //定義LCD的數(shù)據(jù)/命令控制口
//#define rw RC4 //定義LCD的讀/寫(xiě)控制口
//#define e RC3 //定義LCD的使能口
#define rw RE1 //定義LCD的讀/寫(xiě)控制口
#define e RE0 //定義LCD的使能口
#define psb RC2 //定義通信方式控制口
#define rst RC0 //定義復(fù)位口
#define nop() asm("nop") //定義nop()函數(shù)
#define address1 0xa
//#define uint unsigned int;
//#define uchar unsigned char;
union adres0
{ unsigned int y0;
unsigned char adre0[2];
}adresult0;
union adres1
{ unsigned int y1;
unsigned char adre1[2];
}adresult1;
union adres5
{ unsigned int y5;
unsigned char adre5[2];
}adresult5;
unsigned char cnt,cnt1,BGSZ;
//--------------------鍵盤(pán)定義---------------------------------------
unsigned int result_key;
unsigned int k1,k2,k3,k4;
//---------------------有關(guān)現(xiàn)實(shí)中英文顯示現(xiàn)實(shí)數(shù)組-----------------------------
//清除顯示
const unsigned char TABCL[ ]={0xA2,0xA0,0xA2,0xA0,0xA2,0xA0,0xA2,0xA0,0xA2,0xA0,0xA2,0xA0,0xA2,0xA0,0xA2,0xA0};
//宏遠(yuǎn)氧業(yè)
const unsigned char TAB1A[ ]={0xBA,0xEA,0xD4,0xB6,0xD1,0xF5,0xD2,0xB5};
//通風(fēng)
const unsigned char TABTF[ ]={0xCD,0xA8,0xB7,0xE7};
//艙內(nèi)
const unsigned char TABCN[ ]={0xB2,0xD5,0xC4,0xDA};
//壓力
const unsigned char TABYL[ ]={0xD1,0xB9,0xC1,0xA6};
//校準(zhǔn)
const unsigned char TABJZ[ ]={0xD0,0xA3,0xD7,0xBC};
//背光設(shè)置
const unsigned char TABBG[ ]={0xB1,0xB3,0xB9,0xE2,0xC9,0xE8,0xD6,0xC3};
//%%%%%%%%%%%%%%%%%%
const unsigned char TABBB[ ]={0xA3,0xA5};
//WWW.YANGCANG.COM
const unsigned char TAB1B[ ]={'W', 'W','W', '.', 'Y', 'A', 'N', 'G', 'C', 'A', 'N', 'G', '.', 'C', 'O', 'M'};
//TEL0755-28187975
//const unsigned char TAB1C[ ]={'T', 'E', 'L' ,':','0' ,'5', '3' ,'5','-', '6', '3','0', '0' ,'5','5' ,'9'};
const unsigned char TAB1C[ ]={'T', 'E', 'L' ,':',0x30 ,'5', '3' ,'5','-', '6', '3','0', '0' ,'5','5' ,'9'};
//FAX0755-28187976
const unsigned char TAB1D[ ]={'F', 'A', 'X', ':', '0', '5', '3', '5', '-','6', '3','2', '0', '0', '5', '5'};
//SHOW PRESSURE
const unsigned char TABSP[ ]={'S', 'H', 'O', 'W', ' ', 'P', 'R', 'E', 'S','S', 'U','R', 'E'};
//BATTERY:
const unsigned char TABBAR[ ]={'B', 'A', 'T', 'T', 'E', 'R', 'Y', ':'};
//0,1,2,3,4,5,6,7,8,9 半交字符
const unsigned char TABNUM[ ]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
char ee_data_write[2];
unsigned char ee_date[2];
unsigned int n1,n2;
int j1,j2;
//------------------LCD操作定義--------------------------
unsigned int lcd_x; //定義LCD頁(yè)地址寄存器
unsigned int lcd_y; //定義LCD列地址寄存器
bit busy; //定義LCD忙標(biāo)志位
void init(); //申明I/O口設(shè)置函數(shù)
void lcd_init(); //申明LCD初始化函數(shù)
void lcd_init1(); //申明LCD初始化函數(shù)
void clear_p(); //申明清屏函數(shù)
void han_wr2a(); //申明顯示公司名稱函數(shù)
void han_wr2b(); //申明顯示公司web函數(shù)
void han_wr2c(); //申明顯示公司tel函數(shù)
void han_wr2d(); //申明顯示公司fax函數(shù)
void wr_zb(); //申明有關(guān)顯示設(shè)置函數(shù)
void flash(); //申明設(shè)置LCD顯示閃爍函數(shù)
void qushu1(int counts,const unsigned char *ps); //申明查表獲取顯示數(shù)據(jù)//LOGO信息,依次顯示
void qushu11(int counts,const unsigned char *ps); //申明查表獲取顯示數(shù)據(jù)//同時(shí)顯示
void send_d(unsigned char x); //申明送一字節(jié)數(shù)據(jù)顯示函數(shù)
void send_i(unsigned char x); //申明送一字節(jié)控制命令函數(shù)
void write_xy_d(unsigned char x, unsigned char d);
void chk_busy(); //申明檢測(cè)LCD是否工作繁忙函數(shù)
void show1(void); //顯示現(xiàn)實(shí)申明查表獲取顯示數(shù)據(jù)//LOGO信息函數(shù)
void show2(void); //顯示主界面函數(shù)
void show3(void); //顯示菜單函數(shù)
void show4(void); //顯示背光時(shí)間函數(shù)
void write();
void read();
void wrtacktest();
void i2c_idle();
void display_e();
void init_e();
void delay(); //申明延時(shí)函數(shù)1,供各命令之間的延時(shí)和決定顯示快慢
void delay1(); //申明延時(shí)函數(shù)2,用以決定顯示閃爍快慢
void delay_e(); //申明延時(shí)函數(shù)2,用以決定顯示閃爍快慢
void initAD1(); //ad口初始化函數(shù)申明
void initAD2_ref(); //ad口初始化函數(shù)申明
void initAD2_ref_vdd();
void initAD3(); //ad口初始化函數(shù)申明
//--------------------鍵盤(pán)函數(shù)---------------------------------------
void delay_key(); //delay函數(shù)申明
void scan_key(); //按鍵掃描程序申明
void display_key(int x); //顯示函數(shù)申明
void menu_main(); //主菜單函數(shù)
void menu_down(); //向下按鍵
void menu_up(); //向上按鍵
void menu_close(); //退出按鍵
void TF_CHECK(); //通風(fēng)壓力校準(zhǔn)
void CN_CHECK(); //艙內(nèi)壓力校準(zhǔn)
//void display();
//---------------------定時(shí)器函數(shù)-----------------------------------
//void tmint(); //初始化定時(shí)器T0
//void interrupt clkint(void); //中斷服務(wù)程序
//void inizhi(); //定時(shí)參數(shù)初始化
void uinttouchar(unsigned int x); //hex轉(zhuǎn)化成十進(jìn)制
//void adinitial(); //A/D轉(zhuǎn)換初始化子程序
//void interrupt adint(void);
//-------------------------------------------------------------------
//主程序
void main()
{
int result_ad=0x00;
int result_ad1=0x00; //定義轉(zhuǎn)換結(jié)果寄存器
int result_ad2=0x00;
int result_ad_ref=0x00;
int result_ad3=0x00;
unsigned int baifen1,bai1,shi1,ge1,temp1; //定義4個(gè)臨時(shí)變量
unsigned int baifen2,bai2,shi2,ge2,temp2; //定義4個(gè)臨時(shí)變量
unsigned int baifen3,bai3,shi3,ge3,temp3; //定義4個(gè)臨時(shí)變量
//init_e();
//ee_data_write[0]=0x01;
//ee_data_write[1]=0x01;
//write();
//delay_e();
//read(); //讀取修正數(shù)據(jù)
//j1=ee_date[0]&0x0f;
//delay_e();
//j2=ee_date[1]&0x0f;
//delay_e();
show1(); //顯示LOGO信息
k1=0x00;k2=0x00;k3=0x00;k4=0x00;
cnt=0x00;
while(1)
{
int i; //定義循環(huán)次數(shù)控制寄存器
result_ad=0x00; //轉(zhuǎn)換結(jié)果清0
result_ad1=0x00; //轉(zhuǎn)換結(jié)果清0
result_ad2=0x00; //轉(zhuǎn)換結(jié)果清0
result_ad_ref=0x00;
result_ad3=0x00; //轉(zhuǎn)換結(jié)果清0
n1=0x01;
n2=0x02;
//n3=0x00;
//--------------RAO通道AD轉(zhuǎn)化-----------------------
//delay(); /
ADRESH=0;
ADRESL=0;
adresult0.adre0[0]=0;
adresult0.adre0[1]=0;
//delay();
for(i=2;i>0;i--) //求5次轉(zhuǎn)換結(jié)果的平均值
{
initAD1(); //調(diào)用初始化函數(shù)
nop();
ADGO=0X1; //開(kāi)啟轉(zhuǎn)換過(guò)程
delay();
while(ADGO); //等待轉(zhuǎn)換完成
nop();
adresult0.adre0[0]=ADRESL;
adresult0.adre0[1]=ADRESH;
//result_ad1=result_ad1+ADRESL; //累計(jì)轉(zhuǎn)換結(jié)果
result_ad1=result_ad1+adresult0.y0; //累計(jì)轉(zhuǎn)換結(jié)果
//n1=n1+adresult0.y0;
}
result_ad1=result_ad1/2;
result_ad1=result_ad1-n1;
//n1=n1/5;
if (result_ad1<102) result_ad1=102;
if (result_ad1>=102)
if (result_ad1<166) temp1=result_ad1*21-2182+10; //if (result_ad1<166) temp1=result_ad1*21-2182+88 >=0mpa <0.135mpa
//if (result_ad1<99) temp1=result_ad1*362-23252; // >=0mpa <0.13mpa
if (result_ad1>=166)
if (result_ad1<217) temp1=result_ad1*21-2182+10; // >=0.135mpa <0.245mpa
//if (result_ad1<125) temp1=result_ad1*362-23252; // >=0.13mpa <0.23mpa
if (result_ad1>=217)
if (result_ad1<265) temp1=result_ad1*21-2182+10; // >=0.245mpa <0.345mpa
//if (result_ad1<148) temp1=result_ad1*362-23252; // >=0.23mpa <0.32mpa
if (result_ad1>=265)
if (result_ad1<331) temp1=result_ad1*21-2182+10; // >=0.345mpa <0.485mpa
if (result_ad1>=331)
if (result_ad1<368) temp1=result_ad1*21-2182+10; // >=0.485mpa <0.565mpa
if (result_ad1>=368)
if (result_ad1<430) temp1=result_ad1*21-2182+10; // >=0.565mpa <0.695mpa\
if (result_ad1>=430)
if (result_ad1<494) temp1=result_ad1*21-2182+10; // >=0.695mpa <0.83mpa
if (result_ad1>=494)
if (result_ad1<543) temp1=result_ad1*21-2182+10; // >=0.83mpa <0.935mpa
if (result_ad1>=543) temp1=result_ad1*21-2182+10; // >=0.935mpa
temp1=temp1;
//temp1=temp1/10;
temp1=temp1;
if (temp1<100)
{
//if (temp1>50) baifen1=temp1/10;
//if (temp1<=50) baifen1=0;
baifen1=0;
bai1=0;
shi1=0;
ge1=0;
}
if (temp1>=100)
if (temp1<1000)
{
baifen1=(temp1%100)/10;
bai1=0;
shi1=0;
ge1=temp1/100;
}
if (temp1>=1000)
if (temp1<10000)
{
baifen1=((temp1%1000)%100)/10;
bai1=0;
shi1=temp1/1000;
ge1=(temp1%1000)/100;
}
if (temp1>=10000)
{
baifen1=(((temp1%10000)%1000)%100)/10;
bai1=temp1/10000;
shi1=(temp1%10000)/1000;
ge1=((temp1%10000)%1000)/100;
}
//temp1=result_ad1;
//bai1=temp1/0x64; //求顯示的百位
//shi1=(temp1%0x64)/0xa; //求顯示的十位
//ge1=(temp1%0x64)%0xa; //求顯示的個(gè)位
//baifen1=((temp1%0x64)%0xa)/10;
//--------------RA1通道AD轉(zhuǎn)化-----------------------
/* adresult1.adre1[0]=0;
adresult1.adre1[1]=0;
//delay();
for(i=5;i>0;i--) //求5次轉(zhuǎn)換結(jié)果的平均值
{
initAD2_ref_vdd(); //調(diào)用初始化函數(shù)
nop();
ADGO=0X1; //開(kāi)啟轉(zhuǎn)換過(guò)程
//delay();
while(ADGO); //等待轉(zhuǎn)換完成
adresult1.adre1[0]=adresult1.adre1[0]+ADRESL;
adresult1.adre1[1]=adresult1.adre1[1]+ADRESH;
result_ad_ref=result_ad_ref+ADRESL; //累計(jì)轉(zhuǎn)換結(jié)果
}
result_ad_ref=result_ad_ref/5;
n2=adresult1.adre1[0]/5;
n2=adresult1.adre1[1]/5;
adresult1.y1=adresult1.y1/5;
n2=adresult1.y1;
*/
ADRESH=0;
ADRESL=0;
adresult1.adre1[0]=0;
adresult1.adre1[1]=0;
//delay();
result_ad=0x00; //轉(zhuǎn)換結(jié)果清0
for(i=2;i>0;i--) //求5次轉(zhuǎn)換結(jié)果的平均值
{
initAD2_ref(); //調(diào)用初始化函數(shù)
nop();
ADGO=0X1; //開(kāi)啟轉(zhuǎn)換過(guò)程
delay();
while(ADGO); //等待轉(zhuǎn)換完成
nop();
adresult1.adre1[0]=ADRESL;
adresult1.adre1[1]=ADRESH;
//result_ad2=result_ad2+ADRESL; //累計(jì)轉(zhuǎn)換結(jié)果
result_ad2=result_ad2+adresult1.y1; //累計(jì)轉(zhuǎn)換結(jié)果
}
result_ad2=result_ad2/2;
//n2=adresult1.y1;
result_ad2=result_ad2-n2;
//temp2=result_ad2;
if (result_ad2<105) result_ad2=105;
if (result_ad2>=105)
if (result_ad2<266)
{
temp2=result_ad2*85-9036+120+60;
//temp2=result_ad2*9-904-43*result_ad2/105;
}
//if (result_ad2<266) temp2=result_ad2*9-904-40; // >=0mpa <0.135mpa -43*(result_ad2/105)
//if (result_ad2<152) temp2=result_ad2*158-10593+300; // >=0mpa <0.13mpa
if (result_ad2>=266)
if (result_ad2<388)
{
temp2=result_ad2*85-9036+120+60;
//temp2=result_ad2*9-904-43*result_ad2/105;
//temp2=result_ad2*9-904-110; // >=0.135mpa <0.24mpa
}
if (result_ad2>=388)
if (result_ad2<509) //temp2=result_ad2*9-904-210; // >=0.24mpa <0.34mpa
{
temp2=result_ad2*85-9036+120+60;
//temp2=result_ad2*9-904-43*result_ad2/105;
}
if (result_ad2>=509)
if (result_ad2<625) //temp2=result_ad2*9-904-210; // >=0.34mpa <0.44mpa
{
temp2=result_ad2*85-9036+120+60;
//temp2=result_ad2*9-904-43*result_ad2/105;
}
if (result_ad2>=625)
if (result_ad2<755) //temp2=result_ad2*9-904-310; // >=0.44mpa <0.55mpa
{
temp2=result_ad2*85-9036+120+60;
//temp2=result_ad2*9-904-43*result_ad2/105;
}
if (result_ad2>=755) //temp2=result_ad2*9-904-310; // >=0.55mpa
{
temp2=result_ad2*85-9036+120+60;
//temp2=result_ad2*9-904-43*result_ad2/105;
}
temp2=temp2;
temp2=temp2/10;
temp2=temp2;
if (temp2<100)
{
//if (temp2>50) baifen1=temp2/10;
//if (temp2<=50) baifen2=0;
baifen2=0;;
bai2=0;
shi2=0;
ge2=0;
}
if (temp2>=100)
if (temp2<1000)
{
baifen2=(temp2%100)/10;
bai2=0;
shi2=0;
ge2=temp2/100;
}
if (temp2>=1000)
if (temp2<10000)
{
baifen2=((temp2%1000)%100)/10;
bai2=0;
shi2=temp2/1000;
ge2=(temp2%1000)/100;
}
if (temp2>=10000)
{
baifen2=(((temp2%10000)%1000)%100)/10;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -