Newhaven Display Forum

Newhaven Products => Character LCDs => Topic started by: samiam208 on June 10, 2014, 10:25:10 PM

Title: I2C Controller (PIC16F960) more detail needed
Post by: samiam208 on June 10, 2014, 10:25:10 PM
I am trying to use a Serial LCD Character Display with the PIC16F690 controller in the I2C mode. I am writing a bit-bang assembly code program.  I cannot find sufficient info to accomplish the I2C protocol for this controller.  What is the sequence I use to send ASCII characters to be displayed? Will this work?-- Start, Device address, ASCII Byte,……..more ASCII Bytes, Stop?  The “Table of Commands” does not show any Prefix or command for displaying characters and does not show anything for multi-character(byte) transfers.  The Data Sheet for the controller is just the generic PIC and does not help.  Are there any documents that detail the I2C interface?  You know the kind of detail that is shown for an I2C EEPROM or RTC.  The exact display I am trying to use is NHD-0216K3Z-NS(RGB)-FWB-V3.
Title: Re: I2C Controller (PIC16F960) more detail needed
Post by: Michael_L on June 11, 2014, 09:42:28 AM
The PIC controller datasheet we provide a link to in our spec is the actual datasheet for that PIC.  Have you looked at pages 184-186?  Also included in our datasheet is also a link to example code for our serial LCDs.  You may access this to help see how the interface works with our display.  In addition to that example code, you may also refer to the below Arduino code I have for this display:

Code: [Select]
//---------------------------------------------------------
/*
NHD_0216K3Z_mega.ino
Program for writing to Newhaven Display 2 x 16 (K3Z) Character LCD with PIC16F690 controller

(c)2014 Mike LaVine - Newhaven Display International, LLC.

        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
*/
//---------------------------------------------------------

#include <Wire.h>

int ASDA = 20;      // SDA signal connected to pin 20 (SDA) of Arduino Mega 2560
int ASCL = 21;      // SCL signal connected to pin 21 (SCL) of Arduino Mega 2560

unsigned char text1[]={"Newhaven Display"};
unsigned char text2[]={" International  "};

unsigned char tx_packet[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);

const char slave2w = 0x28;   //0x50 shifted over 1 bit

void send_packet(unsigned char x)
{
  unsigned char ix;
  Wire.beginTransmission(slave2w);
  for(ix=0;ix<x;ix++)
  {
    Wire.write(tx_packet[ix]);
  }
  Wire.endTransmission();
}

void lcd_cursor(unsigned int x)
{
  tx_packet[0] = 0xFE;
  tx_packet[1] = 0x45;
  tx_packet[2] = x;
  send_packet(3);
}

void lcd_clear(void)
{
  tx_packet[0] = 0xFE;
  tx_packet[1] = 0x51;
  send_packet(2);
}

void setup()       //runs first when powered on
{
  pinMode(ASCL, OUTPUT);      //set Arduino I2C lines as outputs
  pinMode(ASDA, OUTPUT);      //
  digitalWrite(ASCL, LOW);    //
  digitalWrite(ASDA, LOW);    //
  delay(100);    //100ms delay
}

void loop()
{
  Wire.begin();             //initialize Arduino I2C
  TWBR = 152;               //change Arduino Mega 2560 I2C clock frequency from 100kHz to 50kHz
  lcd_clear();
 
  tx_packet[0] = 0xFE;
  tx_packet[1] = 0x52;
  tx_packet[2] = 40;        //contrast 1 - 50
  send_packet(3);
 
  tx_packet[1] = 0x53;     
  tx_packet[2] = 15;        //backlight 1 - 15
  send_packet(3);
 
  tx_packet[1] = 0x48;      //underline cursor off
  send_packet(2);
 
  tx_packet[1] = 0x46;      //cursor home
  send_packet(2);
 
  delay(250);
 
  while(1)
  {
  for(unsigned char i=0;i<16;i++)
  {
    tx_packet[i] = text1[i];
  }
  send_packet(16);
 
  lcd_cursor(0x40);
  delay(100);  //100ms delay
 
  for(unsigned char i=0;i<16;i++)
  {
    tx_packet[i] = text2[i];
  }
  send_packet(16);
  delay(1000);
  }
}


Any other detailed information regarding that PIC controller can be found in the datasheet for it, accessible by clicking the link to it in our spec.
Title: Re: I2C Controller (PIC16F960) more detail needed
Post by: samiam208 on June 18, 2014, 09:23:16 AM
Thanks,
I got it now.
Samiam208