#include <xc.h>
#define _XTAL_FREQ 31250
// PIC16F1459 Configuration Bit Settings
// 'C' source line config statements
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable (PWRT enabled
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR) - PULL UP PIN 4 OR TURN THIS OFF
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover Mode (Internal/External Switchover Mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config CPUDIV = CLKDIV6 // CPU System Clock Selection Bit (CPU system clock divided by 6)
#pragma config USBLSCLK = 48MHz // USB Low SPeed Clock Selection bit (System clock expects 48 MHz, FS/LS USB CLKENs divide-by is set to 8.)
#pragma config PLLMULT = 3x // PLL Multipler Selection Bit (3x Output Frequency Selected)
#pragma config PLLEN = ENABLED // PLL Enable Bit (3x or 4x PLL Enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
//The pins used are same as explained earlier
#define lcd_port LATC // write to LAT, read from PORT
// RC7-4 is the LCD 4 bit databus
#define LCD_RSout LATC2 // moved from ICSP
#define LCD_ENout LATC3
// RC0,RC1 reserved for ICSP DEBUG
//--------------------- STROBE LCD ---------------------------
// Pulses E line on LCD to write
int strobeLCD(void)
{
LCD_ENout = 1;
__delay_us(1);
LCD_ENout = 0;
}
//--------------------- WRITE 8 BIT DATA TO LCD -----------------
// Assumes LCD is ready and RS is set to correct value
// LCD data bus is RC4-RC7
void writeLCD(unsigned char dat)
{
lcd_port &= 0x0f; // get current port, clear upper bits
lcd_port |= (dat & 0xf0); // combine w/upper nibble, leave lower same
strobeLCD();
lcd_port &= 0x0f; // get current port, clear upper bits
lcd_port |= ((dat <<4) & (0xf0)); // combine w/lower nibble, leave lower port same
strobeLCD();
__delay_us(200); // wait for display to process
}
//-------------------- WRITE LCD COMMAND --------------------
// Assumes E is low and display is NOT busy
void lcd_cmd (unsigned char cmd)
{
LCD_RSout = 0; // select command register
writeLCD(cmd);
}
//---------------------- WRITE LCD DATA --------------------------
void lcd_data (unsigned char dat)
{
LCD_RSout = 1; // select data register
writeLCD(dat);
}
//-------------------- RESET/CONFIGURE LCD -------------------------
// Delays are generous, trim when able
void lcd_reset()
{
lcd_port &= 0x0f; // clear upper bits of LCD port
lcd_port |= 0x30; // direct data to LCD DB7-4
LCD_RSout = 0;
strobeLCD(); // write 3h, wait 10ms
__delay_ms(10);
strobeLCD(); // write 3h, wait..
__delay_ms(10);
strobeLCD(); // write 3h
__delay_ms(10);
}
//------------------------ INIT AND CONFIGURE LCD ---------------------
void lcd_init ()
{
lcd_reset(); // LCD reset
lcd_cmd(0x28); // Funciton Set: 4-bit mode - 2 line - 5x7 font.
lcd_cmd(0x0C); // Display no cursor - no blink.
lcd_cmd(0x06); // Automatic Increment - No Display shift.
lcd_cmd(0x80); // Address DDRAM with 0 offset 80h.
}
//======================= MAIN =====================================
void main ()
{
TRISC=0b00000000;
PORTC=0b00000000;
ANSELC=0b00000000;
TRISB=0b00000000;
PORTB=0b00000000;
ANSELB=0b00000000;
TRISA=0b00000000;
PORTA=0b00000000;
ANSELA=0b00000000;
__delay_ms(300); // power up delay for LCD
lcd_init();
lcd_data('H');
lcd_data('E');
lcd_data('L');
lcd_data('L');
lcd_data('O');
while(1); // wait forever
}
// INCLUDES
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = ON // MCLR Pin Function Select bit (MCLR pin function is MCLR)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF // Brown Out Detect (BOR disabled)
#pragma config IESO = ON // Internal External Switchover bit (Internal External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)
// DEFINES
#define _XTAL_FREQ 31250
#define lcd_port TRISC
#define LCD_RSout PORTAbits.RA0
#define LCD_ENout PORTAbits.RA2
//--------------------- STROBE LCD ---------------------------
// Pulses E line on LCD to write
int strobeLCD(void)
{
LCD_ENout = 1;
__delay_us(1);
LCD_ENout = 0;
}
//--------------------- WRITE 8 BIT DATA TO LCD -----------------
// Assumes LCD is ready and RS is set to correct value
// LCD data bus is RC4-RC7
void writeLCD(unsigned char dat)
{
lcd_port &= 0x0f; // get current port, clear upper bits
lcd_port |= (dat & 0xf0); // combine w/upper nibble, leave lower same
strobeLCD();
lcd_port &= 0x0f; // get current port, clear upper bits
lcd_port |= ((dat <<4) & (0xf0)); // combine w/lower nibble, leave lower port same
strobeLCD();
__delay_us(200); // wait for display to process
}
//-------------------- WRITE LCD COMMAND --------------------
// Assumes E is low and display is NOT busy
void lcd_cmd (unsigned char cmd)
{
LCD_RSout = 0; // select command register
writeLCD(cmd);
}
//---------------------- WRITE LCD DATA --------------------------
void lcd_data (unsigned char dat)
{
LCD_RSout = 1; // select data register
writeLCD(dat);
}
//-------------------- RESET/CONFIGURE LCD -------------------------
// Delays are generous, trim when able
void lcd_reset()
{
lcd_port &= 0x0f; // clear upper bits of LCD port
lcd_port |= 0x30; // direct data to LCD DB7-4
LCD_RSout = 0;
strobeLCD(); // write 3h, wait 10ms
__delay_ms(10);
strobeLCD(); // write 3h, wait..
__delay_ms(10);
strobeLCD(); // write 3h
__delay_ms(10);
}
//------------------------ INIT AND CONFIGURE LCD ---------------------
void lcd_init ()
{
lcd_reset(); // LCD reset
lcd_cmd(0x28); // Funciton Set: 4-bit mode - 2 line - 5x7 font.
lcd_cmd(0x0E); // Display cursor - blink.
lcd_cmd(0x06); // Automatic Increment - No Display shift.
lcd_cmd(0x80); // Address DDRAM with 0 offset 80h.
}
//======================= MAIN =====================================
void main ()
{
TRISC=0b00000000;
PORTC=0b00000000;
ANSEL=0b00000000;
//ANSELB=0b00000000;
TRISA=0b00000000;
PORTA=0b00000000;
//ANSELA=0b00000000;
CMCON0 = 0x07;
__delay_ms(300); // power up delay for LCD
lcd_init();
//lcd_data('H');
//lcd_data('E');
//lcd_data('L');
//lcd_data('L');
//lcd_data('O');
while(1); // wait forever
}
Why are you writing the data to the TRISC register and not LATC?#define lcd_port TRISC
This is kind of the basic the PIC needs to have to run. If you have an LED try to connect it and make it blink. I think that has been mentioned earlier in the thread.VDD, VSS and a 10k between VDD and MCLRE