problema I2C en pic18f26j50

0

He estado intentando conectar una pantalla iled de i2c en el microcontrolador pic18f26j50 pero no consigo que funcione.

Estoy usando mikroC pro para la foto.

#include "ssd1306.h"
#include "font.h"
#include "bitmap.h"

void main() {

 ANCON0 = 0x1F;
 ANCON1 = 0x1F;

 SSPSTAT=0x80;
 SSPADD=0x18;                                     //100khz baud rate
 SSPCON1=0x28;                                    // Master mode in I2c.
 SSPCON2=0x00;
 TRISB4_bit=1;
 TRISB5_bit=1;

 I2C1_Init(100000);

 Oled_Init();
 Oled_Fillscreen(0x00);
 Oled_Image(image,7,40,0,2);
}

He utilizado el mismo código exacto (con cambios de valor de registro obvios) en un pic18f2550 ... y funciona como un encanto ...

como último recurso, he cambiado todo el código para que funcione con el software I2C ... funciona pero es muy lento. Así que, obviamente, el problema no está en la pantalla sino en el código del microcontrolador.

¿Alguien puede indicarme la dirección correcta?

Oled_Init () consiste en el siguiente código.

void Oled_Init(void){
TRIS_RES = 0;
OLED_RES = 0;
Oled_Command(0xAE);                     // Set Display OFF
Oled_Command(0x81); Oled_Command(0xCF); // Set Contrast Control
Oled_Command(0xA4);                     // Entire Display ON
Oled_Command(0xA6);                     // Set Normal

Oled_Command(0x20); Oled_Command(0x02); // Set Memory Addressing Mode
Oled_Command(0x00);                     // Set Lower Column
Oled_Command(0x10);                     // Set Higher Column
Oled_Command(0xB0);                     // Set Page Start

Oled_Command(0x40);                     // Set Display Start Line
Oled_Command(0xA1);                     // Set Segment Re-map
Oled_Command(0xA8); Oled_Command(0x3F); // Set Multiplex Ratio
Oled_Command(0xC8);                     // Set COM Output
Oled_Command(0xD3); Oled_Command(0x00); // Set Display Offset
Oled_Command(0xDA); Oled_Command(0x12); // Set COM Pins Hardware Configuration

Oled_Command(0xD5); Oled_Command(0x80); // Set Display Clock
Oled_Command(0xD9); Oled_Command(0xF1); // Set Pre-charge Period
Oled_Command(0xDB); Oled_Command(0x40); // Set VCOMH Deselect Level
Oled_Command(0x8D); Oled_Command(0x14); // Charge Pump Setting

Oled_Command(0xAF);                     // Set Display ON
Oled_FillScreen(0x00);                  // Clear screen
}

y la función Oled_Command ()

void Oled_Command(uchar cmd){
I2C1_Start();
I2C1_Wr(OLED_12C_ADDRESS);
I2C1_Wr(0x00);  // Co = 0, D/C = 0
I2C1_Wr(cmd);
I2C1_Stop();
}
    
pregunta Suraj Bhawal

0 respuestas

Lea otras preguntas en las etiquetas