1. Introduction
This article shows you how to communicate with PIC16F877A microcontroller via CuscoPIC board. To do so, we will use ASCII driver to communicate via Serial/Serial (RS232/RS232).
First, you must program the microcontroller with the parallel port, and then pass the bootloader so that the board will enable RS232 port. (CuscoPIC’s website will present the steps for recording the bootloader).
Next in the controller’s programming, you can use MPLab programmer from Microchip, PIC16F877A’s manufacturer.
2. Programming
The program used in this example reads the values coming from the computer’s serial.
{
char x,y, linha[17];
signed long aux;
int index;
while(1) // infinite loop
{
if (!kbhit()) continue;
x = getch();
if (x == ‘A’) { //Tests the value coming from the supervisory
aux = AD(0); //Passes the value of the potentiometer to an “aux” variable
printf(“%04li”, aux); //Prints the display with the value of the potentiometer
} else if (x == ‘B’) { //Tests the value coming from the supervisory
output_d(y); //Writes the value of “y” in D output
if (y) y=0; else y=128; //If “y” equals “0”, I receives value “128”
} else if (x == ‘C’) { //Tests the value coming from the supervisory
index=0; //Sets the vector for the display
do {
linha[index]=getch();
index++;
} while(linha[index-1]);
lcd_gotoxy(1,2);
printf(lcd_putc,”SLIDER=%s”, linha); //Prints “Slider=” display with the value of the supervisory
}
}
}
3. Settings
After compiling and recording the program at CuscoPIC, you must set up the supervisory (Elipse SCADA or Elipse E3). The settings of the example below were developed with Elipse SCADA, but they can also work for Elipse E3.
1. Add the ASCII driver to the project.
2. Set up the driver’s extras with the serial’s TX and RX (write and read) commands.
Note: You can set up the type of information to be read by the driver as the example of “C” command described in the microcontroller’s programming, which in this case is C%4u/h00 (where: % – symbol identifying the variable field; 4 – number of characters; u – unsigned decimal; and /00 – special character in two-digit hexadecimal format). All settings possibilities for this driver are at its user’s manual, in the chapter Setting ASCII Commands.
3. Set up the Physical Layer as serial and fill its fields according to the information supplied by the board’s developer.
4. Insert and set up the tags according to the ID configured in the driver’s extra settings and the desired (read and/or write) parameter. For further information on the read/write parameters, please refer to the driver’s manual Tags Reference chapter.
Examples of tags settings:
N1 = 0; N2 = 3; N3 = 0; N4 = 0
Read/write tag (N1=0); using a level-3 command (N2 = 3); with a variable index in 0 (N3 = 0); and no Offset in the message (N4 = 0).
N1 = 1; N2 = 4; N3 = 0; N4 = 0
Tag that reads or writes the values of TX’s variable fields before sending a command (N1 = 1);
using a level-4 index command (N2 = 4); with a variable index in 0 (N3 = 0); and 0 default in N4 (N4 = 0).
N1 = 4; N2 = 4; N3 = 0; N4 = 0
Tag that sends a request to the microcontroller (N1 = 4); using a level-4 index command (N2 = 4); 0 default in N3 (N3 = 0); and 0 default in N4 (N4 = 0).
5. After the tags have been set up, configure the screens as desired.
4. Final Remarks
It is possible to communicate with a microcontrolled device via ASCII driver, as long as it supports the reading and writing of messages with the supervisory via RS232 port. These messages are preconfigured in the microcontroller’s program.