hello everyone i have a problem with running the LCD.. I have been banging my head for a long time and i will need some help :/ .. i will post my Header, code and library
------------------------------------------------------HEADER ----------------------------------------------------------------------
----------------------------------------------- MAIN -----------------------------------------
----------------------------------------------- XLCD.H (LIBRARY) ----------------------------------
please if you have any ideas share them! Thanks in advance. I will be following the thread so i can answer any question you might have for me!
-------------------------------------------------------------------------------------------------------------------
------------------------------------------------------HEADER ----------------------------------------------------------------------
Code:
/*
* File: Header.h
* Author: knn
*
* Created on 11. februar 2015, 22:07
*/
#ifndef HEADER_H
#define HEADER_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* HEADER_H */
// PIC18F45K22 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.
// CONFIG1H
#pragma config FOSC = INTIO7 // INTIO7 works XT is giving problems....Oscillator Selection bits (XT oscillator)
#pragma config PLLCFG = ON // 4X PLL Enable (Oscillator multiplied by 4)
#pragma config PRICLKEN = ON // Primary clock enable bit (Primary clock is always enabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
// CONFIG2L
#pragma config PWRTEN = OFF // Power-up Timer Enable bit (Power up timer disabled)
#pragma config BOREN = SBORDIS // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 190 // Brown Out Reset Voltage bits (VBOR set to 1.90 V nominal)
// CONFIG2H
#pragma config WDTEN = OFF // Watchdog Timer Enable bits (Watch dog timer is always disabled. SWDTEN has no effect.)
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
// CONFIG3H
#pragma config CCP2MX = PORTC1 // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = ON // PORTB A/D Enable bit (PORTB<5:0> pins are configured as analog input channels on Reset)
#pragma config CCP3MX = PORTB5 // P3A/CCP3 Mux bit (P3A/CCP3 input/output is multiplexed with RB5)
#pragma config HFOFST = ON // HFINTOSC Fast Start-up (HFINTOSC output and ready status are not delayed by the oscillator stable status)
#pragma config T3CMX = PORTC0 // Timer3 Clock input mux bit (T3CKI is on RC0)
#pragma config P2BMX = PORTD2 // ECCP2 B output mux bit (P2B is on RD2)
#pragma config MCLRE = INTMCLR // Was EXTMCLR MCLR Pin Enable bit (MCLR pin enabled, RE3 input pin disabled)
// CONFIG4L
#pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled if MCLRE is also 1)
#pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
// CONFIG5L
#pragma config CP0 = OFF // Code Protection Block 0 (Block 0 (000800-001FFFh) not code-protected)
#pragma config CP1 = OFF // Code Protection Block 1 (Block 1 (002000-003FFFh) not code-protected)
#pragma config CP2 = OFF // Code Protection Block 2 (Block 2 (004000-005FFFh) not code-protected)
#pragma config CP3 = OFF // Code Protection Block 3 (Block 3 (006000-007FFFh) not code-protected)
// CONFIG5H
#pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
// CONFIG6L
#pragma config WRT0 = OFF // Write Protection Block 0 (Block 0 (000800-001FFFh) not write-protected)
#pragma config WRT1 = OFF // Write Protection Block 1 (Block 1 (002000-003FFFh) not write-protected)
#pragma config WRT2 = OFF // Write Protection Block 2 (Block 2 (004000-005FFFh) not write-protected)
#pragma config WRT3 = OFF // Write Protection Block 3 (Block 3 (006000-007FFFh) not write-protected)
// CONFIG6H
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
// CONFIG7L
#pragma config EBTR0 = OFF // Table Read Protection Block 0 (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection Block 1 (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF // Table Read Protection Block 2 (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF // Table Read Protection Block 3 (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)
// CONFIG7H
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)
----------------------------------------------- MAIN -----------------------------------------
Code:
///*
// * File: main.c
// * Author: Platinum
// *
// * Created on March 17, 2015, 10:41 AM
// */
#include "Header.h"
#include <xlcd.h>
#include <stdio.h>
#include <stdlib.h>
#include <delays.h>
#include <xc.h>
#define _XTAL_FREQ 8000000
void init_XLCD(void); //Initialize LCD display
void DelayFor18TCY(void) { // dalay for 20 TCY
//Delay10TCYx(2);
__delay_us(39);
}
void DelayPORXLCD(){ // delay for 15 ms
__delay_ms(15);//
}
void DelayXLCD(){ // delay for 5 ms
__delay_ms(5);//
}
void main(void)
{
init_XLCD(); //Call the Initialize LCD display function
while(1)
{
putrsXLCD("Hello World"); //Display "Hello World"
SetDDRamAddr(0x40); //shift cursor to beginning of second line
putrsXLCD("LCD Display"); //Display "LCD display"
}
}
void init_XLCD(void) //Initialize LCD display
{ PORTBbits.RB4=1;
PORTBbits.RB6=1;
OpenXLCD(FOUR_BIT&LINES_5X7); //configure LCD in 4-bit Data Interface mode
//and 5x7 characters, multiple line display
while(BusyXLCD()); //Check if the LCD controller is not busy
//before writing some commands?
WriteCmdXLCD(0x06); // move cursor right, don?t shift display
WriteCmdXLCD(0x0C); //turn display on without cursor
}
Code:
#ifndef __XLCD_H
#define __XLCD_H
#include "p18cxxx.h"
/* PIC18 XLCD peripheral routines.
*
* Notes:
* - These libraries routines are written to support the
* Hitachi HD44780 LCD controller.
* - The user must define the following items:
* - The LCD interface type (4- or 8-bits)
* - If 4-bit mode
* - whether using the upper or lower nibble
* - The data port
* - The tris register for data port
* - The control signal ports and pins
* - The control signal port tris and pins
* - The user must provide three delay routines:
* - DelayFor18TCY() provides a 18 Tcy delay
* - DelayPORXLCD() provides at least 15ms delay
* - DelayXLCD() provides at least 5ms delay
*/
/* Interface type 8-bit or 4-bit
* For 8-bit operation uncomment the #define BIT8
*/
/* #define BIT8 */
/* When in 4-bit interface define if the data is in the upper
* or lower nibble. For lower nibble, comment the #define UPPER
*/
/* #define UPPER */
/* DATA_PORT defines the port to which the LCD data lines are connected */
#define DATA_PORT PORTB
#define TRIS_DATA_PORT TRISB
/* CTRL_PORT defines the port where the control lines are connected.
* These are just samples, change to match your application.
*/
#define RW_PIN LATBbits.LATB5 /* PORT for RW */
#define TRIS_RW TRISBbits.TRISB5 /* TRIS for RW */
#define RS_PIN LATBbits.LATB4 /* PORT for RS */
#define TRIS_RS TRISBbits.TRISB4 /* TRIS for RS */
#define E_PIN LATBbits.LATB6 /* PORT for D */
#define TRIS_E TRISBbits.TRISB6 /* TRIS for E */
/* Display ON/OFF Control defines */
#define DON 0b00001111 /* Display on */
#define DOFF 0b00001011 /* Display off */
#define CURSOR_ON 0b00001111 /* Cursor on */
#define CURSOR_OFF 0b00001101 /* Cursor off */
#define BLINK_ON 0b00001111 /* Cursor Blink */
#define BLINK_OFF 0b00001110 /* Cursor No Blink */
/* Cursor or Display Shift defines */
#define SHIFT_CUR_LEFT 0b00000100 /* Cursor shifts to the left */
#define SHIFT_CUR_RIGHT 0b00000101 /* Cursor shifts to the right */
#define SHIFT_DISP_LEFT 0b00000110 /* Display shifts to the left */
#define SHIFT_DISP_RIGHT 0b00000111 /* Display shifts to the right */
/* Function Set defines */
#define FOUR_BIT 0b00101100 /* 4-bit Interface */
#define EIGHT_BIT 0b00111100 /* 8-bit Interface */
#define LINE_5X7 0b00110000 /* 5x7 characters, single line */
#define LINE_5X10 0b00110100 /* 5x10 characters */
#define LINES_5X7 0b00111000 /* 5x7 characters, multiple line */
#ifdef _OMNI_CODE_
#define PARAM_SCLASS
#else
#define PARAM_SCLASS auto
#endif
#ifndef MEM_MODEL
#ifdef _OMNI_CODE_
#define MEM_MODEL
#else
#define MEM_MODEL far /* Change this to near for small memory model */
#endif
#endif
/* OpenXLCD
* Configures I/O pins for external LCD
*/
void OpenXLCD(PARAM_SCLASS unsigned char);
/* SetCGRamAddr
* Sets the character generator address
*/
void SetCGRamAddr(PARAM_SCLASS unsigned char);
/* SetDDRamAddr
* Sets the display data address
*/
void SetDDRamAddr(PARAM_SCLASS unsigned char);
/* BusyXLCD
* Returns the busy status of the LCD
*/
unsigned char BusyXLCD(void);
/* ReadAddrXLCD
* Reads the current address
*/
unsigned char ReadAddrXLCD(void);
/* ReadDataXLCD
* Reads a byte of data
*/
char ReadDataXLCD(void);
/* WriteCmdXLCD
* Writes a command to the LCD
*/
void WriteCmdXLCD(PARAM_SCLASS unsigned char);
/* WriteDataXLCD
* Writes a data byte to the LCD
*/
void WriteDataXLCD(PARAM_SCLASS char);
/* putcXLCD
* A putc is a write
*/
#define putcXLCD WriteDataXLCD
/* putsXLCD
* Writes a string of characters to the LCD
*/
void putsXLCD(PARAM_SCLASS char *);
/* putrsXLCD
* Writes a string of characters in ROM to the LCD
*/
void putrsXLCD(const char *);
/* User defines these routines according to the oscillator frequency */
extern void DelayFor18TCY(void);
extern void DelayPORXLCD(void);
extern void DelayXLCD(void);
#endif
-------------------------------------------------------------------------------------------------------------------