Activity 4. Create a moving dot with LEDs
The purpose of this activity is to create a moving
dot with the 8 LEDs that are connected to PORTB of the microcontroller. The dot
will move from left to right and from right to left.
(20 minutes)
Activity 4
Step 1. The circuit is drawn in the Proteus Design Suite. In this step 8 LEDs are connected to the PORTB parallel port.
Step 2. The program in C language is written.
The student must complete the following program in C language.
#include <main.h> // We include the file
// of the initial settings main.h
#byte PORTB =0xF81 // we assign to the memory position 0xF81
// the name PORTB
// This means that we create an 8 bit
// variable whose value will
// be stored at the memory address F81h
// At the memory address F81h is the PORTB
// data register
int8 i;
void main(void){
set_tris_b(0x00); // We define PORTB as output
// This is done by giving to the PORTB
// direction register the value 0000 0000
PORTB =0b10000000; // We give to the PORTB data register
//the initial value 1000 0000
while(TRUE) { // eternal loop
for(i=1;i<=7;i++){
…………………………………………………………………………
Complete the program with the necessary commands
…………………………………………………………………………..
} // closes the bracket of for
for(i=7;i>=1;i--){
…………………………………………………………………………
Complete the program with the necessary commands
…………………………………………………………………………..
} //closes the bracket of for
} // Closes the bracket of while(TRUE)
} // Closes the bracket of main()
//The initial value of PORTB is 10000000.
Tip1. Division of the value of PORTB by 2 moves the 1 to the right.
Tip2. Multiplication of the value of PORTB with 2 moves the 1 to the left.
Step 3. Compile the program in order to create the hex.file (machine code).
- Load the program (hex.file) to the microcontroller
- Check that the program runs properly