I have easypic6 development board and I want to develop touch panel and GLCD applications on pic18f452.
But when I tried the touch panel example (in mikroC compiler examples) after making some modifications to suit pic18F452(as it is originally designed to suit pic16F887), I got the writings clear on the screen, but the touch screen does not work.
I suppose that the configuration of ADCON1 is the source of the problem now.
As I understand, it needs to change A0 and A1 to analog inputs, while all other port A pins are digital output.
Can anyone here help me in this problem ?
Thanks
But when I tried the touch panel example (in mikroC compiler examples) after making some modifications to suit pic18F452(as it is originally designed to suit pic16F887), I got the writings clear on the screen, but the touch screen does not work.
I suppose that the configuration of ADCON1 is the source of the problem now.
As I understand, it needs to change A0 and A1 to analog inputs, while all other port A pins are digital output.
Rich (BB code):
/*
* Project name:
TouchPanelWrite (Demo for working with TouchPanel Controller)
* Copyright:
(c) Mikroelektronika, 2010.
* Revision History:
20100203:
- initial release;
* Description:
This code works with TouchPanel and GLCD. Two digital output and
two analog input signals are used for communication with TouchPanel.
This example is for writing on the screen, calibration constants for touch
panel are set via library function.
* Test configuration:
MCU: PIC16F887
http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf
Dev.Board: EasyPIC6 - ac:Touch_Panel
http://www.mikroe.com/eng/products/view/297/easypic6-development-system/
Oscillator: HS, 08.0000 MHz
Ext. Modules: GLCD 128x64, Touch Panel
http://www.mikroe.com/eng/categories/view/43/components/
SW: mikroC PRO for PIC
http://www.mikroe.com/eng/products/view/7/mikroc-pro-for-pic/
* Notes:
- Turn on GLCD backlight switch SW8.8.
- Turn on TouchPanel Controller switches SW9.5, SW9.6, SW9.7 and SW9.8.
- Turn off PORTA LEDs SW9.1.
*/
// Glcd module connections
char GLCD_DataPort at PORTD;
sbit GLCD_CS1 at RB0_bit;
sbit GLCD_CS2 at RB1_bit;
sbit GLCD_RS at RB2_bit;
sbit GLCD_RW at RB3_bit;
sbit GLCD_EN at RB4_bit;
sbit GLCD_RST at RB5_bit;
sbit GLCD_CS1_Direction at TRISB0_bit;
sbit GLCD_CS2_Direction at TRISB1_bit;
sbit GLCD_RS_Direction at TRISB2_bit;
sbit GLCD_RW_Direction at TRISB3_bit;
sbit GLCD_EN_Direction at TRISB4_bit;
sbit GLCD_RST_Direction at TRISB5_bit;
// End Glcd module connections
// Touch Panel module connections
sbit DriveA at RC0_bit;
sbit DriveB at RC1_bit;
sbit DriveA_Direction at TRISC0_bit;
sbit DriveB_Direction at TRISC1_bit;
// End Touch Panel module connections
bit write_erase;
char pen_size;
char write_msg[] = "WRITE"; // GLCD menu messages
char clear_msg[] = "CLEAR";
char erase_msg[] = "ERASE";
unsigned int x_coord, y_coord;
void Initialize() {
/*ANSEL = 3; // Configure AN0 and AN1 pins as analog inputs
ANSELH = 0; // and other AN pins as digital I/O
TRISA = 3;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0; */
ADCON1 = 4; //This is the closest configuration to ANSEL =3
//but here AN3 also will be analog
CCP1CON = 0;
CCP2CON = 0;
TRISA = 0b00000011;
Glcd_Init(); // Initialize GLCD
Glcd_Fill(0); // Clear GLCD
ADC_Init(); // Initialize ADC
TP_Init(128, 64, 0, 1); // Initialize touch panel
TP_Set_ADC_Threshold(900); // Set touch panel ADC threshold
}
void main() {
Initialize();
// You can get calibration constants using touch panel calibration example
TP_Set_Calibration_Consts(76, 917, 108, 906); // Set calibration constants
Glcd_Write_Text("WRITE ON SCREEN", 20, 5, 1) ;
Delay_ms(1000);
Glcd_Fill(0); // Clear GLCD
Glcd_V_Line(0,7,0,1);
Glcd_Write_Text(clear_msg,1,0,0);
Glcd_V_Line(0,7,97,1);
Glcd_Write_Text(erase_msg,98,0,0);
// Pen Menu:
Glcd_Rectangle(41,0,52,9,1);
Glcd_Box(45,3,48,6,1);
Glcd_Rectangle(63,0,70,7,1);
Glcd_Box(66,3,67,4,1);
Glcd_Rectangle(80,0,86,6,1);
Glcd_Dot(83,3,1);
write_erase = 1;
pen_size = 1;
while (1) {
if (TP_Press_Detect()) {
// After a PRESS is detected read X-Y and convert it to 128x64 space
if (TP_Get_Coordinates(&x_coord, &y_coord) == 0) {
if ((x_coord < 31) && (y_coord < 8)) {
Glcd_Fill(0);
// Pen Menu:
Glcd_Rectangle(41,0,52,9,1);
Glcd_Box(45,3,48,6,1);
Glcd_Rectangle(63,0,70,7,1);
Glcd_Box(66,3,67,4,1);
Glcd_Rectangle(80,0,86,6,1);
Glcd_Dot(83,3,1);
Glcd_V_Line(0,7,0,1);
Glcd_Write_Text(clear_msg,1,0,0);
Glcd_V_Line(0,7,97,1);
if (write_erase)
Glcd_Write_Text(erase_msg,98,0,0);
else
Glcd_Write_Text(write_msg,98,0,0);
}
// If write/erase is pressed
if ((x_coord > 96) && (y_coord < 8)) {
if (write_erase) {
write_erase = 0;
Glcd_Write_Text(write_msg,98,0,0);
Delay_ms(500);
}
else {
write_erase = 1;
Glcd_Write_Text(erase_msg,98,0,0);
Delay_ms(500);
}
}
// If pen size is selected
if ((x_coord >= 41) && (x_coord <= 52) && (y_coord <= 9))
pen_size = 3;
if ((x_coord >= 63) && (x_coord <= 70) && (y_coord <= 7))
pen_size = 2;
if ((x_coord >= 80) && (x_coord <= 86) && (y_coord <= 6))
pen_size = 1;
if (y_coord < 11)
continue;
switch (pen_size) {
case 1 : {
if ( (x_coord >= 0) && (y_coord >= 0) && (x_coord <= 127) && (y_coord <= 63) )
Glcd_Dot(x_coord, y_coord, write_erase);
break;
}
case 2 : {
if ( (x_coord >= 0) && (y_coord >= 0) && (x_coord <= 127-1) && (y_coord <= 63-1) )
Glcd_Box(x_coord, y_coord, x_coord + 1, y_coord + 1, write_erase);
break;
}
case 3 : {
if ( (x_coord >= 1) && (y_coord >= 1) && (x_coord <= 127-2) && (y_coord <= 63-2) )
Glcd_Box(x_coord-1, y_coord-1, x_coord + 2, y_coord + 2, write_erase);
break;
}
}
}
}
}
}
Can anyone here help me in this problem ?
Thanks