Last active
December 8, 2018 11:47
Contrôle d'un afficheur LCD avec le MPLAB Xpress Evaluation Board
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************** | |
Contrôle d'un afficheur LCD avec le MPLAB Xpress Evaluation Board | |
Instructions complètes: | |
http://electroniqueamateur.blogspot.com/2018/10/afficheur-cristaux-liquide-lcd-et-mplab.html | |
*******************************************************************/ | |
#include "mcc_generated_files/mcc.h" // fichiers générés par MCC | |
#include "stdio.h" // pour l'utilisation de sprintf | |
unsigned int compteur = 0; | |
void envoie_commande(unsigned char commande) // utilisé pour envoyer une instruction à l'afficheur | |
{ | |
RB0=0; // RS (Register Select) à 0 | |
RB1=0; // RW (Read or write) à 0 | |
RB2=1; // E (Enable) à 1 | |
PORTC = commande; // Les broches D0 à D7 de l'afficheur réglées | |
// à la valeur correspondant à l'instruction voulue | |
__delay_ms(50); // délai | |
RB2=0; // E (Enable) à 0 | |
} | |
void affiche_caractere (unsigned char caract) // utilisé pour envoyer un caractère à afficher | |
{ | |
RB0=1; // RS (Register Select) à 1 | |
RB1=0; // RW (Read or write) à 0 | |
RB2=1; // E (Enable) à 1 | |
PORTC = caract; // Les broches D0 à D7 de l'afficheur réglées | |
// à la valeur correspondant au caractère voulu | |
__delay_ms(1); | |
RB2=0; // E (Enable) à 0 | |
} | |
void gestion_string (unsigned char* position) // affiche tous les caractère d'une chaîne | |
{ | |
while(*position != '\0') // jusqu'à ce qu'on soit arrivé à la fin de la chaîne de caractère | |
{ | |
affiche_caractere(*position); // on affiche le caractère | |
position++; // on passe au caractère suivant | |
} | |
} | |
void initialisation_LCD(void) // initialisation de l'afficheur | |
{ | |
__delay_ms(100); // délai | |
envoie_commande(0x38); //Mode 8 bits, 2 lighes | |
envoie_commande(0x01); // On efface le contenu de l'afficheur | |
envoie_commande(0x0E); | |
//envoie_commande(0x80); // Curseur placé au début de la première ligne | |
} | |
void main (void) | |
{ | |
SYSTEM_Initialize(); | |
initialisation_LCD(); | |
while (1) | |
{ | |
char data[16]; // contiendra la valeur du compteur en string | |
envoie_commande(0x80); // Curseur au début de la première ligne | |
gestion_string("ELECTRONIQUE"); | |
envoie_commande(0xC0); // curseur au début de la deuxième ligne | |
gestion_string("EN AMATEUR "); | |
sprintf(data, "%d", compteur); // conversion de la valeur du compteur en string | |
gestion_string(data); // affichage de la valeur du compteur | |
if (compteur <= 100){ | |
compteur++; | |
} | |
else { | |
compteur = 0; // on remet le compteur à zéro | |
envoie_commande(0x01); // 0x01 est la commande pour tout effacer sur le LCD. | |
} | |
__delay_ms(1000); // on attend une seconde avant de changer la valeur du compteur | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment