[ kazanovic @ 04.11.2015. 09:02 ] @
Imam sledeći problem, dakle koristio sam 16x2 lcd sa 16f628a naravno sve radi kako treba. Posto mi koristenje display-a na standardni nacin zauzima previse pinova rjesio sam kupiti i2c modul za display.

Modul koji sam kupio

Koristim mikroC i on ima u sebi biblioteku za softverski i2c posto ovaj PIC nema hardwerski ugradjen. Pokusavao sam razne primjere sa neta medjutim bezuspjesno nista se ne desava display samo upaljen, nikako ne mogu da ga natjeram da izbaci nesto na ekran.

da li neko ima iskustva sa ovim problemom ili ima neki hex naravno sa semom da mogu ubaciti u cip i testirati modul cisto da vidim da li radi.

[ ZAS011 @ 04.11.2015. 12:11 ] @
A imaš li još kakvu dokumentaciju uz taj modul?
Traži od kineza da ti pošalje.
[ darkominich @ 04.11.2015. 19:43 ] @
Probaj da prepravis kod odavde za softverski I2C:
http://www.libstock.com/projects/view/1434/i2c-lcd-16x2-20x2-20x4

Takodje koju si I2C adresu koristio?
Koliko vidim po dokumentaciji po defaultu je 0x27 (kada nijedan kratkospojnik nije stavljen na A0, A1 i A2).

Kod mikroelektronikinih biblioteka za I2C za PIC je cesto slucaj da adresu moras da siftujes u levo za jedan bit.
Probaj sa 0x4E.
[ kazanovic @ 04.11.2015. 21:31 ] @
Evo koda koji koristim, mozda ce neko uociti gresku.

Code:


#define _LCD_FIRST_ROW          0x80     //Move cursor to the 1st row
#define _LCD_SECOND_ROW         0xC0     //Move cursor to the 2nd row
#define _LCD_THIRD_ROW          0x94     //Move cursor to the 3rd row
#define _LCD_FOURTH_ROW         0xD4     //Move cursor to the 4th row
#define _LCD_CLEAR              0x01     //Clear display
#define _LCD_RETURN_HOME        0x02     //Return cursor to home position, returns a shifted display to
                                         //its original position. Display data RAM is unaffected.
#define _LCD_CURSOR_OFF         0x0C     //Turn off cursor
#define _LCD_UNDERLINE_ON       0x0E     //Underline cursor on
#define _LCD_BLINK_CURSOR_ON    0x0F     //Blink cursor on
#define _LCD_MOVE_CURSOR_LEFT   0x10     //Move cursor left without changing display data RAM
#define _LCD_MOVE_CURSOR_RIGHT  0x14     //Move cursor right without changing display data RAM
#define _LCD_TURN_ON            0x0C     //Turn Lcd display on
#define _LCD_TURN_OFF           0x08     //Turn Lcd display off
#define _LCD_SHIFT_LEFT         0x18     //Shift display left without changing display data RAM
#define _LCD_SHIFT_RIGHT        0x1E     //Shift display right without changing display data RAM

#define  Waddr 0x3F

// Software I2C connections
sbit Soft_I2C_Scl           at RA3_bit;
sbit Soft_I2C_Sda           at RA4_bit;
sbit Soft_I2C_Scl_Direction at TRISA3_bit;
sbit Soft_I2C_Sda_Direction at TRISA4_bit;

/*   LCD_I2C found with PCF8574
         P7,P6,P5,P4 of PCF8574 = MSbits DB7,DB6,DB5,DB4 of LCD Display.
         P3 is hardware display bit (BackLight : 1 = on / 0 = off)
         P2 is hardware E display bit clock : E = 1 -> E = 0 active
         P1 is R/W hardware Read/Write bit hardware : Read = 1 / Write = 0
         P0 is RS hardware Register Select : CmdReg = 0 / DataReg = 1
*/

char msg[21];
char message1[] = "Software I2C LCD";
char message2[] = "16x2, 20x2, 20x4";
const char message3[] = "PIC12F683";
const char message4[] = "mikroC PRO PIC";

