I2C pcf8574t based LCD on PIC16F819-XC8 Help please? - Page 1
Forum section: electronics / general

author: djsb
author_rank: Super Contributor
timestamp: June 09, 2024, 03:04:59 pm
content: 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.

author: djsb
author_rank: Super Contributor
timestamp: June 10, 2024, 01:17:47 pm
content: I've found this topic on the Microchip forum started by PStech_Paulhttps://forum.microchip.com/s/topic/a5C3l000000MYXxEAO/t362857I'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.

author: amwales
author_rank: Regular Contributor
timestamp: June 10, 2024, 03:30:31 pm
content: 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 yourpickit5 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

author: amwales
author_rank: Regular Contributor
timestamp: June 10, 2024, 03:43:00 pm
content: A little googling and I found thesehttps://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.

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 13, 2024, 08:41:10 pm
content: Basic & simple I2C library for PIC:https://www.eevblog.com/forum/microcontrollers/does-everyone-seriously-write-their-own-i2c-library-for-pic-mcus/msg4021135/#msg4021135