|
|
View previous topic :: View next topic |
Author |
Message |
ep.hobbyiest
Joined: 08 Oct 2014 Posts: 20
|
oled example code is not working |
Posted: Tue Sep 26, 2017 10:25 am |
|
|
Hi,
I am referring to a code example from one old post:
https://www.ccsinfo.com/forum/viewtopic.php?t=52861
Which seems to be working for others. But when i tried it, then the controller got stuck at the Oled_init() function only.
I am using the PIC18F25K22 controller. Here is my main.h file:
Code: |
#include <18F25K22.h>
#device ADC=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(internal=16MHz)
#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3,force_hw)
#define LED PIN_B5
#define DELAY 500
|
and here is main.c file.
Code: |
#include <main.h>
#include <string.h>
#define OLED 0x3C
#INCLUDE <stdlib.h>
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
}; // ~
const INT LOGOS [1024] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0xBE, 0xB6, 0xF6, 0xE6, 0x00, 0x00, 0xFE, 0xFE, 0x80,
0x80, 0x80, 0xFE, 0xFE, 0x00, 0x00, 0xFE, 0xFE, 0x84, 0x86, 0x86, 0xFE, 0xFC, 0x00, 0x00, 0xFC,
0xFE, 0x96, 0x96, 0x96, 0x9E, 0xDC, 0x00, 0x00, 0xFE, 0xFE, 0x0C, 0x06, 0x06, 0x00, 0x9C, 0xBE,
0xB6, 0xF6, 0xE6, 0x00, 0x00, 0xFE, 0xFE, 0x80, 0x80, 0x80, 0xFE, 0xFE, 0x00, 0x00, 0xFE, 0xFE,
0x84, 0x86, 0x86, 0xFE, 0xFC, 0x00, 0x00, 0xFC, 0xFE, 0x96, 0x96, 0x96, 0x9E, 0xDC, 0x00, 0x00,
0xFE, 0xFE, 0x0C, 0x06, 0x06, 0x06, 0xFF, 0xFF, 0x06, 0x06, 0x00, 0xFE, 0xFE, 0x0C, 0x06, 0x06,
0x00, 0xEC, 0xF6, 0x96, 0x96, 0xFE, 0xFC, 0x00, 0x00, 0xFE, 0xFE, 0x0C, 0x06, 0x06, 0xFE, 0xFC,
0x00, 0x00, 0xC6, 0xE6, 0xB6, 0x9E, 0x8E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x0F, 0x0F,
0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01,
0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0x30, 0xB0, 0xD8, 0xD8, 0xD8, 0xD8, 0x18,
0x30, 0xF0, 0xC0, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0xC0, 0xC0, 0x80,
0xC0, 0xC0, 0xC0, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0xC0,
0x80, 0x00, 0x00, 0xD8, 0xD8, 0x00, 0x00, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00,
0xC0, 0xC0, 0x80, 0xC0, 0xC0, 0xC0, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x7F, 0x60, 0xCF, 0xDF, 0xD8, 0xCC, 0xDF, 0xDB, 0x18,
0x1C, 0x0F, 0x07, 0x00, 0x00, 0xDB, 0xFF, 0xB6, 0xB6, 0xB7, 0xF3, 0xE0, 0x00, 0x3F, 0x3F, 0x01,
0x00, 0x00, 0x3F, 0x3F, 0x01, 0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00, 0x1D, 0x3E, 0x32, 0x12, 0x3F,
0x3F, 0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00,
0x1F, 0x3F, 0x30, 0x30, 0x30, 0x19, 0x00, 0x1F, 0x3F, 0x30, 0x30, 0x30, 0x3F, 0x1F, 0x00, 0x00,
0x3F, 0x3F, 0x01, 0x00, 0x00, 0x3F, 0x3F, 0x01, 0x00, 0x00, 0x3F, 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, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x06, 0x06, 0x06, 0xFE, 0xFE, 0x06, 0x06, 0x06, 0x00, 0xF0, 0xF0, 0x60, 0x30, 0x30, 0x00,
0xF6, 0xF6, 0x00, 0x00, 0xE0, 0xF0, 0xB0, 0xB0, 0xB0, 0xF0, 0xE0, 0x00, 0x00, 0xE0, 0xF0, 0xB0,
0xB0, 0x30, 0x00, 0x30, 0xFC, 0xFC, 0x30, 0x30, 0x00, 0x00, 0xE0, 0xF0, 0xB0, 0xB0, 0xB0, 0xF0,
0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF6, 0xF6, 0x00, 0x30, 0xFC,
0xFC, 0x30, 0x30, 0x00, 0x00, 0x60, 0xB0, 0xB0, 0xB0, 0xF0, 0xE0, 0x00, 0x00, 0xFF, 0xFF, 0x00,
0x30, 0xF0, 0xC0, 0x00, 0x00, 0xC0, 0xF0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
0x0F, 0x0F, 0x00, 0x00, 0x07, 0x0F, 0x0C, 0x0C, 0x0C, 0x0C, 0x06, 0x00, 0x00, 0x0C, 0x0D, 0x0D,
0x0F, 0x07, 0x00, 0x00, 0x07, 0x0F, 0x0C, 0x0C, 0x00, 0x00, 0x07, 0x0F, 0x0C, 0x0C, 0x0C, 0x0C,
0x06, 0x00, 0x20, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x07,
0x0F, 0x0C, 0x0C, 0x00, 0x00, 0x07, 0x0F, 0x0C, 0x04, 0x0F, 0x0F, 0x00, 0x00, 0x0F, 0x0F, 0x00,
0x00, 0x01, 0x67, 0x7E, 0x1E, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
int DISPLAY [1024];
void OLED_command(INT ind, int com)
{
i2c_start ();
i2c_write (ind);
i2c_write (0x00);
i2c_write (com);
i2c_stop ();
}
void OLED_write(INT ind)
{
LONG i;
OLED_command (ind, 0x21) ;
OLED_command (ind, 0x00);
OLED_command (ind, 127);
OLED_command (ind, 0x22) ;
OLED_command (ind, 0x00);
OLED_command (ind, 7);
i2c_start ();
i2c_write (ind) ;
i2c_write (0x40) ;
FOR (i = 0; i < 1024; i++)
{
i2c_write (DISPLAY[i]) ;
}
i2c_stop ();
}
void OLED_init(INT add)
{
OLED_command (add, 0xae) ;
OLED_command (add, 0xa8);
OLED_command (add, 0x3f);
OLED_command (add, 0xd3);
OLED_command (add, 0x00);
OLED_command (add, 0x40);
OLED_command (add, 0xa0);
OLED_command (add, 0xa1);
OLED_command (add, 0xc0);
OLED_command (add, 0xc8);
OLED_command (add, 0xda);
OLED_command (add, 0x12);
OLED_command (add, 0x81);
OLED_command (add, 0xfF);
OLED_command (add, 0xa4);
OLED_command (add, 0xa6) ;
OLED_command (add, 0xd5);
OLED_command (add, 0x80);
OLED_command (add, 0x8d);
OLED_command (add, 0x14) ;
OLED_command (add, 0xAF) ;
OLED_command (add, 0x20) ;
OLED_command (add, 0x00) ;
}
void OLED_pixel(LONG x,long y)
{
LONG nt;
LONG pagina;
LONG bit;
pagina = y /8;
bit= y-(pagina*8);
nt= DISPLAY[pagina*128+x];
nt |= 1 << bit;
DISPLAY[pagina*128+x] = nt;
}
void OLED_line (int x1, int y1, int x2, int y2)
{
SIGNED int x, y, addx, addy, dx, dy;
SIGNED long P;
INT i;
dx = abs ( (SIGNED int) (x2 - x1));
dy = abs ( (SIGNED int) (y2 - y1));
x = x1;
y = y1;
IF (x1 > x2)
addx = -1;
ELSE
addx = 1;
IF (y1 > y2)
addy = -1;
ELSE
addy = 1;
IF (dx >= dy)
{
P = 2 * dy - dx;
FOR (i = 0; i <= dx; ++i)
{
OLED_pixel (x, y);
IF (P < 0)
{
P += 2*dy;
x += addx;
}
ELSE
{
P += 2*dy - 2 * dx;
x += addx;
y += addy;
}
}
}
ELSE
{
P = 2 * dx - dy;
FOR (i = 0; i <= dy; ++i)
{
OLED_pixel (x, y);
IF (P < 0)
{
P += 2*dx;
y += addy;
}
ELSE
{
P += 2*dx - 2 * dy;
x += addx;
y += addy;
}
}
}
}
void OLED_circle(int x, int y, int radius, int1 riemp)
{
SIGNED int a, b, P;
a = 0;
b = radius;
P = 1 - radius;
DO
{
IF (riemp)
{
OLED_line (x - a, y+b, x + a, y + b);
OLED_line (x - a, y-b, x + a, y - b);
OLED_line (x - b, y+a, x + b, y + a);
OLED_line (x - b, y-a, x + b, y - a);
}
ELSE
{
OLED_pixel (a + x, b+y);
OLED_pixel (b + x, a+y);
OLED_pixel (x - a, b+y);
OLED_pixel (x - b, a+y);
OLED_pixel (b + x, y-a);
OLED_pixel (a + x, y-b);
OLED_pixel (x - a, y-b);
OLED_pixel (x - b, y-a);
}
IF (P < 0)
P += 3 + 2 * a++;
ELSE
P += 5 + 2 * (a++ - b--);
} WHILE (a <= b);
}
void OLED_text(int x, int y, char* textptr, int size)
{
INT i, j, k, l, m; // Loop counters
BYTE pixelData[5]; // Stores character data
FOR (i = 0; textptr[i] != '\0'; ++i, ++x) // Loop through the passed string
{
IF (textptr[i] < 'S') // Checks if the letter is in the first text array
memcpy (pixelData, TEXT[textptr[i] - ' '], 5) ;
else IF (textptr[i] <= '~') // Check if the letter is in the second array
memcpy (pixelData, TEXT2[textptr[i] - 'S'], 5) ;
ELSE
memcpy (pixelData, TEXT[0], 5); // DEFAULT to space
IF (x + 5 * size >= 128) // 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 * size; ++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) // The next two loops change the
{
// character's size
FOR (m = 0; m<size; ++m)
{
OLED_pixel (x + m, y+k * size + l); // Draws the pixel
}
}
}
}
}
}
}
void OLED_rect(int x1, int y1, int x2, int y2, int riemp)
{
IF (riemp)
{
INT y, ymax; // Find the y min and max
IF (y1 < y2)
{
y = y1;
ymax = y2;
}
ELSE
{
y = y2;
ymax = y1;
}
FOR (; y <= ymax; ++y) // Draw lines to fill the rectangle
OLED_line (x1, y, x2, y);
}
ELSE
{
OLED_line (x1, y1, x2, y1); // Draw the 4 sides
OLED_line (x1, y2, x2, y2);
OLED_line (x1, y1, x1, y2);
OLED_line (x2, y1, x2, y2);
}
}
void logo()
{
LONG x;
INT c;
FOR (x = 0; x < 1024; x++)
{
c= LOGOS[x];
DISPLAY[x] = c;
}
}
void OLED_clear()
{
LONG x;
FOR (x = 0; x < 1024; x++)
{
DISPLAY[x] = 0x00;
}
}
void main()
{
OLED_init(OLED);
// Example blinking LED program
delay_ms(DELAY);
// OLED_clear();
// logo();
// OLED_write(OLED);
while(true)
{
output_low(LED);
delay_ms(DELAY);
output_high(LED);
delay_ms(DELAY);
}
}
|
The PIC is getting stuck at the OLED_init(OLED) function.
If I comment it out, then the LED blinks continously.
1K8 pull-ups are used. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Tue Sep 26, 2017 10:49 am |
|
|
What voltages are you running the PIC and display at?
Most peripherals these days are 3 volt devices. PICs can be 5,3,2..so you need to read the datasheets and confirm basic information like this.
Also post the display make/model of the display or a link to it's datasheet.
Sometimes people use a 'module' and not the 'device', that info we need to know.
and
Since it's an I2C device, install and run the I2C Scanner program from the code library FIRST. It will confirm/deny the device actually IS connected( and what address) !
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue Sep 26, 2017 11:22 am |
|
|
If you look at this driver:
<https://www.ccsinfo.com/forum/viewtopic.php?t=54453>
You will see my comments about voltage.
The core chip is a 3.3v device. Though a lot of boards will run off 5v, the PIC at 5v will not see it's inputs go high (so will hang on an I2C write, when it sees the clock being held low).
Change your I2C setup to:
#use i2c(Master,Slow,I2C1,SMBUS)
Which will force the I2C hardware to use SMBUS switching levels, and may allow it to work.
With this change done, try the I2C scanner program and see if the device is found.
You will also find that different boards may need different configuration for the charge pump and similar settings, depending on how they are actually wired. |
|
|
ep.hobbyiest
Joined: 08 Oct 2014 Posts: 20
|
|
Posted: Tue Sep 26, 2017 11:27 am |
|
|
I am using 5 volt for the circuit as display also works on 5 volt
I am using following Display module SSD1306 i2c.
I tried i2c Scanner but nothing found on that.
But i have attached pull up of 1K8 and using Hardware i2c channel pins.
|
|
|
ep.hobbyiest
Joined: 08 Oct 2014 Posts: 20
|
|
Posted: Tue Sep 26, 2017 11:38 am |
|
|
I tried following setting as well.
#use i2c(Master,Slow,I2C1,SMBUS)
But no effect.
Should i use software I2C on other pins?
I tried 3.3V power supply as well but for complete circuit. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue Sep 26, 2017 11:46 am |
|
|
SSD1306, is the chip, not the module. Is there any data for the module you have?.
Have you tried the I2C bus scanner program?. Does it see the chip?. |
|
|
ep.hobbyiest
Joined: 08 Oct 2014 Posts: 20
|
|
Posted: Tue Sep 26, 2017 11:52 am |
|
|
I don't have any other data. I got it through ebay.
But yes we will get plenty of data online.
Yes i tried I2C scanner program which gave me result as Nothing Found. |
|
|
ep.hobbyiest
Joined: 08 Oct 2014 Posts: 20
|
|
Posted: Tue Sep 26, 2017 12:03 pm |
|
|
It is working on different port than Hardware.
I tried C0 and C1 for SDA and SCL resp. And it it working.
But in my hardware i have used C3 and C4 pins. On that pins i2c is not working.
What could be the reason?
i checked connection again and again. Is that means pins are gone? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue Sep 26, 2017 1:19 pm |
|
|
No it's the voltage problem.
Software I2C on C3 & C4, will use TTL level input buffers. Will see anything above 2.0v as a '1'. Hardware I2C by default requires 3.5v to see a '1', which won't work with the 3.3v device. The SMBUS option should drop this to 2.1v, but it's either not working or it is still not quite low enough.
I was slightly dubious about the SMBUS option working, because it does change some other parts of the bus specification. Though 'nearly the same', it is not identical to I2C.
You could just use the original pins and select FORCE_SW. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue Sep 26, 2017 2:31 pm |
|
|
There is a way round, if you are prepared to use other pins.
Key is this note in the data sheet:
Quote: |
4: These pins are configured for I2C logic levels. The SCLx/SDAx signals may be assigned to any of the RB1/RB2/RC3/RC4 pins. PPS
assignments to the other pins (e.g., RA5) will operate, but input logic levels will be standard TTL/ST, as selected by the INLVL register,
instead of the I2C specific or SMBus input buffer thresholds.
|
So you can allocate the hardware I2C to pins not listed for I2C (RA5 is the example they give), but if you do, it will then use the default logic levels, not I2C. |
|
|
ep.hobbyiest
Joined: 08 Oct 2014 Posts: 20
|
|
Posted: Tue Sep 26, 2017 9:12 pm |
|
|
Okay.
i am using PIC 18f25k22 which has 2 hardware i2c built in on RB1/RB2 and C3/C4 pins. But pin mapping is not mentioned in the datasheet neither INLVL.
Yes. I have option to use software i2c on same pin (Which is not good choice).
Quote: | Software I2C on C3 & C4, will use TTL level input buffers. Will see anything above 2.0v as a '1'. Hardware I2C by default requires 3.5v to see a '1', which won't work with the 3.3v device. The SMBUS option should drop this to 2.1v, but it's either not working or it is still not quite low enough. |
I did try on voltage 3V3 and 5V. But i think as suggested i will make combination of i2c and SMBus and try again. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue Sep 26, 2017 11:45 pm |
|
|
How are you doing the pull-ups?.
These should be to 3.3v, not 5v.
If these go to 5v, you risk reverse biasing pins on the SSD chip, and over-voltaging it. Also the chip probably won't meet the lower Vol specification for SMBUS if the resistors are pulled to 5v.
Why are you anti software I2C?. Except for the maximum speed there is no disadvantage to this. Since you are only running at 100K, this doesn't really matter at all.
However the CCS code may make some other slight changes for SMBUS, There are slight changes for this. So I'd suggest the best thing to try is:
1) Make sure pullups are to 3.3v.
2) Setup the hardware I2C as normal.
3) Then manually switch just the signalling levels to SMBUS:
Code: |
#byte SSP1STAT=getenv("SFR:SSP1STAT")
#byte SSP1CON1=getenv("SFR:SSP1CON1")
#bit SSPEN=SSP1CON1.5
#bit CKE=SSP1STAT.5
//Then in the main near the start
SSPEN=FALSE; //momentarily disable port
CKE=1; //select SMBUS levels
SSPEN=TRUE; //re-enable port.
|
This then leaves CCS loading I2C code, but with just the hardware levels switched.
One other possibility is that it is the speed causing the problems. I'd guess that the software will go to about 70KHz with your master clock. It may be as simple as the unit not liking your wiring for 100KHz. So try setting the I2C up with the SMBUS hardware, and 'slow=60000'. If it then works, you need to have a look at the waveforms and wiring and see what is wrong. |
|
|
ep.hobbyiest
Joined: 08 Oct 2014 Posts: 20
|
|
Posted: Wed Sep 27, 2017 10:33 am |
|
|
Okay. Right now I don't have 3v3 regulator spare. But i will have to mention method because my pcb are on the way.
I am not against software i2c. I was thinking that if Chip has built in I2C then let's go for it. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Thu Sep 28, 2017 2:27 am |
|
|
OK.
Try using this circuit for the pull-up:
(view with a fixed pitch font)
Code: |
+ve+
|
-----
\ /
\ / 1N4148 * 3
-----
|
-----
\ /
\ /
-----
|
-----
\ /
\ /
-----
|
+------------|
\ |
/ |
\ 1K8R ----- 0.47uF
| -----
+ |
To I2C lines |
|
_|_
\ /
|
Both I2C lines can feed from the same source (with separate resistors obviously). |
|
|
|
|
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
|