mariuszoll
Member level 5
- Joined
- Aug 28, 2012
- Messages
- 82
- Helped
- 1
- Reputation
- 2
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 2,147
Hi,
I use on my project a PIC18F24J11, and I want to display data on LCD on 4bit mode. I use MPLAB, and the compiler MCC18.
RA5-->RS
RA6-->EN
RC0...RC3--> DB4...DB7
Could you help me please to fix this problem? Below is attached the C code:
//Program
/* LCD 16x2
4 bit mode
RA5--> RS
RA6-->Enable
RC0..RC3 --> DB4...DB7
R/W --> GND
LCD: BT 21605VSS-SRE-HQ from Batron
KS0070_lcd_driver
PIC18F24J11
uC internal clock 4MHz
*/
#include <p18f24j11.h>
#include <delays.h>
#include <string.h>
//#include <xlcd.h>
// Pragma
#pragma config WDTEN = OFF
#pragma config OSC = INTOSC
#pragma config XINST = OFF
#pragma config DSBOREN = OFF
#pragma config RTCOSC = INTOSCREF
//*****************************************************************************
// CONSTANT DEFINITION
//*****************************************************************************
//*****************************************************************************
// Variables
/** L O C A L F U N C T I O N S *******************************************/
void set_hi_nibble(char data) // output hi nibble data on port lines
{
unsigned char temp=PORTC;
temp= temp & 0xF0;
temp= temp | (data>>4);
LATC=temp;
}
void set_lo_nibble(char data) // output low nibble data on port lines
{
unsigned char temp=PORTC;
temp= temp & 0xF0;
temp= temp | (data & 0xF0);
LATC=temp;
}
void en_set(void) //function used to set Enable signal properly
{
LATAbits.LATA6 = 1; // Set EN on 1
Delay1KTCYx(1); // delay 1ms
LATAbits.LATA6 = 0; // Set EN on 0
}
void data(unsigned char c) // function used to write data to LCD
{
LATAbits.LATA5=1; // set RS on 1
set_hi_nibble(c);
en_set();
Delay1KTCYx(50); // delay 50ms
set_lo_nibble(c);
en_set();
Delay1KTCYx(50); // delay 50ms
}
void cmd(unsigned char c) // function used to send commands to LCD
{
LATAbits.LATA5=0; // set RS on 0
set_hi_nibble(c);
en_set();
Delay1KTCYx(50); // delay 50ms
set_lo_nibble(c);
en_set();
Delay1KTCYx(50); // delay 50ms
}
void LCDInit(void)
{
Delay10KTCYx(20); // delay 200ms
TRISCbits.TRISC0=0; //RC0 output, DB4
TRISCbits.TRISC1=0; //RC1 output, DB5
TRISCbits.TRISC2=0; //RC2 output, DB6
TRISCbits.TRISC3=0; //RC3 output, DB7
TRISAbits.TRISA5=0; //RA5 output, RS
TRISAbits.TRISA6=0; //RA6 output, EN
// Oscillator frequency
OSCCON=0b01100000; // 4MHz
// pins configurred as digital
ANCON0=0b11111111;
ANCON1=0b00011111;
LATAbits.LATA6=0; // Set EN on 0
Delay1KTCYx(100); // Delay 100ms
LATAbits.LATA5=0; // Set RS on 0
Delay1KTCYx(15); // delay 15ms
LATC=0x2;
en_set();
Delay1KTCYx(5); // delay 5ms
en_set();
Delay100TCYx(1); // delay 100us
en_set();
Delay1KTCYx(5); // delay 5ms
LATC=0x2;
en_set();
Delay10TCYx(4); // delay 40us
//Function set
cmd(0x28); // 4 bits, 2 lines, 5x7 dots format display mode
Delay10TCYx(4); // delay 40us
//Display ON control
cmd(0x0E); // display on, cursor on, blinking cursor position off
Delay10TCYx(4); // delay 40us
//Clear Display
cmd(0x01); // dispaly clear
Delay1KTCYx(2); // delay 2ms
//Entry set increment
cmd(0x07); // increment, display shift to left
Delay100TCYx(10); // delay 1ms
}
///////////////////main function///////////////////////////////////////////
void main()
{
LCDInit();
data('A');
while(1);
}//main
Thank you in advance.
I use on my project a PIC18F24J11, and I want to display data on LCD on 4bit mode. I use MPLAB, and the compiler MCC18.
RA5-->RS
RA6-->EN
RC0...RC3--> DB4...DB7
Could you help me please to fix this problem? Below is attached the C code:
//Program
/* LCD 16x2
4 bit mode
RA5--> RS
RA6-->Enable
RC0..RC3 --> DB4...DB7
R/W --> GND
LCD: BT 21605VSS-SRE-HQ from Batron
KS0070_lcd_driver
PIC18F24J11
uC internal clock 4MHz
*/
#include <p18f24j11.h>
#include <delays.h>
#include <string.h>
//#include <xlcd.h>
// Pragma
#pragma config WDTEN = OFF
#pragma config OSC = INTOSC
#pragma config XINST = OFF
#pragma config DSBOREN = OFF
#pragma config RTCOSC = INTOSCREF
//*****************************************************************************
// CONSTANT DEFINITION
//*****************************************************************************
//*****************************************************************************
// Variables
/** L O C A L F U N C T I O N S *******************************************/
void set_hi_nibble(char data) // output hi nibble data on port lines
{
unsigned char temp=PORTC;
temp= temp & 0xF0;
temp= temp | (data>>4);
LATC=temp;
}
void set_lo_nibble(char data) // output low nibble data on port lines
{
unsigned char temp=PORTC;
temp= temp & 0xF0;
temp= temp | (data & 0xF0);
LATC=temp;
}
void en_set(void) //function used to set Enable signal properly
{
LATAbits.LATA6 = 1; // Set EN on 1
Delay1KTCYx(1); // delay 1ms
LATAbits.LATA6 = 0; // Set EN on 0
}
void data(unsigned char c) // function used to write data to LCD
{
LATAbits.LATA5=1; // set RS on 1
set_hi_nibble(c);
en_set();
Delay1KTCYx(50); // delay 50ms
set_lo_nibble(c);
en_set();
Delay1KTCYx(50); // delay 50ms
}
void cmd(unsigned char c) // function used to send commands to LCD
{
LATAbits.LATA5=0; // set RS on 0
set_hi_nibble(c);
en_set();
Delay1KTCYx(50); // delay 50ms
set_lo_nibble(c);
en_set();
Delay1KTCYx(50); // delay 50ms
}
void LCDInit(void)
{
Delay10KTCYx(20); // delay 200ms
TRISCbits.TRISC0=0; //RC0 output, DB4
TRISCbits.TRISC1=0; //RC1 output, DB5
TRISCbits.TRISC2=0; //RC2 output, DB6
TRISCbits.TRISC3=0; //RC3 output, DB7
TRISAbits.TRISA5=0; //RA5 output, RS
TRISAbits.TRISA6=0; //RA6 output, EN
// Oscillator frequency
OSCCON=0b01100000; // 4MHz
// pins configurred as digital
ANCON0=0b11111111;
ANCON1=0b00011111;
LATAbits.LATA6=0; // Set EN on 0
Delay1KTCYx(100); // Delay 100ms
LATAbits.LATA5=0; // Set RS on 0
Delay1KTCYx(15); // delay 15ms
LATC=0x2;
en_set();
Delay1KTCYx(5); // delay 5ms
en_set();
Delay100TCYx(1); // delay 100us
en_set();
Delay1KTCYx(5); // delay 5ms
LATC=0x2;
en_set();
Delay10TCYx(4); // delay 40us
//Function set
cmd(0x28); // 4 bits, 2 lines, 5x7 dots format display mode
Delay10TCYx(4); // delay 40us
//Display ON control
cmd(0x0E); // display on, cursor on, blinking cursor position off
Delay10TCYx(4); // delay 40us
//Clear Display
cmd(0x01); // dispaly clear
Delay1KTCYx(2); // delay 2ms
//Entry set increment
cmd(0x07); // increment, display shift to left
Delay100TCYx(10); // delay 1ms
}
///////////////////main function///////////////////////////////////////////
void main()
{
LCDInit();
data('A');
while(1);
}//main
Thank you in advance.