Activity 2. Turn ON/OFF LEDs every 500 ms

The purpose of this activity is to turn ON and OFF every 500 ms eight LEDs that are connected to the PORTB of the microcontroller.
(20 minutes)


Activity 2

Step 1. The circuit is drawn in the Proteus Design Suite. In this step 8 LEDs are connected to the PORTD parallel port. A voltmeter and an ammeter are also connected to check the voltage drop across one LED and the current through this LED.




Step 2. The program in C language is written.

Write in CCS Compiler the program in C language

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

                            // main.h is included

#byte PORTD =0xF83 // We attribute to the memory position

                                     // 0xF83 the name PORRD

                                    // This means that we create an 8 bit variable

                                    // whose value will be stored

                                    // at the memory position 0xF83

                                    // The memory position F81h is

                                    // the PORTD data register

 

void main(void){

 

set_tris_d(0x00);     // PORTD is made output

                                // This is done by giving to the

                                // PORTD direction register the value 0000 0000

PORTD =0b11111111;   //We give to the PORTD data register

                                        //the value 1111 1111

 

     while(TRUE) {                               // eternal loop

                  delay_ms(250);                  //delay 250 ms

                  PORTD=0b00000000;       // turn off the 8 LEDs

                  delay_ms(250);                  //delay 250 ms

                  PORTD=0b11111111;       //turn on the 8 LEDs            

                           }                                // closes the bracket or while

                

               }                                           // closes the bracket of main()



Step 3. The program is compiled with the use of CCS C compiler to the microcontroller machine code. The machine code is loaded to the flash memory of the microcontroller.



Step 4. The animation is activated, and we check that the 8 LEDs turn ON and OFF.