void Soft_I2C_LCD_Cmd(char out_char) {

    char hi_n, lo_n;
    char rs = 0x00;

    hi_n = out_char & 0xF0;
    lo_n = (out_char << 4) & 0xF0;

    Soft_I2C_Start();
    Soft_I2C_Write(Waddr);
    Soft_I2C_Write(hi_n | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(hi_n | rs | 0x00 | 0x08);
    Delay_us(100);
    Soft_I2C_Write(lo_n | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(lo_n | rs | 0x00 | 0x08);
    Soft_I2C_Stop();

    if(out_char == 0x01)Delay_ms(2);
}

void Soft_I2C_LCD_Chr(char row, char column, char out_char) {

    char hi_n, lo_n;
    char rs = 0x01;

    switch(row){

        case 1:
        Soft_I2C_LCD_Cmd(0x80 + (column - 1));
        break;
        case 2:
        Soft_I2C_LCD_Cmd(0xC0 + (column - 1));
        break;
        case 3:
        Soft_I2C_LCD_Cmd(0x94 + (column - 1));
        break;
        case 4:
        Soft_I2C_LCD_Cmd(0xD4 + (column - 1));
        break;
    };

    hi_n = out_char & 0xF0;
    lo_n = (out_char << 4) & 0xF0;

    Soft_I2C_Start();
    Soft_I2C_Write(Waddr);
    Soft_I2C_Write(hi_n | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(hi_n | rs | 0x00 | 0x08);
    Delay_us(100);
    Soft_I2C_Write(lo_n | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(lo_n | rs | 0x00 | 0x08);
    Soft_I2C_Stop();
}

void Soft_I2C_LCD_Chr_Cp(char out_char) {

    char hi_n, lo_n;
    char rs = 0x01;

    hi_n = out_char & 0xF0;
    lo_n = (out_char << 4) & 0xF0;

    Soft_I2C_Start();
    Soft_I2C_Write(Waddr);
    Soft_I2C_Write(hi_n | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(hi_n | rs | 0x00 | 0x08);
    Delay_us(100);
    Soft_I2C_Write(lo_n | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(lo_n | rs | 0x00 | 0x08);
    Soft_I2C_Stop();
}


void Soft_I2C_LCD_Init() {

    char rs = 0x00;

    Soft_I2C_Start();
    Soft_I2C_Write(Waddr);
    Delay_ms(30);

    Soft_I2C_Write(0x30 | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(0x30 | rs | 0x00 | 0x08);
    Delay_ms(10);
    Soft_I2C_Write(0x30 | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(0x30 | rs | 0x00 | 0x08);
    Delay_ms(10);
    Soft_I2C_Write(0x30 | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(0x30 | rs | 0x00 | 0x08);
    Delay_ms(10);
    Soft_I2C_Write(0x20 | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(0x20 | rs | 0x00 | 0x08);
    Soft_I2C_Stop();
    Delay_ms(10);

    Soft_I2C_LCD_Cmd(0x28);
    Soft_I2C_LCD_Cmd(0x06);
}

void Soft_I2C_LCD_Out(char row, char col, char *text) {
    while(*text)
         Soft_I2C_LCD_Chr(row, col++, *text++);
}

void Soft_I2C_LCD_Out_Cp(char *text) {
    while(*text)
         Soft_I2C_LCD_Chr_Cp(*text++);
}

void main() {
     Delay_ms(2000);
     TRISB = 0;
     PORTB = 0xFF;
     TRISB = 0xff;

     CMCON = 0x07;              // Disable comparators
     
     Soft_I2C_Init();

    Soft_I2C_LCD_Init();
    Soft_I2C_LCD_Cmd(_LCD_CURSOR_OFF);
    Soft_I2C_LCD_Cmd(_LCD_CLEAR);

    Soft_I2C_LCD_Out(1,1,message1);
    Soft_I2C_LCD_Out(2,1,message2);

    while(1) {

    }
}






[Ovu poruku je menjao kazanovic dana 05.11.2015. u 09:03 GMT+1]
[ darkominich @ 05.11.2015. 19:37 ] @
Code:
#define  Waddr 0x3F


Probaj da zamenis sa nekom od ove dve linije koda:
Code:
#define  Waddr 0x4E

ili
Code:
#define  Waddr 0x27


Cini se da ti nije dobra adresa za I2C.
[ kazanovic @ 05.11.2015. 20:21 ] @
probao sam i sa 0x27 i 0x4E i ostale adrese ni meni nije jasno. nista se ne desava sa displey-om samo bude popunjen donji dio displeya kao kada mu se samo dovede samo napon bez povezivanja na kontroler. Da imam kakav hex kod da ga ubacim u cip cisto da probam da vidim da li je hardverske ili softverske prirode.
[ kazanovic @ 07.11.2015. 23:42 ] @
pozdrav,

imam jedan primjer za i2c sat pa sam malo cackao da vidim da li ce to funkcionisati. Primjer je uradjen tako da koristi externi kristal na 8mhz medjutim ja nemam kristal te velicine pa sam stavio na interni oscilator na 4mhz. Posto ni to nije radilo uzeo sam dio po dio dodavao, radi dok god ne pokusam da inicijalizujem i2c. Da li je moguce da ne radi sto nije koristen externi oscilator ili je ipak u necemu drugom problem.
[ kazanovic @ 17.11.2015. 08:10 ] @
Evo kod koji konacno radi


Code:

#define _LCD_FIRST_ROW          0x80     //Move cursor to the 1st row
#define _LCD_SECOND_ROW         0xC0     //Move cursor to the 2nd row
#define _LCD_THIRD_ROW          0x94     //Move cursor to the 3rd row
#define _LCD_FOURTH_ROW         0xD4     //Move cursor to the 4th row
#define _LCD_CLEAR              0x01     //Clear display
#define _LCD_RETURN_HOME        0x02     //Return cursor to home position, returns a shifted display to
                                         //its original position. Display data RAM is unaffected.
#define _LCD_CURSOR_OFF         0x0C     //Turn off cursor
#define _LCD_UNDERLINE_ON       0x0E     //Underline cursor on
#define _LCD_BLINK_CURSOR_ON    0x0F     //Blink cursor on
#define _LCD_MOVE_CURSOR_LEFT   0x10     //Move cursor left without changing display data RAM
#define _LCD_MOVE_CURSOR_RIGHT  0x14     //Move cursor right without changing display data RAM
#define _LCD_TURN_ON            0x0C     //Turn Lcd display on
#define _LCD_TURN_OFF           0x08     //Turn Lcd display off
#define _LCD_SHIFT_LEFT         0x18     //Shift display left without changing display data RAM
#define _LCD_SHIFT_RIGHT        0x1E     //Shift display right without changing display data RAM

#define  Waddr 0x4E

 // Software I2C connections
sbit Soft_I2C_Scl           at RA3_bit;
sbit Soft_I2C_Sda           at RA4_bit;
sbit Soft_I2C_Scl_Direction at TRISA3_bit;
sbit Soft_I2C_Sda_Direction at TRISA4_bit;

/*   LCD_I2C found with PCF8574
         P7,P6,P5,P4 of PCF8574 = MSbits DB7,DB6,DB5,DB4 of LCD Display.
         P3 is hardware display bit (BackLight : 1 = on / 0 = off)
         P2 is hardware E display bit clock : E = 1 -> E = 0 active
         P1 is R/W hardware Read/Write bit hardware : Read = 1 / Write = 0
         P0 is RS hardware Register Select : CmdReg = 0 / DataReg = 1
*/

char msg[21];
char message1[] = "Software I2C LCD";
char message2[] = "16x2, 20x2, 20x4";
const char message3[] = "PIC12F683";
const char message4[] = "mikroC PRO PIC";

void Soft_I2C_LCD_Cmd(char out_char) {

    char hi_n, lo_n;
    char rs = 0x00;

    hi_n = out_char & 0xF0;
    lo_n = (out_char << 4) & 0xF0;

    Soft_I2C_Start();
    Soft_I2C_Write(Waddr);
    Soft_I2C_Write(hi_n | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(hi_n | rs | 0x00 | 0x08);
    Delay_us(100);
    Soft_I2C_Write(lo_n | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(lo_n | rs | 0x00 | 0x08);
    Soft_I2C_Stop();

    if(out_char == 0x01)Delay_ms(2);
}

void Soft_I2C_LCD_Chr(char row, char column, char out_char) {

    char hi_n, lo_n;
    char rs = 0x01;

    switch(row){

        case 1:
        Soft_I2C_LCD_Cmd(0x80 + (column - 1));
        break;
        case 2:
        Soft_I2C_LCD_Cmd(0xC0 + (column - 1));
        break;
        case 3:
        Soft_I2C_LCD_Cmd(0x94 + (column - 1));
        break;
        case 4:
        Soft_I2C_LCD_Cmd(0xD4 + (column - 1));
        break;
    };

    hi_n = out_char & 0xF0;
    lo_n = (out_char << 4) & 0xF0;

    Soft_I2C_Start();
    Soft_I2C_Write(Waddr);
    Soft_I2C_Write(hi_n | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(hi_n | rs | 0x00 | 0x08);
    Delay_us(100);
    Soft_I2C_Write(lo_n | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(lo_n | rs | 0x00 | 0x08);
    Soft_I2C_Stop();
}

void Soft_I2C_LCD_Chr_Cp(char out_char) {

    char hi_n, lo_n;
    char rs = 0x01;

    hi_n = out_char & 0xF0;
    lo_n = (out_char << 4) & 0xF0;

    Soft_I2C_Start();
    Soft_I2C_Write(Waddr);
    Soft_I2C_Write(hi_n | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(hi_n | rs | 0x00 | 0x08);
    Delay_us(100);
    Soft_I2C_Write(lo_n | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(lo_n | rs | 0x00 | 0x08);
    Soft_I2C_Stop();
}


void Soft_I2C_LCD_Init() {

    char rs = 0x00;

    Soft_I2C_Start();
    Soft_I2C_Write(Waddr);
    Delay_ms(30);

    Soft_I2C_Write(0x30 | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(0x30 | rs | 0x00 | 0x08);
    Delay_ms(10);
    Soft_I2C_Write(0x30 | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(0x30 | rs | 0x00 | 0x08);
    Delay_ms(10);
    Soft_I2C_Write(0x30 | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(0x30 | rs | 0x00 | 0x08);
    Delay_ms(10);
    Soft_I2C_Write(0x20 | rs | 0x04 | 0x08);
    Delay_us(50);
    Soft_I2C_Write(0x20 | rs | 0x00 | 0x08);
    Soft_I2C_Stop();
    Delay_ms(10);

    Soft_I2C_LCD_Cmd(0x28);
    Soft_I2C_LCD_Cmd(0x06);
}

void Soft_I2C_LCD_Out(char row, char col, char *text) {
    while(*text)
         Soft_I2C_LCD_Chr(row, col++, *text++);
}

void Soft_I2C_LCD_Out_Cp(char *text) {
    while(*text)
         Soft_I2C_LCD_Chr_Cp(*text++);
}

void main() {
void Soft_I2C_Init();

     CMCON  |= 7;        // Disable CompaRAtors
     TRISB = 0x00; // Set PORTB7 input all other direction to be output
     PORTB = 0xff;    // Turn OFF LEDs on PORTB
     TRISA = 0b00000000; // RA5-6-7 is input only
     delay_ms(200);
    Soft_I2C_LCD_Init();
    Soft_I2C_LCD_Cmd(_LCD_CURSOR_OFF);
    Soft_I2C_LCD_Cmd(_LCD_CLEAR);

    Soft_I2C_LCD_Out(1,1,message1);
    Soft_I2C_LCD_Out(2,1,message2);

    while(1) {

    }
}



Problem je bio u ovoj liniji koda
Code:
void Soft_I2C_Init();


A adresa za modul je 0x4E
[ kazanovic @ 17.11.2015. 08:15 ] @
Evo i kod za satni modul DS1307 sa pic 16F628A I2C komunikacija ako kome bude trebalo posto sam se bas namucio sa primjerima sa neta ovo 100% radi. Koristio sam 16Mhz oscilator ma da vjerovatno moze raditi i sa internim za sad nisam probao.

Code:

 // LCD module connections
sbit LCD_RS at RA0_bit;
sbit LCD_EN at RA1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISA0_bit;
sbit LCD_EN_Direction at TRISA1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;

 // Software I2C connections
sbit Soft_I2C_Scl           at RA3_bit;
sbit Soft_I2C_Sda           at RA4_bit;
sbit Soft_I2C_Scl_Direction at TRISA3_bit;
sbit Soft_I2C_Sda_Direction at TRISA4_bit;

unsigned short sec;
unsigned short minute;
unsigned short hour;
unsigned short day;
unsigned short date;
unsigned short month;
unsigned short year;
unsigned short dataa;
char ddate[11];
char time[12];
unsigned char dday;
unsigned char dhour;
unsigned char BCD2UpperCh(unsigned char bcd);
unsigned char BCD2LowerCh(unsigned char bcd);

unsigned short read_ds1307(unsigned short address)

{
  unsigned short r_data;
  Soft_I2C_Start();
  Soft_I2C_Write(0xD0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
  Soft_I2C_Write(address);
  Soft_I2C_Start();
  Soft_I2C_Write(0xD1); //0x68 followed by 1 --> 0xD1
  r_data=Soft_I2C_Read(0);
  Soft_I2C_Stop();
  return(r_data);
}

void write_ds1307(unsigned short address,unsigned short w_data)
{
  Soft_I2C_Start(); // issue I2C start signal
  //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
  Soft_I2C_Write(0xD0); // send byte via I2C (device address + W)
  Soft_I2C_Write(address);
  Soft_I2C_Write(w_data); // send data (data to be written)
  Soft_I2C_Stop(); // issue I2C stop signal
}

void main()
{
     void Soft_I2C_Init();

     CMCON  |= 7;        // Disable CompaRAtors
     TRISB = 0x00; // Set PORTB7 input all other direction to be output
     PORTB = 0xff;    // Turn OFF LEDs on PORTB
     TRISA = 0b00000000; // RA5-6-7 is input only

      Lcd_Init(); // Initialize LCD
      Lcd_Cmd(_LCD_CLEAR); // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
      Lcd_Out(1,1,"Ucitavanje..."); // Write message3 in 1st row
      Lcd_Out(2,1,"SAT 1.0 BY KAZAN");
      Delay_ms(1000);

      //Set Time
      //write_ds1307(0,0x80); //Reset second to 0 sec. and stop Oscillator
      //write_ds1307(1,0x50); //write min 25
      //write_ds1307(2,0x69); //write hour 8 PM
      //write_ds1307(3,0x01); //write day of week 2:Saturday
      //write_ds1307(4,0x09); // write date 22
      //write_ds1307(5,0x11); // write month May
      //write_ds1307(6,0x15); // write year 10 --> 2010
      //write_ds1307(7,0x10); //SQWE output at 1 Hz
      //write_ds1307(0,0x00); //Reset second to 0 sec. and start Oscillator

      Delay_ms(1000);
      Lcd_Cmd(_LCD_CLEAR); // Clear display
      
      while(1){
          sec=read_ds1307(0); // read second
          minute=read_ds1307(1); // read minute
          hour=read_ds1307(2); // read hour
          day=read_ds1307(3); // read day
          date=read_ds1307(4); // read date
          month=read_ds1307(5); // read month
          year=read_ds1307(6); // read year

          ddate[0] = BCD2UpperCh(date);
          ddate[1] = BCD2LowerCh(date);
          ddate[2] = '/';
          ddate[3] = BCD2UpperCh(month);
          ddate[4] = BCD2LowerCh(month);
          ddate[5] = '/';
          ddate[6] = '2';
          ddate[7] = '0';
          ddate[8] = BCD2UpperCh(year);
          ddate[9] = BCD2LowerCh(year);
          ddate[10] = '\0';
          dday = BCD2LowerCh(day);

          dhour = BCD2UpperCh(hour);

          if (dhour == '4') {
             time[0] = ' ';
             time[9] = 'A';
          }
          else if (dhour == '5') {
             time[0] = '1';
             time[9] = 'A';
          }
          else if (dhour == '6') {
             time[0] = ' ';
             time[9] = 'P';
          }
          else if (dhour == '7') {
             time[0] = '1';
             time[9] = 'P';
          }

          time[1] = BCD2LowerCh(hour);
          time[2] = ':';
          time[3] = BCD2UpperCh(minute);
          time[4] = BCD2LowerCh(minute);
          time[5] = ':';
          time[6] = BCD2UpperCh(sec);
          time[7] = BCD2LowerCh(sec);
          time[8] = ' ';
          time[10] = 'M';
          time[11] = '\0';


          Lcd_Out(1,4, sec); // Write message3 in 1st row
          Lcd_Out(2,3,time);
          delay_ms(200);
        }
}

unsigned char BCD2LowerCh(unsigned char bcd)
{
         return ((bcd & 0x0F) + '0');
}
unsigned char BCD2UpperCh(unsigned char bcd)
{
         return ((bcd >> 4) + '0');
}




Ne bi bilo lose ako neko koristi kao i ja PIC a da povezuje sa Arduino modulima a da ima vec uradjene primjere da ubaci ovdje.