PIC DEM plus 2 LCD interfacing with pic18f4520

Status
Not open for further replies.

sam217

Newbie level 3
Joined
Jun 27, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,315
Hi,

I am a beginner and new to embedded.started using pic dem plus 2 having pic18f4520.i need a source code in c for ocular om16214 lcd interfacing(16X2,4 bit mode).plz help me out.thx
 

Hi,

This sample of code is for an 8 bits interface.
You just need to change the initialization sequence and send two times the data. (one quarter and another)
Sorry i have problems with files attachements.
Hope it helps you.
Regards
JoseMiguel

#include <p18f4550.h>
#include <usart.h> // Prototypes de l'interface série
#include <stdio.h> // Prototypes des fonctions d'entrée-sortie

#define LCD PORTD // Registre de donnée de l'afficheur
#define RS PORTAbits.RA0 // Cmd/data sur Afficheur
#define E PORTAbits.RA1 // Clock sur Afficheur


void Ports_Init (void);
void Usart_Init (void);
void LCD_Init (void);
void LCD_Cmd (char);
void sendChar(char);
void sendStr(const char*);
void Delayus(int);
void Delayms(int);


/* Sortie d'une commande */
/*************************/
void LCD_Cmd(char Cmd)
{ RS=0;
E=1;
LCD=Cmd;
D2=1;
E=0;
LCD=0x00;
RS=1;
}



void sendStr(const char* pStr)
{
char c='\0';
while(*pStr != '\0')
{
c = *pStr;
pStr++;

sendChar(c);
Delayus(1);
}

}

//================
// Sous-programmes
//================

// Initialisation des Ports GPIO
//------------------------------
void Ports_Init (void)
{ LATD = 0x00; TRISD = 0x00; // RDx =sortie > Données de l'afficheur
LATB = 0x07; TRISB = 0x38; // RB0,1,2=Sorties >D1,D2,D3 RB3,4,5=Entrées >Bp1,2,3
ADCON1 = 0x0F;
TRISAbits.TRISA0 = 0;
TRISAbits.TRISA1 = 0;

}


// Initialise de l'USART (port Série RS232)
//-----------------------------------------
void Usart_Init (void)
{ TXSTA=0;
RCSTA=0;
RCSTAbits.SPEN=1;
TRISCbits.TRISC6 = 1;TRISCbits.TRISC7 = 1;

BAUDCONbits.BRG16=1; // Sélectionne vitesse en 16bits
SPBRGH = Bds/256; // BaudRate MSB
SPBRG = Bds-(Bds/256); // BaudRate LSB

TXSTAbits.TXEN=1;
TXSTAbits.BRGH=1;
RCSTAbits.CREN=1;
}


// Initialisation sans Interruptions
//**********************************
void initSIrq (void)
{ PIE1 = 0x00; // Pas d'activation d'interruptions
PIE2 = 0x00;
}


// Delay en µs
//************
void Delayus(int t)
{ int i;
for (i=0;i<t;i++)
{}
}

// Delay en ms
//************
void Delayms(int t)
{ int i;
for (i=0;i<t;i++)
{Delayus(1000);
}
}

//==============================
// Traitement de l'afficheur LCD
//==============================

void LCD_Init(void)
{ LCD_Cmd(0x3C); // 2 Lignes - Display ON
Delayus(50); // attente 50µs
LCD_Cmd(0x0F); // Cuor ON - Blink ON
Delayus(50); // attente 50µs
LCD_Cmd(0x01); // Clear Display
Delayms(2); // Attente 2ms
LCD_Cmd(0x06); // Increment - Shift OFF
Delayms(1); // Attente 1ms
}

/* Sortie d'une donnée */
/***********************/
void sendChar(char Car)
{
RS=1;
E=1;
LCD=Car;
E=0;
RS=0;
D1=1;
Delayus(1);
LCD=0x00;
 

Hey Jose thx a lot
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…