Saturday, February 28, 2015

PIC16F876A RS232 and LCD display



This exercise to practice the communication of μContrôleur and a PC using the RS232 protocol.

PIC confirms the sending and receiving on an LCD display.
I am using for the first time MikroC PRO, which includes some syntactic differences from the old standard MikroC release.

Before going further, I had to put in place the necessary elements to perform the tests. The PC on which I experience and code, is the latest generation and has no / more physical serial port. To overcome this, a solution exists Fortunately, the use of virtual ports generated by the excellent freeware open source named com0com.

A simple google search will help you find the different software used in this exercise, as a precaution I put a copy of the utilities in the download section.





Using this utility is very simple, it offers the possibility to create as many serial port pair as one wishes, and appoint them to our convenience. (a pair is sufficient for the present test). By default the existing pair is named "CNCA0 and CNCB0", simply change on the left figure the pair 0 is renowned COM2 and COM6 replacing in the respective fields their name. Prefer uppercase and no space. If the alternative name is blue, the name is available, if red is that it already exists.



The installation of the software includes drivers who unfortunately are not signed and refuse to install Windows Seven x64 ...
Once again there is a solution, Driver Signature Enforcement Overrider is a small utility that allows to override indicating the operating system to allow the validation of non-signed drivers.
Only a tick "Enable Test Mode" and next.

The installation of this utility requires a system reboot. This being done, com0com can be installed.

This step is not required on previous versions of Windows.





To communicate from PC to PIC, I use a freeware called Terminal, as Hyperterminal as supplied windows, does not seem to exist in Seven. This terminal is complete and functional, it allows as text or binary display, hex and / or decimal. It requires no installation, just launch the executable. All settings are available on the top of the interface, the central area is the reception area, and the lower part is used to enter data to send, with the added ability to send a sequence contained in a text file .





First code to confirm the operation of the various elements.


/*******************************************************************
*                                                                  *
*               professional--information.blogspot.com             *
*                           -  PIC16F876A   -                      *
*                                                                  *
*                                                                  *
*******************************************************************/

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();                    
  Lcd_Cmd(_LCD_CLEAR);           
  Lcd_Cmd(_LCD_CURSOR_OFF);      

  Lcd_Out(1,2, "Caractere: ");   
  Delay_ms(1000);               

  UART1_Init(9600);             
  Delay_ms(100);                

  UART1_Write_Text("Connexion");
  UART1_Write(13);              
  UART1_Write(10);              
  
  do {
    if (UART1_Data_Ready() == 1) {   
      Lecture_UART1 = UART1_Read();  
      UART1_Write(Lecture_UART1);    
      temp = Lecture_UART1;          
    }//fin If
    Delay_ms(100);
    Lcd_Chr(1,13, temp);       
    
  }while(1);  

} 

No comments:

Post a Comment