|
|
View previous topic :: View next topic |
Author |
Message |
albe01
Joined: 02 Jul 2010 Posts: 30 Location: italy
|
Problem with Glcd library modified |
Posted: Sun May 15, 2011 12:10 pm |
|
|
Hello to everyone... i have a problem with this library 192x64:
normally works, but if i define FAST_GLCD theres same errors and not compile it.
---------------------- this is the problem--------
Code: |
void glcd_fillScreen(int1 color)
#ifdef FAST_GLCD
{
unsigned int8 data;
unsigned int8 *p1, *p2, *p3;
unsigned int16 i;
p1 = displayData.left;
p2 = displayData.right;
p3 = displayData.mid;
data = 0xFF * color;
for(i=0; i<512; ++i)
{
*p1++ = data;
*p2++ = data;
*p3++ = data;
}
}
#else
|
Errors of the compiler:
p1 improper use of a function identifier
p2.p3 undefined identifier
ecc ecc...
Everything is apparently normal, but if FAST_GLCD is defined not compile...
I use a pic18f4525, and include graphics.c to use this glcd
regards
Code: |
#ifndef GLCD_CSA
#define GLCD_CSA PIN_D4
#endif
#ifndef GLCD_CSB
#define GLCD_CSB PIN_D3
#endif
#ifndef GLCD_DI
#define GLCD_DI PIN_D5 // Data or Instruction input
#endif
#ifndef GLCD_RW
#define GLCD_RW PIN_D6 // Read/Write
#endif
#ifndef GLCD_E
#define GLCD_E PIN_D7 // Enable
#endif
#ifndef GLCD_RST
#define GLCD_RST PIN_D2 // Reset
#endif
#define GLCD_LEFT 0
#define GLCD_MID 1
#define GLCD_RIGHT 2
#ifndef ON
#define ON 1
#endif
#ifndef OFF
#define OFF 0
#endif
/////////////////////////////////////////////////////////////////////////
// Function Prototypes
/////////////////////////////////////////////////////////////////////////
void glcd_init(int1 mode);
void glcd_pixel(unsigned int8 x, unsigned int8 y, int1 color);
void glcd_fillScreen(int1 color);
void glcd_writeByte(int side, BYTE data);
BYTE glcd_readByte(int side);
void glcd_update();
/////////////////////////////////////////////////////////////////////////
#ifdef FAST_GLCD
struct
{
unsigned int8 left[512];
unsigned int8 right[512];
unsigned int8 mid[512];
} displayData;
#endif
//=============================================================================
// Purpose: Initialize the LCD.
// Call before using any other LCD function.
// Inputs: OFF - Turns the LCD off
// ON - Turns the LCD on
void glcd_init(int1 mode)
{
// Initialze some pins
output_high(GLCD_RST);
output_low(GLCD_E);
//output_low(GLCD_CS1);
//output_low(GLCD_CS2);
//output_low(GLCD_CS3);
output_high(GLCD_CSA);
output_high(GLCD_CSB);
output_low(GLCD_DI); // Set for instruction
glcd_writeByte(GLCD_LEFT, 0xC0); // Specify first RAM line at the top
glcd_writeByte(GLCD_RIGHT, 0xC0); // of the screen
glcd_writeByte(GLCD_MID, 0xC0);
glcd_writeByte(GLCD_LEFT, 0x40); // Set the column address to 0
glcd_writeByte(GLCD_RIGHT, 0x40);
glcd_writeByte(GLCD_MID, 0x40);
glcd_writeByte(GLCD_LEFT, 0xB8); // Set the page address to 0
glcd_writeByte(GLCD_RIGHT, 0xB8);
glcd_writeByte(GLCD_MID, 0xB8);
if(mode == ON)
{
glcd_writeByte(GLCD_LEFT, 0x3F); // Turn the display on
glcd_writeByte(GLCD_MID, 0x3F);
glcd_writeByte(GLCD_RIGHT, 0x3F);
}
else
{
glcd_writeByte(GLCD_LEFT, 0x3E); // Turn the display off
glcd_writeByte(GLCD_MID, 0x3E);
glcd_writeByte(GLCD_RIGHT, 0x3E);
}
glcd_fillScreen(OFF); // Clear the display
#ifdef FAST_GLCD
glcd_update();
#endif
}
//==================================================================================
// Purpose: Update the LCD with data from the display arrays
#ifdef FAST_GLCD
void glcd_update()
{
unsigned int8 i, j;
unsigned int8 *p1, *p2, *p3;
p1 = displayData.left;
p2 = displayData.right;
p3 = displayData.mid;
// Loop through the vertical pages
for(i = 0; i < 8; ++i)
{
output_low(GLCD_DI); // Set for instruction
glcd_writeByte(GLCD_LEFT, 0x40); // Set horizontal address to 0
glcd_writeByte(GLCD_RIGHT, 0x40);
glcd_writeByte(GLCD_MID, 0x40);
glcd_writeByte(GLCD_LEFT, i | 0xB8); // Set page address
glcd_writeByte(GLCD_RIGHT, i | 0xB8);
glcd_writeByte(GLCD_MID, i | 0xB8);
output_high(GLCD_DI); // Set for data
// Loop through the horizontal sections
for(j = 0; j < 64; ++j)
{
glcd_writeByte(GLCD_LEFT, *p1++); // Turn pixels on or off
glcd_writeByte(GLCD_RIGHT, *p2++); // Turn pixels on or off
glcd_writeByte(GLCD_MID, *p3++); // Turn pixels on or off
}
}
}
#endif
//===================================================================================
// Purpose: Turn a pixel on a graphic LCD on or off
// Inputs: 1) x - the x coordinate of the pixel
// 2) y - the y coordinate of the pixel
// 3) color - ON or OFF
void glcd_pixel(unsigned int8 x, unsigned int8 y, int1 color)
#ifdef FAST_GLCD
{
unsigned int8* p;
unsigned int16 temp;
temp = y/8;
temp *= 64;
temp += x;
if((x > 63)&&(x<128))
{
p = displayData.mid + temp - 64;
}
else if(x>127)
{
p = displayData.right + temp-128;
}
else
{
p = displayData.left+temp;
if(color)
{
bit_set(*p, y%8);
}
else
{
bit_clear(*p, y%8);
}
}
#else
{
BYTE data;
int side = GLCD_LEFT; // Stores which chip to use on the LCD
if((x > 63)&&(x < 128)) // Check for first or second display area if((x > 63)&&(x < 128))
{
x -= 64;
side = GLCD_MID;
}
else if (x >127)
{
x -=128;
side=GLCD_RIGHT;
}
else
{
side=GLCD_LEFT;
}
output_low(GLCD_DI); // Set for instruction
bit_clear(x,7); // Clear the MSB. Part of an instruction code
bit_set(x,6); // Set bit 6. Also part of an instruction code
glcd_writeByte(side, x); // Set the horizontal address
glcd_writeByte(side, (y/8 & 0xBF) | 0xB8); // Set the vertical page address
output_high(GLCD_DI); // Set for data
glcd_readByte(side); // Need two reads to get data
data = glcd_readByte(side); // at new address
if(color == ON)
bit_set(data, y%8); // Turn the pixel on
else // or
bit_clear(data, y%8); // turn the pixel off
output_low(GLCD_DI); // Set for instruction
glcd_writeByte(side, x); // Set the horizontal address
output_high(GLCD_DI); // Set for data
glcd_writeByte(side, data); // Write the pixel data
}
#endif
//=============================================================================================
// Purpose: Fill the LCD screen with the passed in color
// Inputs: ON - turn all the pixels on
// OFF - turn all the pixels off
void glcd_fillScreen(int1 color)
#ifdef FAST_GLCD
{
unsigned int8 data;
unsigned int8 *p1, *p2, *p3;
unsigned int16 i;
p1 = displayData.left;
p2 = displayData.right;
p3 = displayData.mid;
data = 0xFF * color;
for(i=0; i<512; ++i)
{
*p1++ = data;
*p2++ = data;
*p3++ = data;
}
}
#else
{
unsigned int8 i, j;
// Loop through the vertical pages
for(i = 0; i < 8; ++i)
{
output_low(GLCD_DI); // Set for instruction
glcd_writeByte(GLCD_LEFT, 0b01000000); // Set horizontal address to 0
glcd_writeByte(GLCD_RIGHT, 0b01000000);
glcd_writeByte(GLCD_MID, 0b01000000);
glcd_writeByte(GLCD_LEFT, i | 0b10111000);// Set page address
glcd_writeByte(GLCD_RIGHT, i | 0b10111000);
glcd_writeByte(GLCD_MID, i | 0b10111000);
output_high(GLCD_DI); // Set for data
// Loop through the horizontal sections
for(j = 0; j < 64; ++j)
{
glcd_writeByte(GLCD_LEFT, 0xFF*color); // Turn pixels on or off
glcd_writeByte(GLCD_RIGHT, 0xFF*color); // Turn pixels on or off
glcd_writeByte(GLCD_MID, 0xFF*color); // Turn pixels on or off
}
}
}
#endif
//==================================================================================
// Purpose: Write a byte of data to the specified chip
// Inputs: 1) chipSelect - which chip to write the data to
// 2) data - the byte of data to write
void glcd_writeByte(int8 side, BYTE data)
{
set_tris_b(0x00); //set_tris_d(0x00);
output_low(GLCD_RW); // Set for writing
switch(side)
{
case GLCD_LEFT:
output_low(GLCD_CSA); //
output_low(GLCD_CSB);
break;
case GLCD_MID:
output_high(GLCD_CSA);
output_low(GLCD_CSB);
break;
case GLCD_RIGHT:
output_low(GLCD_CSA);
output_high(GLCD_CSB);
break;
//default: // Deselected
//output_high(GLCD_CSA);
//output_high(GLCD_CSB);
}
delay_us(1);
output_b(data); // Put the data on the port
delay_us(1);
output_high(GLCD_E); // Pulse the enable pin
delay_us(1);
output_low(GLCD_E);
output_high(GLCD_CSA); // Reset the chip select lines
output_high(GLCD_CSB);
}
//===============================================================================
// Purpose: Reads a byte of data from the specified chip
// Ouputs: A byte of data read from the chip
BYTE glcd_readByte(int8 side)
{
BYTE data; // Stores the data read from the LCD
set_tris_b(0xFF); // Set port d to input
output_high(GLCD_RW); // Set for reading
switch(side)
{
case GLCD_LEFT:
output_low(GLCD_CSA);
output_low(GLCD_CSB);
break;
case GLCD_MID:
output_high(GLCD_CSA);
output_low(GLCD_CSB);
break;
case GLCD_RIGHT:
output_low(GLCD_CSA);
output_high(GLCD_CSB);
break;
//default: // Deselected
//output_high(GLCD_CSA);
//output_high(GLCD_CSB);
}
delay_us(1);
output_high(GLCD_E); // Pulse the enable pin
delay_us(1);
data = input_b(); // Get the data from the display's output register
output_low(GLCD_E);
output_high(GLCD_CSA); // Reset the chip select lines
output_high(GLCD_CSB);
return data; // Return the read data
}
#endif
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 15, 2011 12:29 pm |
|
|
Post your compiler version. |
|
|
albe01
Joined: 02 Jul 2010 Posts: 30 Location: italy
|
|
Posted: Sun May 15, 2011 12:59 pm |
|
|
PCM programmer wrote: | Post your compiler version. |
4.114 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 15, 2011 1:30 pm |
|
|
There is no main() in your post.
Post something that I can compile and test.
It's got to have an #include for the PIC, #fuses, #use delay, #include
files, main(), etc. |
|
|
albe01
Joined: 02 Jul 2010 Posts: 30 Location: italy
|
|
Posted: Sun May 15, 2011 1:57 pm |
|
|
main code:
Code: |
#include <18F4525.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#define FAST_GLCD // Try commenting this out to see the differences
#include <KS0108_192X64.c>
#include <graphics.c>
#include <math.h>
void displayVoltage(int adc) {
char voltage[9];
sprintf(voltage, "%f", (float)adc * .01960784); // Converts adc to text
voltage[4] = '\0'; // Visualizza 2,3 o un decimale
glcd_rect(35, 18, 60, 25, YES, OFF); // Clear the old voltage
glcd_text57(35, 18, voltage, 1, ON); // ( 1 è la dimensione )scrive la tensione
}
void main() {
int1 warn = FALSE;
int8 adc = 0, adc_old = 0;
char voltText[] = " Volts", warning[] = "Batteria scarica!";// scritte glcd
//float theta = 0;
setup_adc_ports(AN0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
glcd_init(ON); // Must initialize the LCD
glcd_rect(1, 5, 126, 15, NO, ON); // Outline the bar
glcd_text57(60, 18, voltText, 1, ON); // Display "Volts"
//glcd_circle(30, 47, 10, NO, ON); // Disegna il cerchio
for(;;) {
adc = read_adc(); // Read a value from the ADC
displayVoltage(adc); // Display the reading
adc = (adc > 249) ? 249 : adc; // Keep the value 249 or less
if(adc != adc_old) {
glcd_rect(adc/2+1, 6, adc_old/2+1, 14, YES, OFF); // Pulisce la vecchia barra
glcd_rect(1, 6, adc/2+1, 14, YES, ON); // Disegna barra aggiornata
adc_old = adc; // Set old value to new
if(adc < 150 && !warn) { // Controlla se superiore a X volts
//glcd_rect(45, 38, 124, 55, YES, ON); // con il primo valore allunga verso < Draw a filled black rectangle
glcd_text57(15, 40, warning, 1, ON); // posizione "Batt.scarica" su LCD "1" prima di ON è la dimensione
glcd_rect(2, 58, 10, 62, NO, ON); // crea simbolo batteria vuoto
glcd_rect(11, 59, 11, 61, NO, ON); // disegna testa batteria
warn = TRUE; }
else if(adc >=160 && warn) {
glcd_rect(12, 37, 125, 55, YES, OFF); // Pulisce area schermo "low batt"
glcd_rect(2, 58, 11, 62, YES, OFF);
warn = FALSE; }
}
// Le seguenti 3 linee fanno girare la lancetta nel cerchio
//glcd_line(30, 47, 30+(int)(8*sin(theta)+.5), 47-(int)(8*cos(theta)+.5), OFF);
//theta = (theta > 5.9) ? 0 : (theta += .3);
//glcd_line(30, 47, 30+(int)(8*sin(theta)+.5), 47-(int)(8*cos(theta)+.5), ON);
#ifdef FAST_GLCD
glcd_update();
#else
delay_ms(100); // Reduces flicker by allowing pixels to be on
// much longer than off
#endif
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 15, 2011 2:15 pm |
|
|
Problem: Missing closing brace in the previous function:
Quote: | void glcd_pixel(unsigned int8 x, unsigned int8 y, int1 color)
#ifdef FAST_GLCD
{
unsigned int8* p;
unsigned int16 temp;
temp = y/8;
temp *= 64;
temp += x;
if((x > 63)&&(x<128))
{
p = displayData.mid + temp - 64;
}
else if(x>127)
{
p = displayData.right + temp-128;
}
else
{
p = displayData.left+temp;
if(color)
{
bit_set(*p, y%8);
}
else
{
bit_clear(*p, y%8);
}
} |
|
|
|
albe01
Joined: 02 Jul 2010 Posts: 30 Location: italy
|
|
Posted: Sun May 15, 2011 2:28 pm |
|
|
Thanks, I had not found the error
regards |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|