#include #include #use delay(clock=11059200) #fuses HS, NOWDT, NOPROTECT, NOLVP, NOBROWNOUT #define x_mais PIN_B6 //X+ #define y_mais PIN_B7 //Y+ #define x_menos PIN_C0 //X- #define y_menos PIN_C1 //Y- void adc_init(); void bottom1(float x,float y); void bottom2(float x,float y); void bottom3(float x,float y); void bottom4(float x,float y); int bottom5(float x,float y,int on_off); int greeting(float x,float y,int z); void main() { long px, py,auxy,auxx; int x=0,z=0,y=0; char tx[],ty[]; set_tris_A (0xFF); // Configura Port_A como entrada set_tris_B (11000000); // Configura Port_B como saida / entrada(B6/B7) set_tris_C (0x00); // Configura Port_C como saida adc_init(); glcd_init(ON); while (true) { /* Tratando X drive touch */ output_low(y_menos); output_float(y_mais); output_low(x_mais); output_high(x_menos); /* Lendo analogica 0 */ set_adc_channel(0); //habitila anal?ica 0 delay_ms(5); px=(read_adc()); //guarda valor de 8bits na variavel posx auxx=px; if(px < 23) px = 120; /* Fator de escala pra x */ else px=(px*0.52)-10; /* Tratando Y drive touch */ output_low(x_menos); output_float(x_mais); output_low(y_mais); output_high(y_menos); /* Lendo analogica 1 */ set_adc_channel(1); //habitila anal?ica 1 delay_ms(5); py=(read_adc()); //guarda valor de 8bits na variavel posy auxy=py; if(py < 57 || py > 238) px = 120; /* Fator de escala pra y */ else py=(py*0.36)-21; /* Tela de apresenta??o e trunca o programa enquanto nao clicar no botao (quadrado) */ if(z==0) z=greeting(px,py,z); else{ /* Verifica se um dos bot?es da parte lateral da pel?cula foi acionada */ bottom1(auxx,auxy); bottom2(auxx,auxy); bottom3(auxx,auxy); bottom4(auxx,auxy); x=bottom5(auxx,auxy,x); glcd_pixel(px, py, ON); } } } void adc_init(){ setup_adc_ports (RA0_RA1_RA3_ANALOG); SETUP_ADC(ADC_CLOCK_INTERNAL); } int greeting(float x,float y,int z){ int k=0; float px,py; char text1[]="Projeto TouchScreen + 16F877A"; char text2[]="Diogo M."; char text3[]="Michel B."; char text4[]="Pressione o botao"; k=z; px=x; py=y; glcd_text57(1,1,text1,1,ON); glcd_text57(1,30,text2,1,ON); glcd_text57(1,40,text3,1,ON); glcd_text57(1,50,text4,1,ON); glcd_rect(100,40,110,50,NO,ON); if(px > 99 && px < 111){ if(py > 39 && py < 51){ k=1; glcd_fillScreen(OFF); delay_ms(200); } else k=0; } return k; } void bottom1(float x,float y){ float xaux,yaux; char textcase1[]="Clearing Screen"; xaux=x; yaux=y; if(yaux > 26 && yaux <60){ if(xaux > 0 && xaux < 20){ glcd_fillScreen(OFF); glcd_text57(1,30,textcase1,1,ON); delay_ms(250); glcd_fillScreen(OFF); } } } void bottom2(float x,float y){ float xaux,yaux; char textcase1[]="SMS in development"; xaux=x; yaux=y; if(yaux > 72 && yaux <96){ if(xaux > 0 && xaux < 20){ glcd_fillScreen(OFF); glcd_text57(1,30,textcase1,1,ON); } } } void bottom3(float x,float y){ float xaux,yaux; char textcase2[]="Contact list in"; char textcase22[]="development"; xaux=x; yaux=y; if(yaux > 116 && yaux <141){ if(xaux > 0 && xaux < 20){ glcd_fillScreen(OFF); glcd_text57(1,30,textcase2,1,ON); glcd_text57(1,37,textcase22,1,ON); } } } void bottom4(float x,float y){ float xaux,yaux; char textcase3[]="Dial up in"; char textcase33[]="development"; xaux=x; yaux=y; if(yaux > 156 && yaux <182){ if(xaux > 0 && xaux < 20){ glcd_fillScreen(OFF); glcd_text57(1,30,textcase3,1,ON); glcd_text57(1,37,textcase33,1,ON); } } } int bottom5(float x,float y,int on_off){ int z; float xaux,yaux; char textcase4[]="Turning Screen OFF..."; char textcase5[]="Turning ON"; xaux=x; yaux=y; z=on_off; if(yaux > 198 && yaux <228){ if(xaux > 0 && xaux < 20){ if(z==0){ glcd_fillScreen(OFF); glcd_text57(1,30,textcase4,1,ON); delay_ms(1500); glcd_init(OFF); z=1; } else if(z==1){ glcd_init(ON); glcd_text57(1,30,textcase5,1,ON); delay_ms(1000); glcd_text57(1,30,textcase5,1,OFF); z=0; } } } return z; }