Author Topic: I2C pcf8574t based LCD on PIC16F819-XC8 Help please?  (Read 682 times)

0 Members and 1 Guest are viewing this topic.

Offline djsbTopic starter

  • Frequent Contributor
  • **
  • Posts: 957
  • Country: gb
I2C pcf8574t based LCD on PIC16F819-XC8 Help please?
« on: June 09, 2024, 03:04:59 pm »
I've been asked to write some XC8 example code for a PIC16F819. The I2C LCD uses a PCF8574T backpack, and I'd like to provide an example for the students I work with that does NOT use the microchip code configurator plugin. I'm not even sure that the PIC16F819 can use the MCC plugin. I just need the simplest of "Hello World" examples or an example that can turn the backlight on and off.
What steps would you recommend that I take to tackle this? I'm still doing the usual YouTube and google searches, and I've yet to search through my Gooligum examples (https://github.com/gooligumelec/PIC-tutorials). Unfortunately, there are NO I2C examples in the Gooligum repository (or the full downloads which I bought a while ago).
I've also posted on the Microchip forum, but no replies so far (apart from my own replies with updates). That maybe because I've yet to show any code that I've tried. I'm just struggling to get started. Is the MCC the way to go with this kind of task? Thanks.
« Last Edit: June 10, 2024, 01:30:20 pm by djsb »
David
Hertfordshire, UK
University Electronics Technician, London, PIC16/18, CCS PCM C, Arduino UNO, NANO,ESP32, KiCad V8+, Altium Designer 21.4.1, Alibre Design Expert 28 & FreeCAD beginner. LPKF S103,S62 PCB router Operator, Electronics instructor. Credited KiCad French to English translator
 

Offline djsbTopic starter

  • Frequent Contributor
  • **
  • Posts: 957
  • Country: gb
Re: I2C pcf8574t based LCD on PIC16F819-XC8 Help please?
« Reply #1 on: June 10, 2024, 01:17:47 pm »
I've found this topic on the Microchip forum started by PStech_Paul

https://forum.microchip.com/s/topic/a5C3l000000MYXxEAO/t362857

I'll be trying some of the code in the topic out on a PIC16F1847 (which is similar to the PIC16F1825 referred to in the topic)which we also use on our course. I will report back with any progress, and I'll post any code that remotely works later.
« Last Edit: June 10, 2024, 01:25:27 pm by djsb »
David
Hertfordshire, UK
University Electronics Technician, London, PIC16/18, CCS PCM C, Arduino UNO, NANO,ESP32, KiCad V8+, Altium Designer 21.4.1, Alibre Design Expert 28 & FreeCAD beginner. LPKF S103,S62 PCB router Operator, Electronics instructor. Credited KiCad French to English translator
 

Offline amwales

  • Regular Contributor
  • *
  • Posts: 99
  • Country: gb
Re: I2C pcf8574t based LCD on PIC16F819-XC8 Help please?
« Reply #2 on: June 10, 2024, 03:30:31 pm »
You are correct that MCC is not supported for the PIC16F819, it was quite simple to check, run mplabx, create a new project targeting the chip and click MCC.
The box that pops up provides the comment 'How to fix this: change your project device to one supported by the MCC content types.'
You should be able to get something running quickly enough just clicking 'Window->Target Memory Views->Configuration Bits'
Change FOSC to INTOSCIO, WDTE to OFF and click 'Generate Source Code to Output' and add that to your main.c, compile and program with your
pickit5 programmer ( assuming you have a pickit5 programmer ).

// PIC16F819 Configuration Bit Settings

// 'C' source line config statements

// CONFIG
#pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTRC oscillator; port I/O function on both RA6/OSC2/CLKO pin and RA7/OSC1/CLKI pin)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON         // Low-Voltage Programming Enable bit (RB3/PGM pin has PGM function, Low-Voltage Programming enabled)
#pragma config CPD = OFF        // Data EE Memory Code Protection bit (Code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off)
#pragma config CCPMX = RB2      // CCP1 Pin Selection bit (CCP1 function on RB2)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>


int main(void) {

  while(1) {
  }
}


Add some code to set a pin as output, toggle the pin and add an LED.
Your next step is to find out how to do I2C, good luck
 
The following users thanked this post: djsb

Offline amwales

  • Regular Contributor
  • *
  • Posts: 99
  • Country: gb
Re: I2C pcf8574t based LCD on PIC16F819-XC8 Help please?
« Reply #3 on: June 10, 2024, 03:43:00 pm »
A little googling and I found these

https://deepbluembedded.com/interfacing-i2c-lcd-16x2-tutorial-with-pic-microcontrollers-mplab-xc8/
https://deepbluembedded.com/i2c-communication-protocol-tutorial-pic/

Different PIC chips but the ideas will be similar and may help get you started.
Compare the documentation for the PIC16F877A against the PIC16F819 i2c section, paying attention to the register names and their functions.
 
The following users thanked this post: djsb

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6239
  • Country: es
« Last Edit: June 13, 2024, 08:45:30 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: djsb


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf