Autor Tema: Error de visualización GLCD, con protocolo I2C [SOLUCIONADO]  (Leído 6475 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado thegame

  • PIC18
  • ****
  • Mensajes: 441
    • Mcu Tronics
Error de visualización GLCD, con protocolo I2C [SOLUCIONADO]
« en: 23 de Julio de 2020, 15:13:08 »
Buenas a todos compañeros, quiero saber si me pueden ayudar con lo siguiente:

Tengo una pantalla GLCD, 128X64, la cual la he probado y funciona correctamente, dicha pantalla la he conectado a un PIC18F26K22, para que la controle, lo cual hace, mostrandome texto e imagenes, este pic esta armado en una pcb, que a su ves, por medio del protocolo I2C, se comunica con otra pcb que realiza el papel de maestro, con un PIC18F46K22 (prácticamente son el mismo solo variando la memoria de programa).

Ahora, la comunicación maestro ----> esclavo (por I2C), es correcta, ya que la he comprobado enviandole un caracter (una letra) ó numero, y validándolo por medio de una condicional (algo como: if(dato=='a')), de modo que la comunicación es correcta, el dato enviado por parte del maestro y el recibido por parte del esclavo es correcto, por lo que compruebo que se entienden.

Ahora, lo que yo quiero y he intentado hacer y no logro es, que el dato que recibe el esclavo, sea un numero o caracter, lo dibuje en la GLCD

He intentado algo como:

Código: [Seleccionar]
sprintf(cadena_datos,"%u",dato_recibido);
glcd_text57(0,0,cadena_datos,1,1);
glcd_update();

Con lo que obtengo caracteres ilegibles, en la posicion que le indico, pero no dibuja el dato que llega por I2C al esclavo.

Es decir, si el maestro envia un 25, el esclavo lo recibe pero no dibuja en la GLCD el 25, dibuja cualquier cosa.

Ahora si yo hago:

Código: [Seleccionar]
cadena_datos[4]="hola";

glcd_text57(0,0,cadena_datos,1,1);
glcd_update();

Sin problema me escribe lo que la cadena tiene.

Es mas un problema de formato, pero he intentado de muchas formas, cambiando los identificadores %u,%c,%s,%d, etc etc etc sin exito
He intentado con funciones para convertir el numero en cadena y que al pasarlo a la funcion que escribe en el glcd sea ya una cadena, y nada

Alguien ha trabajado con ello, o sabe como deberia pasarle el dato a la funcion glcd_text57()?????????

Muchas gracias de antemano

Saludos
« Última modificación: 25 de Julio de 2020, 03:18:04 por thegame »
Nunca se deja de aprender

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #1 en: 23 de Julio de 2020, 16:27:09 »
Código: C
  1. cadena_datos[4]={0,0,0,0};
  2.  
  3. dato_recibido=25;
  4. sprintf(cadena_datos,"%u",dato_recibido);
  5. glcd_text57(0,0,cadena_datos,1,1);
  6. glcd_update();


y


Código: C
  1. cadena_datos[4]="25";
  2.  
  3. glcd_text57(0,0,cadena_datos,1,1);
  4. glcd_update();

funcionan igual ? Sino es algun problema de libreria. Lo que hay que identificar es: Cual libreria
« Última modificación: 23 de Julio de 2020, 16:29:24 por KILLERJC »

Desconectado thegame

  • PIC18
  • ****
  • Mensajes: 441
    • Mcu Tronics
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #2 en: 23 de Julio de 2020, 18:03:46 »
Que tal KillerJc

ambas opciones que planteas, funcionan.

es cuando recibo desde el i2c, el dato proveniente del maestro, cuando falla.

En la interrupcion del esclavo tengo esto:
Código: [Seleccionar]
#INT_SSP
void recepcion_i2c(void)
{
   dato=i2c_read(GLCD);
   i2c_datos=1;
}

Y en el main ( ) del esclavo, proceso asi:

Código: [Seleccionar]
void main()
{
   //Configuracion y Plantilla base del GLCD
   configuracion();
   plantilla_base();
   
   //Ciclo infinito
   while(true)
   { 
      if(i2c_datos==1)
      {
         i2c_datos=0;
         sprintf(cadena_datos,"%u",dato);
         glcd_text57(73,18,cadena_datos,2,1);
         glcd_update();
         
      }
     
   }
}

y pues, no funciona, no se que estare haciendo mal

Saludos y gracias
Nunca se deja de aprender

Desconectado remi04

  • PIC24F
  • *****
  • Mensajes: 657
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #3 en: 23 de Julio de 2020, 18:36:04 »
Prueba al ponerle el monario * a :

  glcd_text57(73,18,*cadena_datos,2,1);

   A falta de ver más código, si estas usando bootloader.  Si usas protección de lectura/escritura de las secciones de memoria de bootloader pued darte problemas los punteros por ahí. Se han dado casos.
« Última modificación: 23 de Julio de 2020, 18:47:46 por remi04 »

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #4 en: 23 de Julio de 2020, 19:00:03 »
No creo que sea el problema.

Es raro lo que planteas... Por lo siguiente...., Esto:

Código: C
  1. dato_recibido=25;
  2. sprintf(cadena_datos,"%u",dato_recibido);
  3. glcd_text57(0,0,cadena_datos,1,1);
  4. glcd_update();

Todo esto suponiendo que sea un byte.
Es exactamente lo mismo que si dato es 25. Siendo que puede ser un numero de 0 a 255, entonces lo mas seguro es que cadena_datos tenga minimo 4 lugares. A no ser que lo uses para otra cosa. Lo unico que se podria plantear es que la recepcion es mala, aun asi el valor de dato estaria entre los valores y no existirian los problemas que comentas.

Respecto a lo planteado por Remi

Si es un array  escribir *cadena_datos[0] o cadena_datos no hay diferencia, *cadena_datos es el puntero del puntero. Ahora lo que no comprendo es como se protegeria la RAM, como el lo plantea, ya que el array esta en RAM.

Desconectado thegame

  • PIC18
  • ****
  • Mensajes: 441
    • Mcu Tronics
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #5 en: 23 de Julio de 2020, 19:22:52 »
Remi, ya lo habia probado antes como lo planteas, y no funciona, el dato sigue dibujandose ilegiblemente.

Killer, la recepcion del i2c, por parte del esclavo, y la correspondiente transmision del maestro, la he corroborado, y funciona correctamente, el colocar algo como esto:

Código: [Seleccionar]
if(dato_recibido==25)
{
     output_high(PIN_B1);
}

sin problema se activa el pin, y si le envió desde el maestro, un numero diferente a 25, no se activa, lo que me hace pensar que se entienden entre ellos y que los datos se transmiten y reciben bien.

incluso, use el código de ejemplo que trae CCS, en el maestro:

Código: [Seleccionar]
unsigned int8wData[16];
int1 ack;

ack = i2c_transfer_out(0x10,1, 1);

if(ack==0)
     printf("\r\nData transferred successfully");
else
     printf("\r\nData transferred unsuccessfully");

Haciendo las adecuaciones adecuadas claro esta, y siempre obtengo la respuesta de transferencia satisfactoria.

Esa, cadena_datos, solo se usa para recibir lo que el maestro envia, y dibujarlo, para nada mas.

De verdad que no entiendo porque no dibuja el dato recibido como debe de ser.

Les comparto la librería que estoy usando, y el código del esclavo que al final es el del problema.

Saludos y gracias

Librería ST7920:

Código: [Seleccionar]
/************************************************************************
*   LCD graphics driver for Digole 12864w with ST7920 driver using       *
*   CCS software. May work with other ST7920 driven LCD. It has          *
*   the following Pin assignments                                        *
*                                                                        *
*   Pin 1 ------------> Gnd                                              *   
*   Pin 2 ------------> +5volts                                          *
*   Pin 3 ------------> Contrast                                         *
*   Pin 4 ------------> Register Select                                  *
*   Pin 5 ------------> Read/Write                                       *
*   Pin 6 ------------> Enable                                           *
*   Pin 7-14 ---------> Data bits                                        *
*   Pin 15 -----------> PSB (parallel=high & serial=low)                 *
*   Pin 16 -----------> NoConnection                                     *
*   Pin 17 -----------> Reset                                            *
*   Pin 18 -----------> Vout                                             *
*   Pin 19 -----------> +5volts                                          *
*   Pin 20 -----------> Gnd                                              *
*                                                                        *
*   This driver is using 8bit parallel operation for optimal RAM         *
*   requirements, if you want i can change it to 4 bit operation.        *
*                                                                        *
*   Developed by Christian Rebogio                                       *
*   suggestions and request please email me at                           *
*   christian.rebogio@gmail.com                                          *
*                                                                        *
* READ THE DATASHEET FOR ST7920!!!!!!!                                   *
************************************************************************/
// change the pin assignment depending on your circuit

#define  rs  PIN_C1                    //COMMNAD/DATA SELECT
#define  rw  PIN_C0                    //READ/WRITE SELECT             
#define  e   PIN_C2                    //ENABLE SIGNAL                 
#define  rst PIN_C5                    //RESET SIGNAL   

#define ON  1
#define OFF 0
#define YES 1
#define NO  0
#define XVAL 16  // 16 X 16 or 256 for there is 8 word values for the upper and lower
#define YVAL 32

// PSB is tied to Vcc for this driver because this driver uses Parallel
// operation.
// data is sent using port B so change output_b() to other ports you
//want to use. Dont for get to change the Busy pin @ lcd_check_busy

#define GLCD_WIDTH   128

/////////////////////////////////////////////////////////////////////////
//// Defines a 5x7 font
/////////////////////////////////////////////////////////////////////////
const unsigned int8 FONT[51][5] ={0x00, 0x00, 0x00, 0x00, 0x00, // SPACE
                         0x00, 0x00, 0x5F, 0x00, 0x00, // !
                         0x00, 0x03, 0x00, 0x03, 0x00, // "
                         0x14, 0x3E, 0x14, 0x3E, 0x14, // #
                         0x24, 0x2A, 0x7F, 0x2A, 0x12, // $
                         0x43, 0x33, 0x08, 0x66, 0x61, // %
                         0x36, 0x49, 0x55, 0x22, 0x50, // &
                         0x00, 0x05, 0x03, 0x00, 0x00, // '
                         0x00, 0x1C, 0x22, 0x41, 0x00, // (
                         0x00, 0x41, 0x22, 0x1C, 0x00, // )
                         0x14, 0x08, 0x3E, 0x08, 0x14, // *
                         0x08, 0x08, 0x3E, 0x08, 0x08, // +
                         0x00, 0x50, 0x30, 0x00, 0x00, // ,
                         0x08, 0x08, 0x08, 0x08, 0x08, // -
                         0x00, 0x60, 0x60, 0x00, 0x00, // .
                         0x20, 0x10, 0x08, 0x04, 0x02, // /
                         0x3E, 0x51, 0x49, 0x45, 0x3E, // 0
                         0x00, 0x04, 0x02, 0x7F, 0x00, // 1
                         0x42, 0x61, 0x51, 0x49, 0x46, // 2
                         0x22, 0x41, 0x49, 0x49, 0x36, // 3
                         0x18, 0x14, 0x12, 0x7F, 0x10, // 4
                         0x27, 0x45, 0x45, 0x45, 0x39, // 5
                         0x3E, 0x49, 0x49, 0x49, 0x32, // 6
                         0x01, 0x01, 0x71, 0x09, 0x07, // 7
                         0x36, 0x49, 0x49, 0x49, 0x36, // 8
                         0x26, 0x49, 0x49, 0x49, 0x3E, // 9
                         0x00, 0x36, 0x36, 0x00, 0x00, // :
                         0x00, 0x56, 0x36, 0x00, 0x00, // ;
                         0x08, 0x14, 0x22, 0x41, 0x00, // <
                         0x14, 0x14, 0x14, 0x14, 0x14, // =
                         0x00, 0x41, 0x22, 0x14, 0x08, // >
                         0x02, 0x01, 0x51, 0x09, 0x06, // ?
                         0x3E, 0x41, 0x59, 0x55, 0x5E, // @
                         0x7E, 0x09, 0x09, 0x09, 0x7E, // A
                         0x7F, 0x49, 0x49, 0x49, 0x36, // B
                         0x3E, 0x41, 0x41, 0x41, 0x22, // C
                         0x7F, 0x41, 0x41, 0x41, 0x3E, // D
                         0x7F, 0x49, 0x49, 0x49, 0x41, // E
                         0x7F, 0x09, 0x09, 0x09, 0x01, // F
                         0x3E, 0x41, 0x41, 0x49, 0x3A, // G
                         0x7F, 0x08, 0x08, 0x08, 0x7F, // H
                         0x00, 0x41, 0x7F, 0x41, 0x00, // I
                         0x30, 0x40, 0x40, 0x40, 0x3F, // J
                         0x7F, 0x08, 0x14, 0x22, 0x41, // K
                         0x7F, 0x40, 0x40, 0x40, 0x40, // L
                         0x7F, 0x02, 0x0C, 0x02, 0x7F, // M
                         0x7F, 0x02, 0x04, 0x08, 0x7F, // N
                         0x3E, 0x41, 0x41, 0x41, 0x3E, // O
                         0x7F, 0x09, 0x09, 0x09, 0x06, // P
                         0x1E, 0x21, 0x21, 0x21, 0x5E, // Q
                         0x7F, 0x09, 0x09, 0x09, 0x76};// R

const unsigned int8 FONT2[44][5]={0x26, 0x49, 0x49, 0x49, 0x32, // S
                         0x01, 0x01, 0x7F, 0x01, 0x01, // T
                         0x3F, 0x40, 0x40, 0x40, 0x3F, // U
                         0x1F, 0x20, 0x40, 0x20, 0x1F, // V
                         0x7F, 0x20, 0x10, 0x20, 0x7F, // W
                         0x41, 0x22, 0x1C, 0x22, 0x41, // X
                         0x07, 0x08, 0x70, 0x08, 0x07, // Y
                         0x61, 0x51, 0x49, 0x45, 0x43, // Z
                         0x00, 0x7F, 0x41, 0x00, 0x00, // [
                         0x02, 0x04, 0x08, 0x10, 0x20, // \
                         0x00, 0x00, 0x41, 0x7F, 0x00, // ]
                         0x04, 0x02, 0x01, 0x02, 0x04, // ^
                         0x40, 0x40, 0x40, 0x40, 0x40, // _
                         0x00, 0x01, 0x02, 0x04, 0x00, // `
                         0x20, 0x54, 0x54, 0x54, 0x78, // a
                         0x7F, 0x44, 0x44, 0x44, 0x38, // b
                         0x38, 0x44, 0x44, 0x44, 0x44, // c
                         0x38, 0x44, 0x44, 0x44, 0x7F, // d
                         0x38, 0x54, 0x54, 0x54, 0x18, // e
                         0x04, 0x04, 0x7E, 0x05, 0x05, // f
                         0x08, 0x54, 0x54, 0x54, 0x3C, // g
                         0x7F, 0x08, 0x04, 0x04, 0x78, // h
                         0x00, 0x44, 0x7D, 0x40, 0x00, // i
                         0x20, 0x40, 0x44, 0x3D, 0x00, // j
                         0x7F, 0x10, 0x28, 0x44, 0x00, // k
                         0x00, 0x41, 0x7F, 0x40, 0x00, // l
                         0x7C, 0x04, 0x78, 0x04, 0x78, // m
                         0x7C, 0x08, 0x04, 0x04, 0x78, // n
                         0x38, 0x44, 0x44, 0x44, 0x38, // o
                         0x7C, 0x14, 0x14, 0x14, 0x08, // p
                         0x08, 0x14, 0x14, 0x14, 0x7C, // q
                         0x00, 0x7C, 0x08, 0x04, 0x04, // r
                         0x48, 0x54, 0x54, 0x54, 0x20, // s
                         0x04, 0x04, 0x3F, 0x44, 0x44, // t
                         0x3C, 0x40, 0x40, 0x20, 0x7C, // u
                         0x1C, 0x20, 0x40, 0x20, 0x1C, // v
                         0x3C, 0x40, 0x30, 0x40, 0x3C, // w
                         0x44, 0x28, 0x10, 0x28, 0x44, // x
                         0x0C, 0x50, 0x50, 0x50, 0x3C, // y
                         0x44, 0x64, 0x54, 0x4C, 0x44, // z
                         0x00, 0x08, 0x36, 0x41, 0x41, // {
                         0x00, 0x00, 0x7F, 0x00, 0x00, // |
                         0x41, 0x41, 0x36, 0x08, 0x00, // }
                         0x02, 0x01, 0x02, 0x04, 0x02};// ~
/////////////////////////////////////////////////////////////////////////

const BYTE TEXT[51][5] ={0x00, 0x00, 0x00, 0x00, 0x00, // SPACE
                         0x00, 0x00, 0x5F, 0x00, 0x00, // !
                         0x00, 0x03, 0x00, 0x03, 0x00, // "
                         0x14, 0x3E, 0x14, 0x3E, 0x14, // #
                         0x24, 0x2A, 0x7F, 0x2A, 0x12, // $
                         0x43, 0x33, 0x08, 0x66, 0x61, // %
                         0x36, 0x49, 0x55, 0x22, 0x50, // &
                         0x00, 0x05, 0x03, 0x00, 0x00, // '
                         0x00, 0x1C, 0x22, 0x41, 0x00, // (
                         0x00, 0x41, 0x22, 0x1C, 0x00, // )
                         0x14, 0x08, 0x3E, 0x08, 0x14, // *
                         0x08, 0x08, 0x3E, 0x08, 0x08, // +
                         0x00, 0x50, 0x30, 0x00, 0x00, // ,
                         0x08, 0x08, 0x08, 0x08, 0x08, // -
                         0x00, 0x60, 0x60, 0x00, 0x00, // .
                         0x20, 0x10, 0x08, 0x04, 0x02, // /
                         0x3E, 0x51, 0x49, 0x45, 0x3E, // 0
                         0x04, 0x02, 0x7F, 0x00, 0x00, // 1
                         0x42, 0x61, 0x51, 0x49, 0x46, // 2
                         0x22, 0x41, 0x49, 0x49, 0x36, // 3
                         0x18, 0x14, 0x12, 0x7F, 0x10, // 4
                         0x27, 0x45, 0x45, 0x45, 0x39, // 5
                         0x3E, 0x49, 0x49, 0x49, 0x32, // 6
                         0x01, 0x01, 0x71, 0x09, 0x07, // 7
                         0x36, 0x49, 0x49, 0x49, 0x36, // 8
                         0x26, 0x49, 0x49, 0x49, 0x3E, // 9
                         0x00, 0x36, 0x36, 0x00, 0x00, // :
                         0x00, 0x56, 0x36, 0x00, 0x00, // ;
                         0x08, 0x14, 0x22, 0x41, 0x00, // <
                         0x14, 0x14, 0x14, 0x14, 0x14, // =
                         0x00, 0x41, 0x22, 0x14, 0x08, // >
                         0x02, 0x01, 0x51, 0x09, 0x06, // ?
                         0x3E, 0x41, 0x59, 0x55, 0x5E, // @
                         0x7E, 0x09, 0x09, 0x09, 0x7E, // A
                         0x7F, 0x49, 0x49, 0x49, 0x36, // B
                         0x3E, 0x41, 0x41, 0x41, 0x22, // C
                         0x7F, 0x41, 0x41, 0x41, 0x3E, // D
                         0x7F, 0x49, 0x49, 0x49, 0x41, // E
                         0x7F, 0x09, 0x09, 0x09, 0x01, // F
                         0x3E, 0x41, 0x41, 0x49, 0x3A, // G
                         0x7F, 0x08, 0x08, 0x08, 0x7F, // H
                         0x00, 0x41, 0x7F, 0x41, 0x00, // I
                         0x30, 0x40, 0x40, 0x40, 0x3F, // J
                         0x7F, 0x08, 0x14, 0x22, 0x41, // K
                         0x7F, 0x40, 0x40, 0x40, 0x40, // L
                         0x7F, 0x02, 0x0C, 0x02, 0x7F, // M
                         0x7F, 0x02, 0x04, 0x08, 0x7F, // N
                         0x3E, 0x41, 0x41, 0x41, 0x3E, // O
                         0x7F, 0x09, 0x09, 0x09, 0x06, // P
                         0x1E, 0x21, 0x21, 0x21, 0x5E, // Q
                         0x7F, 0x09, 0x09, 0x09, 0x76};// R

const BYTE TEXT2[44][5]={0x26, 0x49, 0x49, 0x49, 0x32, // S
                         0x01, 0x01, 0x7F, 0x01, 0x01, // T
                         0x3F, 0x40, 0x40, 0x40, 0x3F, // U
                         0x1F, 0x20, 0x40, 0x20, 0x1F, // V
                         0x7F, 0x20, 0x10, 0x20, 0x7F, // W
                         0x41, 0x22, 0x1C, 0x22, 0x41, // X
                         0x07, 0x08, 0x70, 0x08, 0x07, // Y
                         0x61, 0x51, 0x49, 0x45, 0x43, // Z
                         0x00, 0x7F, 0x41, 0x00, 0x00, // [
                         0x02, 0x04, 0x08, 0x10, 0x20, // \
                         0x00, 0x00, 0x41, 0x7F, 0x00, // ]
                         0x04, 0x02, 0x01, 0x02, 0x04, // ^
                         0x40, 0x40, 0x40, 0x40, 0x40, // _
                         0x00, 0x01, 0x02, 0x04, 0x00, // `
                         0x20, 0x54, 0x54, 0x54, 0x78, // a
                         0x7F, 0x44, 0x44, 0x44, 0x38, // b
                         0x38, 0x44, 0x44, 0x44, 0x44, // c
                         0x38, 0x44, 0x44, 0x44, 0x7F, // d
                         0x38, 0x54, 0x54, 0x54, 0x18, // e
                         0x04, 0x04, 0x7E, 0x05, 0x05, // f
                         0x08, 0x54, 0x54, 0x54, 0x3C, // g
                         0x7F, 0x08, 0x04, 0x04, 0x78, // h
                         0x00, 0x44, 0x7D, 0x40, 0x00, // i
                         0x20, 0x40, 0x44, 0x3D, 0x00, // j
                         0x7F, 0x10, 0x28, 0x44, 0x00, // k
                         0x00, 0x41, 0x7F, 0x40, 0x00, // l
                         0x7C, 0x04, 0x78, 0x04, 0x78, // m
                         0x7C, 0x08, 0x04, 0x04, 0x78, // n
                         0x38, 0x44, 0x44, 0x44, 0x38, // o
                         0x7C, 0x14, 0x14, 0x14, 0x08, // p
                         0x08, 0x14, 0x14, 0x14, 0x7C, // q
                         0x00, 0x7C, 0x08, 0x04, 0x04, // r
                         0x48, 0x54, 0x54, 0x54, 0x20, // s
                         0x04, 0x04, 0x3F, 0x44, 0x44, // t
                         0x3C, 0x40, 0x40, 0x20, 0x7C, // u
                         0x1C, 0x20, 0x40, 0x20, 0x1C, // v
                         0x3C, 0x40, 0x30, 0x40, 0x3C, // w
                         0x44, 0x28, 0x10, 0x28, 0x44, // x
                         0x0C, 0x50, 0x50, 0x50, 0x3C, // y
                         0x44, 0x64, 0x54, 0x4C, 0x44, // z
                         0x00, 0x08, 0x36, 0x41, 0x41, // {
                         0x00, 0x00, 0x7F, 0x00, 0x00, // |
                         0x41, 0x41, 0x36, 0x08, 0x00, // }
                         0x02, 0x01, 0x02, 0x04, 0x02};// ~
                         
//////////////////////////////////////////////////////////////////////////////////
//The following are the functions included in this driver file
// glcd_readbyte();
// glcd_instruction( instruction );
// glcd_data( data ); - data can be an array of characters!
// glcd_check_busy();
// glcd_update(); -must be called always after writing a pixel or using functions
//                 from GRAPHICS.C .. Only applicaticable in Graphing mode
// glcd_fillscreen( ON or OFF);
// glcd_init_graph(); initialize for graphing mode
// glcd_init_basic(); initilize for accessing the stored Characters
//                     you can use glcd_data() for writing text
// glcd_pixel(x coordinate, y coordinate, ON or OFF);
//            -WORKS WITH GRAPHIC.C  from CCS Drivers
// glcd_plot_image(width,height,X coor, Y coor, inverse);
//            -plots the image[] array. Declare it first before this driver.
//             or modify this driver
//
//////////////////////////////////////////////////////////////////////////////////



typedef union
{
  int16 word;
  int8 nbyte[2];
} Dots;

typedef struct
{
  int1 refresh;
  Dots pix[YVAL][XVAL];   // Max dimensions for display (x,y) = (128,32)
  } GD_RAM;             //  (0,0) corresponds to upper lefthand corner.

GD_RAM gdram;


unsigned int8 glcd_readByte (unsigned int1 address)
{
  unsigned int8 data;   // Stores the data read from the LCD
  if(address==1){
     output_high(rs);
  }
  if(address==0){
     output_low(rs);
  }
  output_high(rw);//GLCD_RW = RW_READ;      // Set for reading
  output_high(e);//GLCD_E = 1;      // Pulse the enable pin
  delay_us(1);
  data=input_b();      // Get the data from the display's output register
  output_low(e);//GLCD_E = 0;
  return (data);
}

 
void glcd_check_busy(){
   int1 busy=1;
   output_low(rs);      // LOW RS and High RW will put the lcd to
   output_high(rw);      // read busy flag and address counter
   while(busy){         // will cycle until busy flag is 0
      output_high(e);
      if(!input(PIN_B7)){
         busy=0;
      }
      output_low(e);
   }
}
 
void glcd_instruction(unsigned char x){
   glcd_check_busy();      //must be satisfied before sending instruction
   output_low(rs);      // LOW RS and LOW RW will put the lcd to
   output_low(rw);      // Write instruction mode
   output_b(x);         // 8bit data to bus
   output_high(e);      // enable
   delay_us(1);       
   output_low(e);      // disable
}

void glcd_data(unsigned char x){
   glcd_check_busy();
   output_high(rs);      // HIGH RS and LOW RW will put the lcd to
   output_low(rw);      // Write data register mode
   output_b(x);
   output_high(e);
   delay_us(1);
   output_low(e);
}
 

void glcd_fillScreen (unsigned int1 color)
{
  int8 v, h;
  int16 d;

  d = (color == ON ? 0xFFFFL : 0x0000L);

  for (v=0; v < YVAL; v++)
  {
    for (h=0; h < XVAL; h++)
    {
      gdram.pix[v][h].word = d;
    }
  }
  gdram.refresh = TRUE;
}

void glcd_update ()
{
   int8 v, h;
   if (gdram.refresh)
   {
     for (v = 0; v <YVAL; v ++) // 64
     {
       if (v <32) // first part
       {
          glcd_instruction (0x80 | v); // Set Vertical Address.
          glcd_instruction (0x80); // Set Horizontal Address.
       }
       else // second lcd stop
       {
          glcd_instruction (0x80 | (v - 32)); // Set Vertical Address.
          glcd_instruction (0x88); // Set Horizontal Address.
       }
       for (h = 0; h <XVAL; h ++) // 8
       {
         glcd_data (gdram.pix [v] [h] .nbyte [1]); // Write High Byte.
         glcd_data (gdram.pix [v] [h] .nbyte [0]); // Write Low Byte.
       }
     }
     gdram.refresh = FALSE;
   }
}

void glcd_init_graph(){
   delay_ms(40);
   output_low(rst);         //reset LCD
   delay_us(1);                     
   output_high(rst);        //LCD normal operation
   glcd_instruction(0x30);   //set 8 bit operation and basic instruction set
   delay_us(144);
   glcd_instruction(0x0C);   //display on cursor off and char blink off
   delay_us(100);
   glcd_instruction(0x01);   //display clear
   delay_ms(10);
   glcd_instruction(0x06);   //entry mode set
   delay_us(72);                 
   glcd_instruction(0x34);    // Select extended instruction set.
   delay_ms (10);
   glcd_instruction(0x36);    // Graphic display ON.
   delay_ms (10);

   glcd_fillScreen (OFF);
   glcd_update ();

}

void glcd_init_basic(){
   delay_ms(40);
   output_low(rst);         //reset LCD
   delay_us(1);                     
   output_high(rst);        //LCD normal operation
   glcd_instruction(0x30);   //set 8 bit operation and basic instruction set
   delay_us(144);
   glcd_instruction(0x0C);   //display on cursor off and char blink off
   delay_us(100);
   glcd_instruction(0x01);   //display clear
   delay_ms(10);
   glcd_instruction(0x06);   //entry mode set
   delay_us(72);                 
}

void glcd_pixel(int8 x, int8 y, int1 color)
{
  int8 v, h, b;
  if(y>31){x += 128; y-= 32;};
  v = y;
  h = x/16;
  b = 15 - (x%16);
 
  if (color == ON) bit_set (gdram.pix[v][h].word, b);
  else bit_clear (gdram.pix[v][h].word, b);

  gdram.refresh = TRUE;
}

//credits to http://www.ccsinfo.com/forum/viewtopic.php?t=32819&highlight=st7920//
///////////////////////////////////////////////////////////////////////////////////

//****************************************************************************//
// Purpose:       Write text on a graphic LCD                                 //
// Inputs:        (x,y) - The upper left coordinate of the first letter       //
//                textptr - A pointer to an array of text to display          //
//                size - The size of the text: 1 = 5x7, 2 = 10x14, ...        //
//                color - ON or OFF                                           //
// Dependencies:  glcd_pixel()                                                //
//****************************************************************************//
void glcd_text57(int x, int y, char* textptr, int size, int1 color)
{
   unsigned int8 j, k, l, m;                       // Loop counters
   unsigned int8 pixelData[5];                     // Stores character data

   for(; *textptr != '\0'; ++textptr, ++x)// Loop through the passed string
   {
      if(*textptr < 'S') // Checks if the letter is in the first font array
         memcpy(pixelData, FONT[*textptr - ' '], 5);
      else if(*textptr <= '~') // Check if the letter is in the second font array
         memcpy(pixelData, FONT2[*textptr - 'S'], 5);
      else
         memcpy(pixelData, FONT[0], 5);   // Default to space

      // Handles newline and carriage returns
      switch(*textptr)
      {
         case '\n':
            y += 7*size + 1;
            continue;
         case '\r':
            x = 0;
            continue;
      }

      if(x+5*size >= GLCD_WIDTH)          // Performs character wrapping
      {
         x = 0;                           // Set x at far left position
         y += 7*size + 1;                 // Set y at next position down
      }
      for(j=0; j<5; ++j, x+=size)         // Loop through character byte data
      {
         for(k=0; k < 7; ++k)             // Loop through the vertical pixels
         {
            if(bit_test(pixelData[j], k)) // Check if the pixel should be set
            {
               for(l=0; l < size; ++l)    // These two loops change the
               {                          // character's size
                  for(m=0; m < size; ++m)
                  {
                     glcd_pixel(x+m, y+k*size+l, color); // Draws the pixel
                  }
               }
            }
         }
      }
   }
}

void glcd_image_xy(int ancho, int alto,int x, int y, int1 inverse, unsigned char *imagen) //ancho maximo:128, alto maximo:64, x= fila, y=columna, inverse= invertir color, imagen= arreglo a dibujar)
{
   unsigned int i, j, k;
   unsigned int16 count=0;
   int width  = ancho;
   int height = alto;
   glcd_fillScreen(OFF);                        //Clears the screen (opt.)
   if(inverse)
   {
      for(i=0;i<height;i+=8)
      {   
         for(j=0;j<width;j++)
         {
            for(k=0;k<8;k++)
            {
               if(~bit_test(imagen[count],k))
               {
                  glcd_pixel(x+j,y+i+k,ON);
               }
            }
            count++;
         }
      }
   }
   else
   {
      for(i=0;i<height;i+=8)
      {   
         for(j=0;j<width;j++)
         {
            for(k=0;k<8;k++)
            {
               if(bit_test(imagen[count],k))
               {
                  glcd_pixel(x+j,y+i+k,ON);
               }
            }
            count++;
         }
      }
   }
}

Codigo del Esclavo:

Código: [Seleccionar]

//**************LIBRERIA PRINCIPAL PIC, FUSES, DELAY, CRISTAL
#include<18f26k22.h>
#fuses HSH,NOWDT,NOPROTECT,NOLVP,NODEBUG,NOBROWNOUT,PUT,NOPLLEN,NOFCMEN,NOIESO
#use delay(clock=20Mhz)

//*********************MAPEO DE PLANTILLA BASE DE PANTALLA GLCD**************************************
unsigned char plantilla_1_glcd [] = {
0xFF, 0xFF, 0xFF, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xFF, 0xFF, 0xFF
};

//************************MAPEO DE LOGO MCU TRONICS************************************************
unsigned char splash_glcd [] = {
0xFF, 0xFF, 0xFF, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x87, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x87, 0x87, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x80, 0xC0, 0xF0, 0xF8, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xF0, 0xC0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0x07, 0x03, 0x03, 0x03, 0x03, 0x07, 0x07, 0x07, 0x0F, 0x1E, 0x1C, 0x3C, 0x38, 0x38,
0x20, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF0, 0xFE,
0xFF, 0x3F, 0x7F, 0xF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0xC0, 0xC0, 0xC0, 0xC0,
0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xFF, 0xFF, 0xFF
};

//***************LIBRERIAS AUXILIARES***************************
#include"ST7920.h"
//#include<stdlib.h>
//#include <graphics.c>
//****************PERIFERICOS************************************
#use i2c(SLAVE,SCL=PIN_C3,SDA=PIN_C4,ADDRESS=0x10,SLOW=100000,FORCE_HW,STREAM=GLCD)

//****************PROTOTIPOS DE FUNCIONES************************
void configuracion(void);
void plantilla_base(void);

//****************VARIABLES**************************************
char titulo_texto[20]="Despachador de Agua";
char signo_pesos[2];
char recibido[10]="Recibido:";
char cadena_datos[5]={' ',' ',' ',' ',' '};
unsigned int8 dato=0,dato_r=0;
int1 i2c_datos=0;

//***************INTERRUPCIONES*********************************
#INT_SSP
void recepcion_i2c(void)
{
   dato=i2c_read(GLCD);
   i2c_datos=1;
}
//Funcion main()
void main()
{
   //Configuracion y Plantilla base del GLCD
   configuracion();
   plantilla_base();
   
   //Ciclo infinito
   while(true)
   { 
      if(i2c_datos==1)
      {
         i2c_datos=0;
         sprintf(cadena_datos,"%u",dato);
         glcd_text57(73,18,cadena_datos,2,1);
         glcd_update();
         
      }
     
   }
}

void configuracion(void)
{
   //Habilitacion de interrupciones
   enable_interrupts(INT_SSP);
   enable_interrupts(PERIPH);
   enable_interrupts(GLOBAL);
   clear_interrupt(INT_SSP);
   //Inicializacion de GLCD
   glcd_init_graph();
   //Dibujamos el splash del logo MCU Tronics
   //glcd_image_xy(128,64,0,0,NO,splash_glcd);
   //glcd_update();
   //delay_ms(2000);
}

void plantilla_base(void)
{
   //Dibujamos la plantilla base
   glcd_image_xy(128,64,0,0,NO,plantilla_1_glcd);
   //Colocamos todos los textos
   glcd_text57(6,4,titulo_texto,1,1);
   glcd_text57(4,21,recibido,1,1);
   sprintf(signo_pesos,"$");
   glcd_text57(60,18,signo_pesos,2,1);
   //Dibujamos los textos y la plantilla
   glcd_update();
}
Nunca se deja de aprender

Desconectado thegame

  • PIC18
  • ****
  • Mensajes: 441
    • Mcu Tronics
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #6 en: 23 de Julio de 2020, 19:41:36 »
adjunto imagen de como dibuja el dato que le envió, en este caso, se le envió un 25.

 

* caracter_ilegible_glcd.jpg
(72.64 kB, 400x533 - visto 413 veces)


Nunca se deja de aprender

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #7 en: 23 de Julio de 2020, 20:04:19 »
Eso no parece que sea el 25 el problema (envio,recepcion, ya que el 25 está)... Sino como que en ese lugar el 25 sale mal... Probaste algun codigo enviando el 25 unicamente, de esa forma y en el mismo lugar del LCD?

O sera que las otras partes escritas traen el problema y es problema del LCD...

El envio y recepcion, funcionan.
Escribir en el LCD tambien. Y se nota claramente el 25, funciona en otras partes. imagino que eso es el 1,1 las coordenadas de comienzo. Por lo que las librerias funcionan.
Ahi se logra ver que es el 25, si funciona bien para las posiciones 1,1, entonces funcionaria correctamente para las posiciones esas que tenes.
Por eso tal ves sea algo del LCD.
« Última modificación: 23 de Julio de 2020, 20:07:51 por KILLERJC »

Desconectado thegame

  • PIC18
  • ****
  • Mensajes: 441
    • Mcu Tronics
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #8 en: 23 de Julio de 2020, 20:17:33 »
Si lo hago dibujar con el otro código expuesto, es decir sin involucrar el dato recibido desde el maestro, lo dibuja a la perfección en la misma posición exacta.

se los muestro:

 

* Caracter legible.jpg
(72.17 kB, 400x533 - visto 401 veces)

Nunca se deja de aprender

Desconectado thegame

  • PIC18
  • ****
  • Mensajes: 441
    • Mcu Tronics
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #9 en: 23 de Julio de 2020, 20:25:58 »
Lo he echo dibujar en otra posicion del GLCD, tomando en cuenta el caracter recibido desde el maestro, y tiene el mismo efecto, mal mal remal:

 

* Caracter ilegible en otra posicion.jpg
(70.36 kB, 400x533 - visto 431 veces)
Nunca se deja de aprender

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #10 en: 23 de Julio de 2020, 20:29:27 »
pregunta... RAM ocupada? que no estemos teniendo problemas por eso.

Listemos que cosas funcionan y que no..

Conversion a decimal - SI
Comunicacion - SI
LCD - SI
Librerias - SI

Lo mas raro es que es el MISMO patron en ambos...
« Última modificación: 23 de Julio de 2020, 20:37:41 por KILLERJC »

Desconectado thegame

  • PIC18
  • ****
  • Mensajes: 441
    • Mcu Tronics
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #11 en: 23 de Julio de 2020, 20:36:28 »
Tengo actualmente el 81% ocupada, la ocupan una imagen que uso de presentacion al arranque, un splash, y la otra es la plantilla, los marcos basicamente.

Permiteme y saco una, y pruebo....
Nunca se deja de aprender

Desconectado thegame

  • PIC18
  • ****
  • Mensajes: 441
    • Mcu Tronics
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #12 en: 23 de Julio de 2020, 20:41:42 »
Negativo, la reduje hasta el 29%, y sigue mal

y si, es el mismo patron mal dibujado sin importar a donde lo mueva o incluso variando el tamaño.

saludos
« Última modificación: 23 de Julio de 2020, 20:43:55 por thegame »
Nunca se deja de aprender

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #13 en: 23 de Julio de 2020, 20:44:11 »
Bueno ultima prueba.... con reduccion del 29% por las dudas.


Recibir el dato, comprobarlo con dato == 25
Convertirlo a ASCII, comprobarlo con cadena_datos[0] == '2' && cadena_datos[1] =='5' && cadena_datos[2] == 0

Si todo esta perfecto, entonces pasamos a ver si es algo de la libreria del GLCD. Al menos te ayudaria a encerrar un poco mas el problema y si es posible un debugger mejor.
« Última modificación: 23 de Julio de 2020, 20:46:25 por KILLERJC »

Desconectado thegame

  • PIC18
  • ****
  • Mensajes: 441
    • Mcu Tronics
Re:Error de visualización GLCD, con protocolo I2C
« Respuesta #14 en: 23 de Julio de 2020, 21:29:32 »
Corrigeme si estoy mal Killer, para la conversion a ASCII, es correcto asi:

Código: [Seleccionar]
a=(int)dato/10;
dato=dato-(a*10);
b=(int)dato/1;
         
cadena_datos[0]="0"+a;
cadena_datos[1]="0"+b;

En alguna otra prueba que hice, envie desde el maestro, una 'a', y en el esclavo revisaba ese mismo caracter y me lo corroboraba sin problema
« Última modificación: 23 de Julio de 2020, 21:31:49 por thegame »
Nunca se deja de aprender