Activity 3. Read the value of a specific pin of an input parallel port

The purpose of this activity is to read the value of pin A0 and the value of pin A1 and turn ON an LED only when A0=1 and A1=1 (Logical function AND between A0 and A1).

(30 minutes)


Activity 3

Step 1. The circuit is drawn at the Proteus Design Suite. In this step 2 switches are connected to the pins A0 and A1 and 1 LED to the pin D0.



Step 2. The program in C language is written. The LED must be turned ON only when A0=1 and A1=1.

The student must complete the following program in C language.

 #include<main.h>  //The <main.h> containd the initial settings

                  //It must be placed in the same folder with

                  //your project.

#byte PORTA=0xF80 //F80 is the PORTA data register in the data memory of the

                  // microcontroller. It's a Special Function Register

#byte PORTD=0xF83  //F83 is the PORTD data register in the data memory of the

                  // microcontroller. It's a Special Function Register

 

// ********* main program ************************

 

void main()

{                   //Opening of the main() bracket

 

set_tris_a(0xff);   //PORTA is set as input (Direction Register=1111 1111)

set_tris_d(0x00);   //PORTD is set as output (Direction Register=0000 0000)

 

 

int1 a;             // Definition of 1 bit integer for storing the value of A0                   

int1 b;             // Definition of 1 bit integer for storing the value of A1 

 

while(TRUE) {      //Eternal loop (condition always TRUE)

            a=input(PIN_A0);

            b=input(PIN_A1);

…………………………………………………………………………

Complete the program with the necessary commands 

………………………………………………………..……………….

            }   //Closing bracket of while()

}      // Closing bracket of main()



Step 3. The program is compiled with the use of CCS C compiler to the microcontroller machine code (the hex.file is created). The program in machine code is loaded to the microcontroller. The animation is activated, and we check that the LED turns ON only when A0=1 and A1=1.