/*******************************************************************
* Expérimentation de communication bi-directionnelle via RS232 *
* connexion entre un PC un PIC avec LCD *
* - PIC16F876A Mikroc PRO - *
* Configuration des fusibles par defaut *
* Juillet 2010 FB Aka Hearty *
*******************************************************************/
unsigned char Lecture_UART1;
unsigned char temp;
// Configuration des ports sur le LCD
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D4 at RB4_bit;
// Orientation des ports
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB7_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB4_bit;
void main() {
ADCON1 = 0x07; // PORTS en mode digital
Delay_ms(100);
temp = 0;
Lcd_Init(); //Initialiser le LCD
Lcd_Cmd(_LCD_CLEAR); // Effacer l'écran
Lcd_Cmd(_LCD_CURSOR_OFF); // Cacher le curseur
Lcd_Out(1,2, "Caractere: "); //Afficher le message
Delay_ms(1000); //Pause de 1 seconde
UART1_Init(9600); //Configuration RS232 - 9600bds,
Delay_ms(100); // Petite pause pour établir la communication
UART1_Write_Text("Connexion établie"); // envoyer le texte vers UART
UART1_Write(13); //retour charriot (Carriage return)
UART1_Write(10); // Curseur en début de ligne (Line feed)
do {
if (UART1_Data_Ready() == 1) { //Si la connexion est effectuée
Lecture_UART1 = UART1_Read(); //Données reçues via UART
UART1_Write(Lecture_UART1); //Renvoyer les données reçus pour confirmation
temp = Lecture_UART1; // variable tampon
}//fin If
Delay_ms(100);
Lcd_Chr(1,13, temp); // afficher sur le LCD le caractère reçu via UART
}while(1); // Boucler le "do"
} //Fin main