Activity 3. Rotate the value of PORTB
The purpose of this activity is to set an initial value
to the PORTB of the microcontroller and to rotate it continuously from right to
left.
(20 minutes)
Activity 3
The initial value of PORTB will be set to 11110000 and this value will be rotated to the left in time steps of 100 ms.
Step 1. The circuit is drawn at 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 stores
// at the memory position F81h
// The memory position F81h
// is the PORTB data register
void main(void) {
set_tris_b(0x00); // We define all the pins of PORTB as outputs
// This is done by giving to the
// PORTB direction register the value 00000000
PORTB =0b11110000; //We give the PORTB data register
//the initial value 111100. This is the value that will
// be rotated
while(TRUE) { // eternal loop
…………………………………………………………………………
Complete the program with the necessary commands
……………………………………………………….. ……………….
} //closes the bracket of the while
} // closes the bracket of main()
Tip1. The command rotate_left(&PORTB,1) will be used to rotate the value of PORTB.
Tip2. The command delay_ms(100) causes delay of 100 ms
Step 3. Compile the program in order to create the hex.file (program in machine code).
- Load the program (hex.file) to the microcontroller.
- Check that the program runs properly.