Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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;
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top