Amigo como le podria hacer para conectar el touch, osea si se donde van las patillas pero quiero que me responda al presionar la pantalla y me genere una interrupcion al tocarla por el pin INT0, la necesito usando solo los 4 pines A/D, alguna idea ??
Hola amigo falflores gracias por el aporte de la libreria, quisiera saber si podrias dar un tip de image2code ya que las imagenes de 20X80 no se visualizan muy claras en la glcd, en tu demo la imagen del robot se ve muy clara y checando el programa se que es de 20x80=1600 coincide con las imagenes que trato de convertir.
gracias de antemano
Amigo como le podria hacer para conectar el touch, osea si se donde van las patillas pero quiero que me responda al presionar la pantalla y me genere una interrupcion al tocarla por el pin INT0, la necesito usando solo los 4 pines A/D, alguna idea ??
/*****************************************************************
** Conexion del touchscreen resistivo de 4 hilos
** X+ = RA0/AN0
** Y+ = RA1/AN1
** X- = RA2/AN2
** Y- = RA3/AN3
*****************************************************************/
#include<16F877A.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=20MHz)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
#include<glcd_160x80.h>
void configure()
{
set_tris_A(0x00);
set_tris_B(0x00);
//set_tris_C(0x00);
set_tris_D(0x00);
output_A(0x00);
output_B(0x00);
//output_C(0x00);
output_D(0x00);
setup_adc_ports(AN0_AN1_AN2_AN3_AN4);
setup_adc(ADC_CLOCK_INTERNAL);
}
int16 tmp;
int16 y_min,y_max,x_min,x_max;
int16 y_loc,x_loc,y_rng,x_rng;
int1 flag_boton=0;
char boton[2];
const int8 imagen[80][20] = { // imagen del teclado adaptada
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xE0,0xFF,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x80,0x11,0x00,0x30,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0E,0x58,0x60,0x03,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0F,0x58,0x00,0x06,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x00,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x80,0x03,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x80,0x01,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x00,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x00,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xE0,0x07,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x0B,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x80,0x13,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xE1,0xFF,0x3F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xC0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xE0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x80,0x11,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x06,0x58,0xE0,0x03,0x0B,0x70,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x03,0x58,0x60,0x00,0x0B,0x18,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x03,0x58,0x60,0x00,0x0B,0x0C,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x03,0x58,0xE0,0x03,0x0B,0x7C,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x82,0x0D,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x82,0x0D,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x82,0x1F,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xE0,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x0B,0x00,0x60,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x80,0x13,0x00,0x70,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xE1,0xFF,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xC0,0xFF,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xE0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x80,0x11,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x3F,0x58,0xC0,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1B,0x58,0x60,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x18,0x58,0x60,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x18,0x58,0xE0,0x07,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x18,0x58,0xE0,0x07,0x0B,0xF8,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x60,0x06,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x60,0x06,0x0B,0xE0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x60,0x06,0x0B,0x70,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x03,0x0B,0x38,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x0B,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x80,0x13,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xE1,0xFF,0x3F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xC0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xFF,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x00,0x00,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x00,0x9F,0x81,0x0F,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x0F,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x0D,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x0D,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x00,0x9F,0x9F,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x00,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x00,0x00,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,0x3F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xFF,0xFF,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,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},
{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,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,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,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},
};
/****************************************************************
***** Rutina para mostrar la imagen del teclado ***
****************************************************************/
void put_image() // función para mostrar la imagen declara en el GLCD
{
glcd_go_address(0);
glcd_command_write();
for(i=0;i<80;i++)
{
for(j=0;j<20;j++) glcd_send_byte(imagen[i][j]);
}
}
/**************************************************
******* Lee la coordenada y ********************
**************************************************/
int16 y_pos(void)
{
int16 result;
set_tris_a(0x04);
output_a(0x0A); //Energize X plate, RA1 and RA3
set_adc_channel(2); //Set AN2 as input
delay_us(10);
result = read_adc(); //get Y axis value
if (result != 0)
{
set_tris_a(0x01);
set_adc_channel(0);
delay_us(10);
tmp = (1023 - read_adc());
result = (result + tmp) >> 1;
}
Return(result);
}
/**************************************************
******* Lee la coordenada x ********************
**************************************************/
int16 x_pos(void)
{
int16 result;
set_tris_a(0x02);
output_a(0x05); //Energize X plate, RA1 and RA3
set_adc_channel(1); //Set AN2 as input
delay_us(10);
result = read_adc(); //get Y axis value
if (result != 0)
{
set_tris_a(0x08);
set_adc_channel(3);
delay_us(10);
tmp = (1023 - read_adc());
result = (result + tmp) >> 1;
}
Return(result);
}
/**************************************************
*** Funcion para determinar si la pantalla ***
*** ha sido pulsada o no... ***
**************************************************/
int1 touch(void)
{
int1 resp;
int16 tmp,ty,tx;
resp=false;
ty = y_pos();
if (ty > 0)
{
delay_ms(30);
ty=y_pos();
tx=x_pos();
if (ty > y_min)
{
if(ty < y_max)
{
resp = true;
tmp=(tx - x_min) << 7;
x_loc =(int16)(tmp/x_rng);
if(x_loc > 127) x_loc = 127;
tmp = (ty - y_min) << 6;
y_loc = (int16)(tmp/y_rng);
if(y_loc > 63) y_loc = 63;
}
}
}
return(resp);
}
/*************************************************************
***** Rutina para calibrar la pantalla *******
*************************************************************/
void calibracion()
{
int1 sw;
sw=1;
while(x_pos()==0)
{
glcd_line(1,1,10,1,sw);
glcd_line(1,1,1,10,sw);
glcd_rect(1,1,5,5,YES,SW);
delay_ms(150);
sw=!sw;
}
delay_ms(30);
y_min = y_pos();
x_min = x_pos();
glcd_fill_screen(OFF);
while(x_pos() > 0);
delay_ms(30);
while(x_pos()==0)
{
glcd_line(128,64,128,54,sw);
glcd_line(128,64,118,64,sw);
glcd_rect(123,59,128,64,YES,SW);
delay_ms(150);
sw=!sw;
}
delay_ms(30);
y_max = y_pos();
x_max = x_pos();
y_rng = y_max - y_min;
x_rng = x_max - x_min;
while(x_pos() > 0);
glcd_fill_screen(OFF);
}
/*****************************************************************
****** Determina sobre que boton se ha pulsado ********
*****************************************************************/
int8 boton_act(void)
{
int8 button;
if(((x_loc>2)&&(y_loc>2))&((x_loc<21)&&(y_loc<16))) button = '1';
if(((x_loc>23)&&(y_loc>2))&((x_loc<42)&&(y_loc<16))) button = '2';
if(((x_loc>44)&&(y_loc>2))&((x_loc<63)&&(y_loc<16))) button = '3';
if(((x_loc>2)&&(y_loc>18))&((x_loc<21)&&(y_loc<32))) button = '4';
if(((x_loc>23)&&(y_loc>18))&((x_loc<42)&&(y_loc<32))) button = '5';
if(((x_loc>44)&&(y_loc>18))&((x_loc<63)&&(y_loc<32))) button = '6';
if(((x_loc>2)&&(y_loc>34))&((x_loc<21)&&(y_loc<48))) button = '7';
if(((x_loc>23)&&(y_loc>34))&((x_loc<42)&&(y_loc<48))) button = '8';
if(((x_loc>44)&&(y_loc>34))&((x_loc<63)&&(y_loc<48))) button = '9';
if(((x_loc>2)&&(y_loc>50))&((x_loc<21)&&(y_loc<64))) button = '0';
if(((x_loc>23)&&(y_loc>50))&((x_loc<63)&&(y_loc<64))) button = 'X';
return(button);
}
void main()
{
configure();
glcd_init(GRAPHIC);
calibracion(); //Calibra la pantalla
put_image(); //muestra el teclado
//glcd_init(CHARACTER);
while(TRUE)
{
/*
// Para ver los valores calibrados y sin calibrar, requiere el GLCD en
// modo alfanumérico, comentar glcd_init(GRAPHIC) y put_image() y
// descomentar glcd_init(CHARATER) arriba del while(TRUE)
temp=touch();
printf(glcd_putc,"\f\n\nSin calibrar: (%lu,%lu)\n",x_pos(),y_pos());
printf(glcd_putc,"Calibrado: (%lu,%lu)\n",x_loc,y_loc);
delay_ms(50);
*/
//------------------------------------------------------------------
/*
// dibujar en el GLCD
if(touch()==true)
{
glcd_pixel(x_loc,y_loc,ON);
}
*/
//------------------------------------------------------------------------
// teclado en pantalla con numeros del 1 al 0 y clear
// el boton 1 prende un LED conectado en PIN_D0
// el boton 2 apaga el LED conectado en PIN_D0
if(touch()==true)
{
boton=boton_act();
boton[1]='\0';
if(boton[0]=='1'&&flag_boton==0)
{
flag_boton=1;
output_high(PIN_D0);
}
if(boton[0]!='1'&&flag_boton==1) flag_boton=0;
if(boton[0]=='2'&&flag_boton==0)
{
flag_boton=1;
output_low(PIN_D0);
}
if(boton[0]!='2'&&flag_boton==1) flag_boton=0;
if (boton[0]=='X')
glcd_rect(91,9,100,22,YES,OFF); //Borra el numero mostrado
if ((boton[0]>='0')&&(boton[0]<='9'))
{
glcd_rect(91,9,100,22,YES,OFF); //Borra el numero mostrado antes de
glcd_text57(91,9,boton,2,ON); //escribir uno nuevo..
}
}
}
} Hola amigo falflores excelente aporte yo igual estaba escribiendo una librería para este dispositivo pero es genial que te tomaras el tiempo de escribirla y la gentileza de compartirla aportaso amigo.
Saludos cordiales.
Bonito trabajo te ha quedado, gracias por compartirla.
Te ha quedado muy bien! ((:-))
Saludos!
Adjunto tu libreria al post por si se llega a caer el enlace.
Si te funciona, a ver si me puedes ayudar a modificarlo para que abarque los 160x80 de nuestros GLCD. Espero te sirva. Saludos!!
Gracias muchas gracias por el codigo, pero ahora ando bajo de recursos y estoy con el PIC18F4550 y no para comprar un 16F, lo adapte cambiando toda la cabezera y usando mi reloj interno de 4Mhz, y me sale un error:
Expecting LVALUE such as a variable name or *expression
Hay un prblema con la variable: boton pero no se cual es.
#include<18F4550.h>
#device adc=10
#fuses INTRC,MCLR,NOPROTECT,NOWDT,NOBROWNOUT,PUT,NODEBUG,NOVREGEN,
#use delay(clock=8MHz)setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF);setup_adc_ports(AN0_TO_AN3);en lugar de setup_adc_ports(AN0_AN1_AN2_AN3_AN4);/*****************************************************************
** Conexion del touchscreen resistivo de 4 hilos
** X+ = RA0/AN0
** Y+ = RA1/AN1
** X- = RA2/AN2
** Y- = RA3/AN3
*****************************************************************/
#include<18F4550.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=20MHz)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
#include<glcd_160x80.h>
void configure()
{
set_tris_A(0x00);
set_tris_B(0x00);
//set_tris_C(0x00);
set_tris_D(0x00);
output_A(0x00);
output_B(0x00);
//output_C(0x00);
output_D(0x00);
setup_adc_ports(AN0_TO_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
}
int16 tmp;
int16 y_min,y_max,x_min,x_max;
int16 y_loc,x_loc,y_rng,x_rng;
int1 flag_boton=0;
char boton[2];
const int8 imagen[80][20] = { // imagen del teclado adaptada
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xE0,0xFF,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x80,0x11,0x00,0x30,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0E,0x58,0x60,0x03,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0F,0x58,0x00,0x06,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x00,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x80,0x03,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x80,0x01,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x00,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x00,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xE0,0x07,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x0B,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x80,0x13,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xE1,0xFF,0x3F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xC0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xE0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x80,0x11,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x06,0x58,0xE0,0x03,0x0B,0x70,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x03,0x58,0x60,0x00,0x0B,0x18,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x03,0x58,0x60,0x00,0x0B,0x0C,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x03,0x58,0xE0,0x03,0x0B,0x7C,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x82,0x0D,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x82,0x0D,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x82,0x1F,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xE0,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x0B,0x00,0x60,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x80,0x13,0x00,0x70,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xE1,0xFF,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xC0,0xFF,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xE0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x80,0x11,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x3F,0x58,0xC0,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1B,0x58,0x60,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x18,0x58,0x60,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x18,0x58,0xE0,0x07,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x18,0x58,0xE0,0x07,0x0B,0xF8,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x60,0x06,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x60,0x06,0x0B,0xE0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x60,0x06,0x0B,0x70,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x03,0x0B,0x38,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x0B,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x80,0x13,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xE1,0xFF,0x3F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xC0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xFF,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x00,0x00,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x00,0x9F,0x81,0x0F,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x0F,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x0D,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x0D,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x00,0x9F,0x9F,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x00,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x00,0x00,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,0x3F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xFF,0xFF,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,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},
{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,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,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,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},
};
/****************************************************************
***** Rutina para mostrar la imagen del teclado ***
****************************************************************/
void put_image() // función para mostrar la imagen declara en el GLCD
{
glcd_go_address(0);
glcd_command_write();
for(i=0;i<80;i++)
{
for(j=0;j<20;j++) glcd_send_byte(imagen[i][j]);
}
}
/**************************************************
******* Lee la coordenada y ********************
**************************************************/
int16 y_pos(void)
{
int16 result;
set_tris_a(0x04);
output_a(0x0A); //Energize X plate, RA1 and RA3
set_adc_channel(2); //Set AN2 as input
delay_us(10);
result = read_adc(); //get Y axis value
if (result != 0)
{
set_tris_a(0x01);
set_adc_channel(0);
delay_us(10);
tmp = (1023 - read_adc());
result = (result + tmp) >> 1;
}
Return(result);
}
/**************************************************
******* Lee la coordenada x ********************
**************************************************/
int16 x_pos(void)
{
int16 result;
set_tris_a(0x02);
output_a(0x05); //Energize X plate, RA1 and RA3
set_adc_channel(1); //Set AN2 as input
delay_us(10);
result = read_adc(); //get Y axis value
if (result != 0)
{
set_tris_a(0x08);
set_adc_channel(3);
delay_us(10);
tmp = (1023 - read_adc());
result = (result + tmp) >> 1;
}
Return(result);
}
/**************************************************
*** Funcion para determinar si la pantalla ***
*** ha sido pulsada o no... ***
**************************************************/
int1 touch(void)
{
int1 resp;
int16 tmp,ty,tx;
resp=false;
ty = y_pos();
if (ty > 0)
{
delay_ms(30);
ty=y_pos();
tx=x_pos();
if (ty > y_min)
{
if(ty < y_max)
{
resp = true;
tmp=(tx - x_min) << 7;
x_loc =(int16)(tmp/x_rng);
if(x_loc > 127) x_loc = 127;
tmp = (ty - y_min) << 6;
y_loc = (int16)(tmp/y_rng);
if(y_loc > 63) y_loc = 63;
}
}
}
return(resp);
}
/*************************************************************
***** Rutina para calibrar la pantalla *******
*************************************************************/
void calibracion()
{
int1 sw;
sw=1;
while(x_pos()==0)
{
glcd_line(1,1,10,1,sw);
glcd_line(1,1,1,10,sw);
glcd_rect(1,1,5,5,YES,SW);
delay_ms(150);
sw=!sw;
}
delay_ms(30);
y_min = y_pos();
x_min = x_pos();
glcd_fill_screen(OFF);
while(x_pos() > 0);
delay_ms(30);
while(x_pos()==0)
{
glcd_line(128,64,128,54,sw);
glcd_line(128,64,118,64,sw);
glcd_rect(123,59,128,64,YES,SW);
delay_ms(150);
sw=!sw;
}
delay_ms(30);
y_max = y_pos();
x_max = x_pos();
y_rng = y_max - y_min;
x_rng = x_max - x_min;
while(x_pos() > 0);
glcd_fill_screen(OFF);
}
/*****************************************************************
****** Determina sobre que boton se ha pulsado ********
*****************************************************************/
int8 boton_act(void)
{
int8 button;
if(((x_loc>2)&&(y_loc>2))&((x_loc<21)&&(y_loc<16))) button = '1';
if(((x_loc>23)&&(y_loc>2))&((x_loc<42)&&(y_loc<16))) button = '2';
if(((x_loc>44)&&(y_loc>2))&((x_loc<63)&&(y_loc<16))) button = '3';
if(((x_loc>2)&&(y_loc>18))&((x_loc<21)&&(y_loc<32))) button = '4';
if(((x_loc>23)&&(y_loc>18))&((x_loc<42)&&(y_loc<32))) button = '5';
if(((x_loc>44)&&(y_loc>18))&((x_loc<63)&&(y_loc<32))) button = '6';
if(((x_loc>2)&&(y_loc>34))&((x_loc<21)&&(y_loc<48))) button = '7';
if(((x_loc>23)&&(y_loc>34))&((x_loc<42)&&(y_loc<48))) button = '8';
if(((x_loc>44)&&(y_loc>34))&((x_loc<63)&&(y_loc<48))) button = '9';
if(((x_loc>2)&&(y_loc>50))&((x_loc<21)&&(y_loc<64))) button = '0';
if(((x_loc>23)&&(y_loc>50))&((x_loc<63)&&(y_loc<64))) button = 'X';
return(button);
}
void main()
{
configure();
glcd_init(GRAPHIC);
calibracion(); //Calibra la pantalla
put_image(); //muestra el teclado
//glcd_init(CHARACTER);
while(TRUE)
{
/*
// Para ver los valores calibrados y sin calibrar, requiere el GLCD en
// modo alfanumérico, comentar glcd_init(GRAPHIC) y put_image() y
// descomentar glcd_init(CHARATER) arriba del while(TRUE)
temp=touch();
printf(glcd_putc,"\f\n\nSin calibrar: (%lu,%lu)\n",x_pos(),y_pos());
printf(glcd_putc,"Calibrado: (%lu,%lu)\n",x_loc,y_loc);
delay_ms(50);
*/
//------------------------------------------------------------------
/*
// dibujar en el GLCD
if(touch()==true)
{
glcd_pixel(x_loc,y_loc,ON);
}
*/
//------------------------------------------------------------------------
// teclado en pantalla con numeros del 1 al 0 y clear
// el boton 1 prende un LED conectado en PIN_D0
// el boton 2 apaga el LED conectado en PIN_D0
if(touch()==true)
{
boton=boton_act();
boton[1]='\0';
if(boton[0]=='1'&&flag_boton==0)
{
flag_boton=1;
output_high(PIN_D0);
}
if(boton[0]!='1'&&flag_boton==1) flag_boton=0;
if(boton[0]=='2'&&flag_boton==0)
{
flag_boton=1;
output_low(PIN_D0);
}
if(boton[0]!='2'&&flag_boton==1) flag_boton=0;
if (boton[0]=='X')
glcd_rect(91,9,100,22,YES,OFF); //Borra el numero mostrado
if ((boton[0]>='0')&&(boton[0]<='9'))
{
glcd_rect(91,9,100,22,YES,OFF); //Borra el numero mostrado antes de
glcd_text57(91,9,boton,2,ON); //escribir uno nuevo..
}
}
}
}
Hola falflores creo que este código es para C18 es así? por que lo estoy compilando en CCS 4.128 y creo que ese es el problema jeje me indicas que tienes el MPLAB 8.86 y ese es el compilador de MICROCHIP jeje y yo estoy usando CCS
/*****************************************************************
** Conexion del touchscreen resistivo de 4 hilos
** X+ = RA0/AN0
** Y+ = RA1/AN1
** X- = RA2/AN2
** Y- = RA3/AN3
*****************************************************************/
#include <18F4550.h>
#device adc=10
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48MHz)
#include "usb_bootloader.h"
#include<glcd_160x80.h>
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
void configure()
{
set_tris_A(0x00);
set_tris_B(0x00);
set_tris_C(0x00);
set_tris_D(0x00);
output_A(0x00);
output_B(0x00);
output_C(0x00);
output_D(0x00);
setup_adc_ports(AN0_TO_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF);
}
int16 tmp;
int16 y_min,y_max,x_min,x_max;
int16 y_loc,x_loc,y_rng,x_rng;
int1 flag_boton=0;
char boton[2];
const int8 imagen[80][20] = { // imagen del teclado adaptada
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xE0,0xFF,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x80,0x11,0x00,0x30,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0E,0x58,0x60,0x03,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0F,0x58,0x00,0x06,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x00,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x80,0x03,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x80,0x01,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x00,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x00,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xE0,0x07,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x0B,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x80,0x13,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xE1,0xFF,0x3F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xC0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xE0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x80,0x11,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x06,0x58,0xE0,0x03,0x0B,0x70,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x03,0x58,0x60,0x00,0x0B,0x18,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x03,0x58,0x60,0x00,0x0B,0x0C,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x03,0x58,0xE0,0x03,0x0B,0x7C,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x82,0x0D,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x82,0x0D,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x82,0x1F,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xE0,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x0B,0x00,0x60,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x80,0x13,0x00,0x70,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xE1,0xFF,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xC0,0xFF,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xE0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x80,0x11,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x3F,0x58,0xC0,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1B,0x58,0x60,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x18,0x58,0x60,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x18,0x58,0xE0,0x07,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x18,0x58,0xE0,0x07,0x0B,0xF8,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x60,0x06,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x60,0x06,0x0B,0xE0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x60,0x06,0x0B,0x70,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x03,0x0B,0x38,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x0B,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x80,0x13,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xE1,0xFF,0x3F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xC0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xFF,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x00,0x00,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x00,0x9F,0x81,0x0F,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x0F,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x0D,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x0D,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x00,0x9F,0x9F,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x00,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x00,0x00,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,0x3F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xFF,0xFF,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,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},
{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,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,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,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},
};
/****************************************************************
***** Rutina para mostrar la imagen del teclado ***
****************************************************************/
void put_image() // función para mostrar la imagen declara en el GLCD
{
glcd_go_address(0);
glcd_command_write();
for(i=0;i<80;i++)
{
for(j=0;j<20;j++) glcd_send_byte(imagen[i][j]);
}
}
/**************************************************
******* Lee la coordenada Y ********************
**************************************************/
int16 y_pos(void)
{
int16 result;
// set_tris_a(0x04); //00000100 RA2 (X-)como entrada
set_tris_a(0b00001000); //00001000 RA3 (X-)como entrada
// output_a(0x0A); //00001010 Energize placa Y, RA1(Y+) y RA3(Y-)
output_a(0b00000011); //00000011 Energize placa Y, RA0(Y+) y RA1(Y-)
// set_adc_channel(2); //Selecciono AN2(X-) como entrada analogica
set_adc_channel(3); //Selecciono AN3(X-) como entrada analogica
delay_us(10); //Espero 10 microsegundos
result = read_adc(); //Obtener el valor del eje Y
if (result != 0)
{
// set_tris_a(0x01); //00000001 Pone RA0(X+) como entrada
set_tris_a(0b00000100); //00001000 Pone RA2(X+) como entrada
// set_adc_channel(0); //Selecciono AN0(X+) como entrada analogica
set_adc_channel(2); //Selecciono AN2(X+) como entrada analogica
delay_us(10);
tmp = (1023 - read_adc());
result = (result + tmp) >> 1;
}
Return(result);
}
/**************************************************
******* Lee la coordenada x ********************
**************************************************/
int16 x_pos(void)
{
int16 result;
// set_tris_a(0x02); //00000010 RA1 (Y+)como entrada
set_tris_a(0b00000001); //00000001 RA0 (Y+)como entrada
// output_a(0x05); //00000101 Energize placa X, RA0(X+) y RA2(X-)
output_a(0b00001100); //00001100 Energize placa X, RA2(X+) y RA3(X-)
// set_adc_channel(1); //Selecsiono AN1(Y+) como entrada analogica
set_adc_channel(0); //Selecsiono AN0(Y+) como entrada analogica
delay_us(10); //Espero 10 microsegundos
result = read_adc(); //Obtener el valor del eje X
if (result != 0)
{
// set_tris_a(0x08); //00001000 Pone RA3(Y-) como entrada
set_tris_a(0b00000010); //00001000 Pone RA1(Y-) como entrada
// set_adc_channel(3); //Selecsiono AN3(Y-) como entrada analogica
set_adc_channel(1); //Selecsiono AN1(Y-) como entrada analogica
delay_us(10);
tmp = (1023 - read_adc());
result = (result + tmp) >> 1;
}
Return(result);
}
/**************************************************
*** Funcion para determinar si la pantalla ***
*** ha sido pulsada o no... ***
**************************************************/
int1 touch(void)
{
int1 resp;
int16 tmp,ty,tx;
resp=false;
ty = y_pos();
if (ty > 0)
{
delay_ms(30);
ty=y_pos();
tx=x_pos();
if (ty > y_min)
{
if(ty < y_max)
{
resp = true;
tmp=(tx - x_min) << 7;
x_loc =(int16)(tmp/x_rng);
if(x_loc > 127) x_loc = 127;
tmp = (ty - y_min) << 6;
y_loc = (int16)(tmp/y_rng);
if(y_loc > 63) y_loc = 63;
}
}
}
return(resp);
}
/*************************************************************
***** Rutina para calibrar la pantalla *******
*************************************************************/
void calibracion()
{
int1 sw;
sw=1;
while(x_pos()==0)
{
glcd_line(1,1,10,1,sw);
glcd_line(1,1,1,10,sw);
glcd_rect(1,1,5,5,YES,SW);
delay_ms(150);
sw=!sw;
}
delay_ms(30);
y_min = y_pos();
x_min = x_pos();
glcd_fill_screen(OFF);
while(x_pos() > 0);
delay_ms(30);
while(x_pos()==0)
{
glcd_line(128,64,128,54,sw);
glcd_line(128,64,118,64,sw);
glcd_rect(123,59,128,64,YES,SW);
delay_ms(150);
sw=!sw;
}
delay_ms(30);
y_max = y_pos();
x_max = x_pos();
y_rng = y_max - y_min;
x_rng = x_max - x_min;
while(x_pos() > 0);
glcd_fill_screen(OFF);
}
/*****************************************************************
****** Determina sobre que boton se ha pulsado ********
*****************************************************************/
int8 boton_act(void)
{
int8 button;
if(((x_loc>2)&&(y_loc>2))&((x_loc<21)&&(y_loc<16))) button = '1';
if(((x_loc>23)&&(y_loc>2))&((x_loc<42)&&(y_loc<16))) button = '2';
if(((x_loc>44)&&(y_loc>2))&((x_loc<63)&&(y_loc<16))) button = '3';
if(((x_loc>2)&&(y_loc>18))&((x_loc<21)&&(y_loc<32))) button = '4';
if(((x_loc>23)&&(y_loc>18))&((x_loc<42)&&(y_loc<32))) button = '5';
if(((x_loc>44)&&(y_loc>18))&((x_loc<63)&&(y_loc<32))) button = '6';
if(((x_loc>2)&&(y_loc>34))&((x_loc<21)&&(y_loc<48))) button = '7';
if(((x_loc>23)&&(y_loc>34))&((x_loc<42)&&(y_loc<48))) button = '8';
if(((x_loc>44)&&(y_loc>34))&((x_loc<63)&&(y_loc<48))) button = '9';
if(((x_loc>2)&&(y_loc>50))&((x_loc<21)&&(y_loc<64))) button = '0';
if(((x_loc>23)&&(y_loc>50))&((x_loc<63)&&(y_loc<64))) button = 'X';
return(button);
}
void main()
{
configure();
glcd_init(GRAPHIC);
calibracion(); //Calibra la pantalla
put_image(); //muestra el teclado
//glcd_init(CHARACTER);
while(TRUE)
{
/*
// Para ver los valores calibrados y sin calibrar, requiere el GLCD en
// modo alfanumérico, comentar glcd_init(GRAPHIC) y put_image() y
// descomentar glcd_init(CHARATER) arriba del while(TRUE)
temp=touch();
printf(glcd_putc,"\f\n\nSin calibrar: (%lu,%lu)\n",x_pos(),y_pos());
printf(glcd_putc,"Calibrado: (%lu,%lu)\n",x_loc,y_loc);
delay_ms(50);
*/
//------------------------------------------------------------------
/*
// dibujar en el GLCD
if(touch()==true)
{
glcd_pixel(x_loc,y_loc,ON);
}
*/
//------------------------------------------------------------------------
// teclado en pantalla con numeros del 1 al 0 y clear
// el boton 1 prende un LED conectado en PIN_B0 ****************
// el boton 2 apaga el LED conectado en PIN_B0 ****************
if(touch()==true)
{
boton=boton_act(); //**************Error************
boton[1]='\0';
if(boton[0]=='1'&&flag_boton==0)
{
flag_boton=1;
output_high(PIN_B0); //**************************
}
if(boton[0]!='1'&&flag_boton==1) flag_boton=0;
if(boton[0]=='2'&&flag_boton==0)
{
flag_boton=1;
output_low(PIN_B0); //**************************
}
if(boton[0]!='2'&&flag_boton==1) flag_boton=0;
if (boton[0]=='X')
glcd_rect(91,9,100,22,YES,OFF); //Borra el numero mostrado
if ((boton[0]>='0')&&(boton[0]<='9'))
{
glcd_rect(91,9,100,22,YES,OFF); //Borra el numero mostrado antes de
glcd_text57(91,9,boton,2,ON); //escribir uno nuevo..
}
}
}
}/*****************************************************************
** Conexion del touchscreen resistivo de 4 hilos
** X+ = RA0/AN0
** Y+ = RA1/AN1
** X- = RA2/AN2
** Y- = RA3/AN3
*****************************************************************/
#include <18F4550.h>
#device adc=10
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48MHz)
#include "usb_bootloader.h"
#include<glcd_160x80.h>
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
void configure()
{
set_tris_A(0x00);
set_tris_B(0x00);
set_tris_C(0x00);
set_tris_D(0x00);
output_A(0x00);
output_B(0x00);
output_C(0x00);
output_D(0x00);
setup_adc_ports(AN0_TO_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF);
}
int16 tmp;
int16 y_min,y_max,x_min,x_max;
int16 y_loc,x_loc,y_rng,x_rng;
int1 flag_boton=0;
char boton[2];
const int8 imagen[80][20] = { // imagen del teclado adaptada
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xE0,0xFF,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x80,0x11,0x00,0x30,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0E,0x58,0x60,0x03,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0F,0x58,0x00,0x06,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x00,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x80,0x03,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x80,0x01,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x00,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x00,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xE0,0x07,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x0B,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x80,0x13,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xE1,0xFF,0x3F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xC0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xE0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x80,0x11,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x06,0x58,0xE0,0x03,0x0B,0x70,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x03,0x58,0x60,0x00,0x0B,0x18,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x03,0x58,0x60,0x00,0x0B,0x0C,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x03,0x58,0xE0,0x03,0x0B,0x7C,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x82,0x0D,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x82,0x0D,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x82,0x1F,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x00,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xE0,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x0B,0x00,0x60,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x80,0x13,0x00,0x70,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xE1,0xFF,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xC0,0xFF,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xE0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x80,0x11,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x3F,0x58,0xC0,0x03,0x0B,0x78,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1B,0x58,0x60,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x18,0x58,0x60,0x06,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x18,0x58,0xE0,0x07,0x0B,0xCC,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x18,0x58,0xE0,0x07,0x0B,0xF8,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x60,0x06,0x0B,0xC0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x60,0x06,0x0B,0xE0,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0x60,0x06,0x0B,0x70,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x0C,0x58,0xC0,0x03,0x0B,0x38,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x0B,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x80,0x13,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xE1,0xFF,0x3F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xC0,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x07,0xFF,0xFF,0xFF,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x8C,0x00,0x00,0x00,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x00,0x9F,0x81,0x0F,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x0F,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x0D,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x33,0x58,0x80,0x81,0x81,0x0D,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x80,0x81,0x81,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x1E,0x58,0x00,0x9F,0x9F,0x19,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x02,0x00,0x58,0x00,0x00,0x00,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0x04,0x00,0x9C,0x00,0x00,0x00,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00},
{0xF8,0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,0x3F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0x07,0xFE,0xFF,0xFF,0xFF,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,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},
{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,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,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,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},
};
/****************************************************************
***** Rutina para mostrar la imagen del teclado ***
****************************************************************/
void put_image() // función para mostrar la imagen declara en el GLCD
{
glcd_go_address(0);
glcd_command_write();
for(i=0;i<80;i++)
{
for(j=0;j<20;j++) glcd_send_byte(imagen[i][j]);
}
}
/**************************************************
******* Lee la coordenada Y ********************
**************************************************/
int16 y_pos(void)
{
int16 result;
// set_tris_a(0x04); //00000100 RA2 (X-)como entrada
set_tris_a(0b00001000); //00001000 RA3 (X-)como entrada
// output_a(0x0A); //00001010 Energize placa Y, RA1(Y+) y RA3(Y-)
output_a(0b00000011); //00000011 Energize placa Y, RA0(Y+) y RA1(Y-)
// set_adc_channel(2); //Selecciono AN2(X-) como entrada analogica
set_adc_channel(3); //Selecciono AN3(X-) como entrada analogica
delay_us(10); //Espero 10 microsegundos
result = read_adc(); //Obtener el valor del eje Y
if (result != 0)
{
// set_tris_a(0x01); //00000001 Pone RA0(X+) como entrada
set_tris_a(0b00000100); //00001000 Pone RA2(X+) como entrada
// set_adc_channel(0); //Selecciono AN0(X+) como entrada analogica
set_adc_channel(2); //Selecciono AN2(X+) como entrada analogica
delay_us(10);
tmp = (1023 - read_adc());
result = (result + tmp) >> 1;
}
Return(result);
}
/**************************************************
******* Lee la coordenada x ********************
**************************************************/
int16 x_pos(void)
{
int16 result;
// set_tris_a(0x02); //00000010 RA1 (Y+)como entrada
set_tris_a(0b00000001); //00000001 RA0 (Y+)como entrada
// output_a(0x05); //00000101 Energize placa X, RA0(X+) y RA2(X-)
output_a(0b00001100); //00001100 Energize placa X, RA2(X+) y RA3(X-)
// set_adc_channel(1); //Selecsiono AN1(Y+) como entrada analogica
set_adc_channel(0); //Selecsiono AN0(Y+) como entrada analogica
delay_us(10); //Espero 10 microsegundos
result = read_adc(); //Obtener el valor del eje X
if (result != 0)
{
// set_tris_a(0x08); //00001000 Pone RA3(Y-) como entrada
set_tris_a(0b00000010); //00001000 Pone RA1(Y-) como entrada
// set_adc_channel(3); //Selecsiono AN3(Y-) como entrada analogica
set_adc_channel(1); //Selecsiono AN1(Y-) como entrada analogica
delay_us(10);
tmp = (1023 - read_adc());
result = (result + tmp) >> 1;
}
Return(result);
}
/**************************************************
*** Funcion para determinar si la pantalla ***
*** ha sido pulsada o no... ***
**************************************************/
int1 touch(void)
{
int1 resp;
int16 tmp,ty,tx;
resp=false;
ty = y_pos();
if (ty > 0)
{
delay_ms(30);
ty=y_pos();
tx=x_pos();
if (ty > y_min)
{
if(ty < y_max)
{
resp = true;
tmp=(tx - x_min) << 7;
x_loc =(int16)(tmp/x_rng);
if(x_loc > 127) x_loc = 127;
tmp = (ty - y_min) << 6;
y_loc = (int16)(tmp/y_rng);
if(y_loc > 63) y_loc = 63;
}
}
}
return(resp);
}
/*************************************************************
***** Rutina para calibrar la pantalla *******
*************************************************************/
void calibracion()
{
int1 sw;
sw=1;
while(x_pos()==0)
{
glcd_line(1,1,10,1,sw);
glcd_line(1,1,1,10,sw);
glcd_rect(1,1,5,5,YES,SW);
delay_ms(150);
sw=!sw;
}
delay_ms(30);
y_min = y_pos();
x_min = x_pos();
glcd_fill_screen(OFF);
while(x_pos() > 0);
delay_ms(30);
while(x_pos()==0)
{
glcd_line(128,64,128,54,sw);
glcd_line(128,64,118,64,sw);
glcd_rect(123,59,128,64,YES,SW);
delay_ms(150);
sw=!sw;
}
delay_ms(30);
y_max = y_pos();
x_max = x_pos();
y_rng = y_max - y_min;
x_rng = x_max - x_min;
while(x_pos() > 0);
glcd_fill_screen(OFF);
}
/*****************************************************************
****** Determina sobre que boton se ha pulsado ********
*****************************************************************/
int8 boton_act(void)
{
int8 button;
if(((x_loc>2)&&(y_loc>2))&((x_loc<21)&&(y_loc<16))) button = '1';
if(((x_loc>23)&&(y_loc>2))&((x_loc<42)&&(y_loc<16))) button = '2';
if(((x_loc>44)&&(y_loc>2))&((x_loc<63)&&(y_loc<16))) button = '3';
if(((x_loc>2)&&(y_loc>18))&((x_loc<21)&&(y_loc<32))) button = '4';
if(((x_loc>23)&&(y_loc>18))&((x_loc<42)&&(y_loc<32))) button = '5';
if(((x_loc>44)&&(y_loc>18))&((x_loc<63)&&(y_loc<32))) button = '6';
if(((x_loc>2)&&(y_loc>34))&((x_loc<21)&&(y_loc<48))) button = '7';
if(((x_loc>23)&&(y_loc>34))&((x_loc<42)&&(y_loc<48))) button = '8';
if(((x_loc>44)&&(y_loc>34))&((x_loc<63)&&(y_loc<48))) button = '9';
if(((x_loc>2)&&(y_loc>50))&((x_loc<21)&&(y_loc<64))) button = '0';
if(((x_loc>23)&&(y_loc>50))&((x_loc<63)&&(y_loc<64))) button = 'X';
return(button);
}
void main()
{
configure();
glcd_init(GRAPHIC);
calibracion(); //Calibra la pantalla
put_image(); //muestra el teclado
//glcd_init(CHARACTER);
while(TRUE)
{
/*
// Para ver los valores calibrados y sin calibrar, requiere el GLCD en
// modo alfanumérico, comentar glcd_init(GRAPHIC) y put_image() y
// descomentar glcd_init(CHARATER) arriba del while(TRUE)
temp=touch();
printf(glcd_putc,"\f\n\nSin calibrar: (%lu,%lu)\n",x_pos(),y_pos());
printf(glcd_putc,"Calibrado: (%lu,%lu)\n",x_loc,y_loc);
delay_ms(50);
*/
//------------------------------------------------------------------
/*
// dibujar en el GLCD
if(touch()==true)
{
glcd_pixel(x_loc,y_loc,ON);
}
*/
//------------------------------------------------------------------------
// teclado en pantalla con numeros del 1 al 0 y clear
// el boton 1 prende un LED conectado en PIN_B0 ****************
// el boton 2 apaga el LED conectado en PIN_B0 ****************
if(touch()==true)
{
boton[0]=boton_act(); //****Ya no debe generar el error*******
boton[1]='\0';
if(boton[0]=='1'&&flag_boton==0)
{
flag_boton=1;
output_high(PIN_B0); //**************************
}
if(boton[0]!='1'&&flag_boton==1) flag_boton=0;
if(boton[0]=='2'&&flag_boton==0)
{
flag_boton=1;
output_low(PIN_B0); //**************************
}
if(boton[0]!='2'&&flag_boton==1) flag_boton=0;
if (boton[0]=='X')
glcd_rect(91,9,100,22,YES,OFF); //Borra el numero mostrado
if ((boton[0]>='0')&&(boton[0]<='9'))
{
glcd_rect(91,9,100,22,YES,OFF); //Borra el numero mostrado antes de
glcd_text57(91,9,boton,2,ON); //escribir uno nuevo..
}
}
}
}Hola amigo falflores queria saber como puedo modificar el programa para usar el touch screen en el glcd que cubra los 160X80, otra cosa no he logrado encender la luz de fondo del glcd, por que no se si es como si fuera como los lcd normales de led o use un circuito especial para eso. gracias saludos.