rahulmr
Junior Member level 1
- Joined
- Feb 21, 2007
- Messages
- 16
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Activity points
- 1,434
Hi all,
I am having a PIC18f4680 with which I am trying to write on LCD. I am using the xLCD library and has just modified the portB to PORTD. Created a new header xLCDMod.h and copied all the XLCD.h contents to that and modified the port to PORTD. Also added copy of all the *.c files of the XLCD in the project and made the reference to xLCDMod.h and compiled.
Now that I am not able to make the LCD display the actual items that I am writing to. I am sure that the PORT change is not causing the issue as some characters are shown and is kind of scrambled and displayed in some random orders. Sometimes only 1 character is shown. I tried out many config setting but nothing worked. I am using a PIC dev board, with 20 MHz crystal.
I am not able to fully understand whether these issues are because of the crystal config or not. Can someone please help me . I am posting the code .
I have removed the config bits for now and just kept only 3 . What all config bits to be set just for the LCD ?
I am having a PIC18f4680 with which I am trying to write on LCD. I am using the xLCD library and has just modified the portB to PORTD. Created a new header xLCDMod.h and copied all the XLCD.h contents to that and modified the port to PORTD. Also added copy of all the *.c files of the XLCD in the project and made the reference to xLCDMod.h and compiled.
Now that I am not able to make the LCD display the actual items that I am writing to. I am sure that the PORT change is not causing the issue as some characters are shown and is kind of scrambled and displayed in some random orders. Sometimes only 1 character is shown. I tried out many config setting but nothing worked. I am using a PIC dev board, with 20 MHz crystal.
I am not able to fully understand whether these issues are because of the crystal config or not. Can someone please help me . I am posting the code .
I have removed the config bits for now and just kept only 3 . What all config bits to be set just for the LCD ?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<delays.h>
#include "XLCDMod.h"// XLCD header customized for PORTD
// PIC18F4680 Configuration Bit Settings
// 'C' source line config statements
#include <xc.h>
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG1H
#pragma config OSC = HS // Oscillator Selection bits (HS oscillator)
#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 PWRT = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = BOHW // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3 // Brown-out Reset Voltage bits (VBOR set to 2.1V)
// CONFIG2H
#pragma config WDT = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
// CONFIG3H
#pragma config PBADEN = ON // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
#pragma config LPT1OSC = OFF // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON // 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 = ON // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
#pragma config BBSIZ = 1024 // Boot Block Size Select bits (1K words (2K bytes) Boot Block)
#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 bit (Block 0 (000800-003FFFh) not code-protected)
#pragma config CP1 = OFF // Code Protection bit (Block 1 (004000-007FFFh) not code-protected)
#pragma config CP2 = OFF // Code Protection bit (Block 2 (008000-00BFFFh) not code-protected)
#pragma config CP3 = OFF // Code Protection bit (Block 3 (00C000-00FFFFh) 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 bit (Block 0 (000800-003FFFh) not write-protected)
#pragma config WRT1 = OFF // Write Protection bit (Block 1 (004000-007FFFh) not write-protected)
#pragma config WRT2 = OFF // Write Protection bit (Block 2 (008000-00BFFFh) not write-protected)
#pragma config WRT3 = OFF // Write Protection bit (Block 3 (00C000-00FFFFh) 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 bit (Block 0 (000800-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (004000-007FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (00C000-00FFFFh) 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)
#define _XTAL_FREQ=20000000
void init_XLCD();
void DelayFor18TCY();
void DelayPORXLCD();
void DelayXLCD();
void main() {
init_XLCD();
while (BusyXLCD());
SetDDRamAddr(0x00);
putsXLCD("123456777");
while (1) {
}
}
void init_XLCD() {
OpenXLCD(FOUR_BIT & LINES_5X7);
while (BusyXLCD());
WriteCmdXLCD(0x06);
while (BusyXLCD());
WriteCmdXLCD(0x0C);
}
void DelayFor18TCY() {
//Delay10TCYx(2);
//return;
Nop();Nop();Nop();Nop();
Nop();Nop();Nop();Nop();
Nop();Nop();
return;
}
void DelayPORXLCD() {
Delay1KTCYx(75); // Delay of 15ms
// Cycles = (TimeDelay * Fosc) / 4
// Cycles = (15ms * 20MHz) / 4
// Cycles = 75,000
return;
}
void DelayXLCD() {
Delay1KTCYx(25); // Delay of 5ms
// Cycles = (TimeDelay * Fosc) / 4
// Cycles = (5ms * 20MHz) / 4
// Cycles = 25,000
return;
}