?? touch.h~
字號(hào):
//沒有觸摸動(dòng)作時(shí)程序不執(zhí)行,當(dāng)有觸摸時(shí)進(jìn)行掃描采集數(shù)據(jù),每5ms進(jìn)行一次數(shù)據(jù)采集
//占用資源:INT0和TIMER2
//2004.08.09
//#include <mylib.h>
//#define BELL_ON() {DDRB.7=1;PORTB.7=1;}
//#define BELL_OFF() {DDRB.7=1;PORTB.7=0;}
/*#define TX1_1() {PORTE.3=0;DDRE.3=1;}//定義觸摸屏四線端口接通狀態(tài)
#define TX1_0() {PORTE.3=1;DDRE.3=1;}
#define TY1_1() {PORTE.5=0;DDRE.5=1;}
#define TY1_0() {PORTE.5=1;DDRE.5=1;}
#define TX0_1() {PORTE.4=1;DDRE.4=1;}
#define TX0_0() {PORTE.4=0;DDRE.4=1;}
#define TY0_1() {PORTE.6=1;DDRE.6=1;}
#define TY0_0() {PORTE.6=0;DDRE.6=1;}
#define TINT_IN() {DDRE.7=0;} //觸摸屏中斷口為輸入方式
#define TINT_INPUT PINE.7
#define TADX_IN() {DDRF|=1;PORTF&=0XFE;delay_us(50);DDRF&=0XFE;}//觸摸屏ADC端口為輸入方式
#define TADY_IN() {DDRF|=2;PORTF&=0XFD;delay_us(50);DDRF&=0XFD;} */
//unsigned int touch_xdata[20]; //觸摸屏X軸數(shù)據(jù)
//unsigned int touch_ydata[20]; //觸摸屏Y軸數(shù)據(jù)
unsigned char touch_timer1; //觸摸屏定時(shí)放電定時(shí)寄存器
unsigned char touch_timer2; //觸摸屏接收數(shù)據(jù)超時(shí)寄存器
//unsigned char touch_ok; //數(shù)據(jù)接收完成標(biāo)志
//unsigned char touch_press; //觸摸屏狀態(tài),是否按下
unsigned char touch_i; //數(shù)據(jù)接收指針
unsigned int touch_x; //觸摸屏X坐標(biāo)值
unsigned int touch_y; //觸摸屏Y坐標(biāo)值
unsigned char tk1;
unsigned char tk2;
unsigned char tk3;
unsigned char tk4;
unsigned char tk5;
unsigned char tk6;
unsigned char tk7;
unsigned char tk8;
unsigned char tk9;
unsigned char tk10;
extern eeprom unsigned char esd;
unsigned char bell_state;
unsigned char bell_timer;
extern unsigned char picture_number;
/*****************************************************************************
觸摸屏初始化
初始化觸摸屏四線端口、初始化觸摸屏中斷口、初始化ADC端口
******************************************************************************/
/*void touch_init(void){
unsigned char i;
TX1_0() //初始化四線端口
TX0_0()
TY1_1()
TY0_0()
TINT_IN() //觸摸屏中斷斷口為輸入方式
EICRB|=0xC0; //設(shè)置INT7為上升沿觸發(fā),清除中斷標(biāo)志,開中斷
EIFR|=0x80;
EIMSK|=0x80;
TADX_IN() //把觸摸屏ADC端口設(shè)置為輸入
TADY_IN()
} */
/*******************************************************************************
INTO中斷程序(觸摸屏數(shù)據(jù)采集程序)
采用中斷方式,在中斷程序中進(jìn)行ADC轉(zhuǎn)換讀取觸摸屏數(shù)據(jù)
*******************************************************************************/
interrupt[9] int7_touch(void){ //觸摸屏數(shù)據(jù)采集程序
touch_int();
/*unsigned char i;
TADY_IN()
TADX_IN()
if(touch_ok==1)return; //數(shù)據(jù)未處理完成,不再接收數(shù)據(jù)
TX1_0() //啟動(dòng)ADC轉(zhuǎn)換Y軸數(shù)據(jù)
TX0_0()
TY0_1()
TY1_1()
delay_us(400);
for(i=0;i<15;i++){
ADCSRA=0XA3;
ADMUX=0X41;
ADCSRA|=0X40;
while(!ADCSRA.4){;}
touch_ydata[i]=ADC&0X03FF;
}
TY1_0() //啟動(dòng)ADC轉(zhuǎn)換X軸數(shù)據(jù)
TY0_0()
TX1_1();
TX0_1()
delay_us(400);
for(i=0;i<15;i++){
ADCSRA=0XA3;
ADMUX=0X40;
ADCSRA|=0X40;
while(!ADCSRA.4){;}
touch_xdata[i]=ADC&0X03FF;
}
touch_ok=1;
touch_press=1;
EIMSK&=0X7F; //一次數(shù)據(jù)接收完成,關(guān)閉中斷
TX1_0()
TX0_0()
TY1_1()
TY0_0()
TINT_IN()
TADX_IN()
TADY_IN()
EIFR|=0X80; //清除中斷標(biāo)志位
TADY_IN()
TADX_IN() */
}
/*****************************************************************************
觸摸屏程序
計(jì)算觸摸屏坐標(biāo)值
觸摸屏端口100ms定時(shí)放電程序
觸摸屏一次按下只接收20個(gè)數(shù)據(jù),等待放開后再接收下一組數(shù)據(jù)
出口參數(shù):
touch_x:X坐標(biāo)
touch_y:Y坐標(biāo)
*****************************************************************************/
/*void touch_data(void){
unsigned int temp[14];
unsigned long int temp1;
unsigned int i,p;
if(touch_ok==1){
touch_ok=0;
for(i=0;i<9;i++){ //求x坐標(biāo)數(shù)據(jù)
temp[i]=touch_xdata[3+i]; //去掉頭尾3個(gè)數(shù)據(jù)
}
for(p=0;p<8;p++){
i=0; //數(shù)據(jù)排序,
while(i<8){
if(temp[i]>temp[i+1]){
temp1=temp[i+1];
temp[i+1]=temp[i];
temp[i]=temp1;
}
i++;
}
}
temp1=0;
for(i=0;i<5;i++){ //去掉最高和最低4個(gè)值并求和
temp1+=temp[i+2];
}
touch_x=temp1/5; //計(jì)算平均值
for(i=0;i<9;i++){ //求y坐標(biāo)數(shù)據(jù)
temp[i]=touch_ydata[3+i]; //去掉頭尾3個(gè)數(shù)據(jù)
}
for(p=0;p<8;p++){
i=0; //數(shù)據(jù)排序,
while(i<8){
if(temp[i]>temp[i+1]){
temp1=temp[i+1];
temp[i+1]=temp[i];
temp[i]=temp1;
}
i++;
}
}
temp1=0;
for(i=0;i<5;i++){ //去掉最高和最低4個(gè)值并求和
temp1+=temp[i+2];
}
touch_y=temp1/5; //計(jì)算平均值
}
if(touch_press==1){ //一次按下只接收20組數(shù)據(jù),等待放開再接收下一組數(shù)據(jù)
TINT_IN()
if(!TINT_INPUT){
delay_ms(10);
if(!TINT_INPUT){
EIFR|=0X80; //清除中斷標(biāo)志位
EIMSK|=0X80;
touch_press=0;
}
}
}
if(touch_timer1>100){ //定時(shí)放電
TADY_IN()
TADX_IN()
touch_timer1=0;
}
}
*/
/*********************************************************************************
觸摸屏按鍵產(chǎn)生程序
根據(jù)觸摸位置及當(dāng)前狀態(tài)產(chǎn)生相應(yīng)按鍵值
出口參數(shù):tk_data
*********************************************************************************/
void touch_key(void){
float x,y;
unsigned int i,j;
if((touch_x==0)&(touch_y==0))return; //沒有數(shù)據(jù)不處理
x=(float)touch_x*0.78125; //把觸摸屏坐標(biāo)轉(zhuǎn)換為L(zhǎng)CD坐標(biāo)
y=480-(float)touch_y*0.46875;
switch(picture_number){ //在不同界面下產(chǎn)生不同的按鍵
case 1: //界面1
if(touch_comp(x,y,240,200,528,264)==1)tk1=1; //控制按鈕
break;
case 2: //界面2
if(touch_comp(x,y,696,76,776,124)==1)tk2=1; //退出按鈕
else if(touch_comp(x,y,600,192,776,240)==1)tk2=2; //數(shù)據(jù)曲線按鈕
else if(touch_comp(x,y,600,248,776,296)==1)tk2=3; //信息查詢按鈕
else if(touch_comp(x,y,600,304,776,352)==1)tk2=4; //當(dāng)前故障按鈕
else if(touch_comp(x,y,600,360,776,408)==1)tk2=5; //歷史故障按鈕
else if(touch_comp(x,y,600,416,776,464)==1)tk2=6; //系統(tǒng)設(shè)置按鈕
break;
case 3: //界面3
if(touch_comp(x,y,696,76,776,124)==1)tk3=1; //退出按鈕
else if(touch_comp(x,y,600,192,776,240)==1)tk3=2; //數(shù)據(jù)曲線按鈕
else if(touch_comp(x,y,600,248,776,296)==1)tk3=3; //信息查詢按鈕
else if(touch_comp(x,y,600,304,776,352)==1)tk3=4; //當(dāng)前故障按鈕
else if(touch_comp(x,y,600,360,776,408)==1)tk3=5; //歷史故障按鈕
else if(touch_comp(x,y,600,416,776,464)==1)tk3=6; //系統(tǒng)設(shè)置按鈕
else if(touch_comp(x,y,40,136,232,216)==1)tk3=7; //單體電壓按鈕
else if(touch_comp(x,y,312,136,504,216)==1)tk3=8; //單體內(nèi)阻按鈕
else if(touch_comp(x,y,40,232,232,312)==1)tk3=9; //統(tǒng)計(jì)參數(shù)按鈕
else if(touch_comp(x,y,312,232,504,312)==1)tk3=10; //容量計(jì)量按鈕
break;
case 4: //界面4
if(touch_comp(x,y,696,76,776,124)==1)tk4=1; //退出按鈕
else if(touch_comp(x,y,600,192,776,240)==1)tk4=2; //系統(tǒng)設(shè)置按鈕
else if(touch_comp(x,y,600,248,776,296)==1)tk4=3; //信息查詢按鈕
else if(touch_comp(x,y,600,304,776,352)==1)tk4=4; //當(dāng)前故障按鈕
else if(touch_comp(x,y,600,360,776,408)==1)tk4=5; //歷史故障按鈕
else if(touch_comp(x,y,600,416,776,464)==1)tk4=6; //系統(tǒng)設(shè)置按鈕
else if(touch_comp(x,y,600,76,680,124)==1)tk4=7; //上頁(yè)按鈕
else if(touch_comp(x,y,600,132,680,180)==1)tk4=8; //下頁(yè)按鈕
break;
case 5://界面5
//if(touch_comp(x,y,600,76,680,124)==1)tk5=1; //返回按鈕
if(touch_comp(x,y,696,76,776,124)==1)tk5=2; //退出按鈕
else if(touch_comp(x,y,600,192,776,240)==1)tk5=3; //數(shù)據(jù)曲線按鈕
else if(touch_comp(x,y,600,248,776,296)==1)tk5=4; //信息查詢按鈕
else if(touch_comp(x,y,600,304,776,352)==1)tk5=5; //當(dāng)前故障按鈕
else if(touch_comp(x,y,600,360,776,408)==1)tk5=6; //歷史故障按鈕
else if(touch_comp(x,y,600,416,776,464)==1)tk5=7; //系統(tǒng)設(shè)置按鈕
break;
case 6: //界面6
if(touch_comp(x,y,592,76,672,124)==1)tk6=1; //確認(rèn)按鈕
else if(touch_comp(x,y,688,76,768,124)==1)tk6=2; //退出按鈕
else{
for(j=0;j<4;j++){
for(i=0;i<3;i++){
if(touch_comp(x,y,600+i*64,192+j*64,648+i*64,240+j*64)==1)tk6=3+i+3*j;
}
}
}
break;
case 7: //界面7
if(touch_comp(x,y,592,76,672,124)==1)tk7=1; //確認(rèn)按鈕
else if(touch_comp(x,y,688,76,768,124)==1)tk7=2; //退出按鈕
else if(touch_comp(x,y,56,140,200,188)==1)tk7=3; //電池類型
else if(touch_comp(x,y,56,196,200,244)==1)tk7=4; //電池節(jié)數(shù)
else if(touch_comp(x,y,56,244,232,284)==1)tk7=5; //單體過壓值
else if(touch_comp(x,y,56,292,232,340)==1)tk7=6; //單體欠壓值
else if(touch_comp(x,y,56,348,232,396)==1)tk7=7; //差壓報(bào)警值
else {
for(j=0;j<4;j++){
for(i=0;i<3;i++){
if(touch_comp(x,y,600+i*64,192+j*64,648+i*64,240+j*64)==1)tk7=8+i+j*3;
}
}
}
break;
case 8: //界面8
if(touch_comp(x,y,592,76,672,124)==1)tk8=1; //確認(rèn)按鈕
else if(touch_comp(x,y,688,76,768,124)==1)tk8=2; //退出按鈕
else if(touch_comp(x,y,56,140,216,188)==1)tk8=3; //通信地址
else if(touch_comp(x,y,56,196,216,244)==1)tk8=4; //通信速率
else if(touch_comp(x,y,56,284,216,332)==1)tk8=5; //通信協(xié)議
else{
for(j=0;j<4;j++){
for(i=0;i<3;i++){
if(touch_comp(x,y,600+i*64,192+j*64,648+i*64,240+j*64)==1)tk8=6+i+j*3;
}
}
}
break;
case 9:
if(touch_comp(x,y,592,76,672,124)==1)tk9=1; //確認(rèn)按鈕
else if(touch_comp(x,y,688,76,768,124)==1)tk9=2; //退出按鈕
else if(touch_comp(x,y,56,148,280,196)==1)tk9=3; //系統(tǒng)密碼
else if(touch_comp(x,y,56,212,152,260)==1)tk9=4; //日期
else if(touch_comp(x,y,56,276,152,324)==1)tk9=5; //時(shí)間
else{
for(j=0;j<4;j++){
for(i=0;i<3;i++){
if(touch_comp(x,y,600+i*64,192+j*64,648+i*64,240+j*64)==1)tk9=6+i+j*3;
}
}
}
break;
case 10: //界面10
if(touch_comp(x,y,40,136,232,216)==1)tk10=1; //電池參數(shù)按鈕
else if(touch_comp(x,y,312,136,504,216)==1)tk10=2; //后臺(tái)通信按鈕
else if(touch_comp(x,y,40,232,232,312)==1)tk10=3; //密碼時(shí)間按鈕
else if(touch_comp(x,y,688,76,768,124)==1)tk10=4;
break;
default:break;
}
touch_x=0; //數(shù)據(jù)處理完畢,清理數(shù)據(jù)
touch_y=0;
}
/******************************************************************************
******************************************************************************/
/*void bell(void){
if(bell_state==1){
BELL_ON()
bell_timer=0;
bell_state=2;
}
else if(bell_state==2){
if(bell_timer>50){
bell_state=0;
BELL_OFF()
}
}
} */
/*****************************************************************************
觸摸屏處理程序
觸摸屏數(shù)據(jù)采集,過濾及轉(zhuǎn)換成按鍵程序
*****************************************************************************/
void touch(void){
touch_data(); //觸摸屏數(shù)據(jù)處理程序
touch_key(); //觸摸屏按鍵產(chǎn)生程序
bell();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -