I think the D_I is the same as the RS pin but this is one of the things that has me confused.4-bit Initialization:
/**********************************************************/
void command(char i)
{
P1 = i; //put data on output Port
D_I =0; //D/I=LOW : send instruction
R_W =0; //R/W=LOW : Write
Nybble(); //Send lower 4 bits
i = i<<4; //Shift over by 4 bits
P1 = i; //put data on output Port
Nybble(); //Send upper 4 bits
}
/**********************************************************/
void write(char i)
{
P1 = i; //put data on output Port
D_I =1; //D/I=HIGH : send data
R_W =0; //R/W=LOW : Write
Nybble(); //Clock lower 4 bits
i = i<<4; //Shift over by 4 bits
P1 = i; //put data on output Port
Nybble(); //Clock upper 4 bits
}
/**********************************************************/
void Nybble()
{
E = 1;
Delay(1); //enable pulse width >= 300ns
E = 0; //Clock enable: falling edge
}
/**********************************************************/
void init()
{
P1 = 0;
P3 = 0;
Delay(100); //Wait >15 msec after power is applied
P1 = 0x30; //put 0x30 on the output port
Delay(30); //must wait 5ms, busy flag not available
Nybble(); //command 0x30 = Wake up
Delay(10); //must wait 160us, busy flag not available
Nybble(); //command 0x30 = Wake up #2
Delay(10); //must wait 160us, busy flag not available
Nybble(); //command 0x30 = Wake up #3
Delay(10); //can check busy flag now instead of delay
P1= 0x20; //put 0x20 on the output port
Nybble(); //Function set: 4-bit interface
command(0x28); //Function set: 4-bit/2-line
command(0x10); //Set cursor
command(0x0F); //Display ON; Blinking cursor
command(0x06); //Entry Mode set
}
[11]
/**********************************************************/
#include <p18f4550.h>
#include <delays.h>
#pragma config PLLDIV = 5 // (20 MHz crystal on PICDEM FS USB board)
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2 // Clock source from 96MHz PLL/2
#pragma config FOSC = HSPLL_HS
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOR = ON
#pragma config BORV = 3
#pragma config VREGEN = ON //USB Voltage Regulator
#pragma config WDT = OFF
#pragma config WDTPS = 32768
#pragma config MCLRE = ON
#pragma config LPT1OSC = OFF
#pragma config PBADEN = OFF
// #pragma config CCP2MX = ON
#pragma config STVREN = ON
#pragma config LVP = OFF
// #pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming
#pragma config XINST = OFF // Extended Instruction Set
#pragma config CP0 = OFF
#pragma config CP1 = OFF
// #pragma config CP2 = OFF
// #pragma config CP3 = OFF
#pragma config CPB = OFF
// #pragma config CPD = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
// #pragma config WRT2 = OFF
// #pragma config WRT3 = OFF
#pragma config WRTB = OFF // Boot Block Write Protection
#pragma config WRTC = OFF
// #pragma config WRTD = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
// #pragma config EBTR2 = OFF
// #pragma config EBTR3 = OFF
#pragma config EBTRB = OFF
#define CLOCK_FREQ 48000000
#define LCD_E LATBbits.LATB2
#define LCD_RS LATBbits.LATB0
#define LCD_RW LATBbits.LATB1
#define LCD_Data LATAbits.LATA0
char const text1[] = {"Newhaven Display"};
char const text2[] = {"Character LCD "};
//
/** D E C L A R A T I O N S *******************************************/
#pragma code // declare executable instructions
void Delayms(int n);
void command(char i);
void write(char i);
void init(void);
void home(void);
void nextline(void);
void disp_pic(void);
void main(void) {
TRISA = 0b00000000;
TRISB = 0b00000000;
//P1=0;
//P3=0;
while(1){
init();
disp_pic();
Delayms(1000);
}
}
void Delayms(int n){
int i;
int j;
j = n * 12;
Delay1KTCYx(j);
// for (i=0;i<n;i++)
// for (j=0;j<12000;j++)
// {;}
}
void command(char i){
LCD_Data = i;
LCD_RS = 0; //3_0
LCD_RW = 0; //3_7
LCD_E = 1; //3_4
Delayms(1);
LCD_E = 0;//3_4
}
void write(char i){
LCD_Data = i;
LCD_RS =1;
LCD_RW =0;
LCD_E = 1;
Delayms(1);
LCD_E = 0;
}
void init(){
LCD_E = 0;
Delayms(5);
command(0x30);
Delayms(100);
command(0x30);
Delayms(10);
command(0x30);
Delayms(10);
command(0x38);
command(0x10);
command(0x0c);
command(0x06);
}
void home(){
command(0x01);
Delayms(5);
}
void nextline(){
command(0xc0);
}
void disp_pic(){
int i;
home();
for (i=0;i<16;i++){
write(text1);
}
nextline();
for (i=0;i<16;i++){
write(text2);
}
}
#include <p18f4550.h>
#include <delays.h>
#pragma config PLLDIV = 5 // (20 MHz crystal on PICDEM FS USB board)
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2 // Clock source from 96MHz PLL/2
#pragma config FOSC = HSPLL_HS
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOR = ON
#pragma config BORV = 3
#pragma config VREGEN = ON //USB Voltage Regulator
#pragma config WDT = OFF
#pragma config WDTPS = 32768
#pragma config MCLRE = ON
#pragma config LPT1OSC = OFF
#pragma config PBADEN = OFF
// #pragma config CCP2MX = ON
#pragma config STVREN = ON
#pragma config LVP = OFF
// #pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming
#pragma config XINST = OFF // Extended Instruction Set
#pragma config CP0 = OFF
#pragma config CP1 = OFF
// #pragma config CP2 = OFF
// #pragma config CP3 = OFF
#pragma config CPB = OFF
// #pragma config CPD = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
// #pragma config WRT2 = OFF
// #pragma config WRT3 = OFF
#pragma config WRTB = OFF // Boot Block Write Protection
#pragma config WRTC = OFF
// #pragma config WRTD = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
// #pragma config EBTR2 = OFF
// #pragma config EBTR3 = OFF
#pragma config EBTRB = OFF
#define CLOCK_FREQ 48000000
#define LCD_E LATBbits.LATB2
#define LCD_RS LATBbits.LATB0
#define LCD_RW LATBbits.LATB1
#define LCD_Data PORTA
char const text1[] = {"Newhaven Display"};
char const text2[] = {"Character LCD "};
//
/** D E C L A R A T I O N S *******************************************/
#pragma code // declare executable instructions
void Delayms(int n);
void command(char i);
void write(char i);
void init(void);
void home(void);
void nextline(void);
void disp_pic(void);
void Nybble(void);
void main(void) {
ADCON1 = 0;
TRISA = 0b00000000;
TRISB = 0b00000000;
//P1=0;
//P3=0;
Delay10KTCYx(200);
while(1){
init();
disp_pic();
Delayms(1000);
}
}
void Delayms(int n){
// int i;
int j;
j = n * 12;
Delay1KTCYx(j);
// for (i=0;i<n;i++)
// for (j=0;j<12000;j++)
// {;}
}
void command(char i){
LCD_Data = i;
LCD_RS = 0; //3_0
LCD_RW = 0; //3_7
Nybble();
PORTA = PORTA << 4;
LCD_Data = i;
Nybble();
}
void write(char i){
LCD_Data = i;
LCD_RS =1;
LCD_RW =0;
Nybble();
PORTA = PORTA << 4;
LCD_Data = i;
Nybble();
}
void Nybble(){
LCD_E = 1;
Delayms(5);
LCD_E = 0;
}
void init(){
LCD_Data = 0;
LCD_RS = 0;
Delayms(100);
LCD_Data = 0x30;
Delayms(30);
Nybble();
Delayms(10);
Nybble();
Delayms(10);
Nybble();
Delayms(10);
LCD_Data = 0x20;
Nybble();
command(0x28);
command(0x10);
command(0x0F);
command(0x06);
}
void home(){
command(0x02);
Delayms(5);
}
void nextline(){
command(0xc0);
}
void disp_pic(){
int i;
command(0x01);
home();
for (i=0;i<16;i++){
write(text1);
}
// nextline();
// for (i=0;i<16;i++){
// write(text2);
// }
// write(0x48);
// write(0x25);
}
void command(char i){
LCD_Data = i[COLOR="red"]>>4[/COLOR];
LCD_RS = 0; //3_0
LCD_RW = 0; //3_7
Nybble();
[COLOR="red"]LCD_Data = i[/COLOR];
Nybble();
}
void write(char i){
LCD_Data = i[COLOR="red"]>>4[/COLOR];
LCD_RS =1;
LCD_RW =0;
Nybble();
[COLOR="red"]LCD_Data = i[/COLOR];
Nybble();
}
void main(void) {
ADCON1 = [COLOR="red"]0x0f[/COLOR];
TRISA = 0b00000000;
TRISB = 0b00000000;
//P1=0;
//P3=0;
Delay10KTCYx(200);
while(1){
init();
disp_pic();
Delayms(1000);
}
}
void command(char i){
char j;
j = i;
i = i >> 4;
LCD_Data = i;
LCD_RS = 0;
LCD_RW = 0;
Nybble();
LCD_Data = j;
Nybble();
}
void write(char i){
char j;
j = i;
i = i >> 4;
LCD_Data = i;
LCD_RS = 1;
LCD_RW = 0;
Nybble();
LCD_Data = j;
Nybble();
LCD_RS = 0;
}
void init(){
LCD_Data = 0;
LCD_RS = 0;
Delayms(30);
LCD_Data = 0x03;
Delayms(10);
Nybble();
Delayms(10);
Nybble();
Delayms(10);
Nybble();
Delayms(10);
LCD_Data = 0x02;
Nybble();
command(0x28);
command(0x10);
command(0x0C);
command(0x06);
command(0x01);
Delayms(100);
}
#include <p18f4550.h>
#include <delays.h>
#pragma config PLLDIV = 5 // (20 MHz crystal on PICDEM FS USB board)
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2 // Clock source from 96MHz PLL/2
#pragma config FOSC = HSPLL_HS
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOR = ON
#pragma config BORV = 3
#pragma config VREGEN = ON //USB Voltage Regulator
#pragma config WDT = OFF
#pragma config WDTPS = 32768
#pragma config MCLRE = ON
#pragma config LPT1OSC = OFF
#pragma config PBADEN = OFF
// #pragma config CCP2MX = ON
#pragma config STVREN = ON
#pragma config LVP = OFF
// #pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming
#pragma config XINST = OFF // Extended Instruction Set
#pragma config CP0 = OFF
#pragma config CP1 = OFF
// #pragma config CP2 = OFF
// #pragma config CP3 = OFF
#pragma config CPB = OFF
// #pragma config CPD = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
// #pragma config WRT2 = OFF
// #pragma config WRT3 = OFF
#pragma config WRTB = OFF // Boot Block Write Protection
#pragma config WRTC = OFF
// #pragma config WRTD = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
// #pragma config EBTR2 = OFF
// #pragma config EBTR3 = OFF
#pragma config EBTRB = OFF
#define CLOCK_FREQ 48000000
#define LCD_E LATBbits.LATB2
#define LCD_RS LATBbits.LATB0
#define LCD_RW LATBbits.LATB1
#define LCD_Data PORTA
char const text1[] = {"New Haven "};
char const text2[] = {"Character LCD "};
//
/** D E C L A R A T I O N S *******************************************/
#pragma code // declare executable instructions
void Delayms(int n);
void command(char i);
void write(char i);
void init(void);
void home(void);
void nextline(void);
void disp_pic(void);
void Nybble(void);
void main(void) {
ADCON1 = 0x0f;
TRISA = 0b00000000;
TRISB = 0b00000000;
LCD_Data = 0;
LCD_RS = 0;
Delay10KTCYx(1500);
init();
while(1){
home();
disp_pic();
Delayms(2000);
}
}
void Delayms(int n){
// int i;
int j;
j = n * 12;
Delay10KTCYx(j);
}
void command(char i){
char j;
j = i;
i = i >> 4;
LCD_Data = i;
LCD_RS = 0;
LCD_RW = 0;
Nybble();
LCD_Data = j;
Nybble();
}
void write(char i){
char j;
j = i;
i = i >> 4;
LCD_Data = i;
LCD_RS = 1;
LCD_RW = 0;
Nybble();
LCD_Data = j;
Nybble();
LCD_RS = 0;
}
void Nybble(){
LCD_E = 1;
Delayms(1);
LCD_E = 0;
}
void init(){
LCD_Data = 0;
LCD_RS = 0;
Delayms(30);
LCD_Data = 0x03;
Delayms(10);
Nybble();
Delayms(10);
Nybble();
Delayms(10);
Nybble();
Delayms(10);
LCD_Data = 0x02;
Nybble();
command(0x28);
command(0x10);
command(0x0C);
command(0x06);
command(0x01);
Delayms(100);
}
void home(){
command(0x02);
Delayms(5);
}
void nextline(){
command(0xc0);
}
void disp_pic(){
int i;
home();
for (i=0;i<16;i++){
write(text1[i]);
}
nextline();
for (i=0;i<16;i++){
write(text2[i]);
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?