Activity 2. Input binary number – output to seven segment displays
The purpose of the activity is to continuously read the value of PORTB which is used as an input and display its value in the decimal number system in the 3 seven-segment displays.
(45 minutes)
Activity 2
Step 1. The circuit is drawn in the Proteus Design Suite.
Step 2. The program in C language is written.
Write in CCS C Compiler the program in C language
#include <main.h>
#byte PORTB =0xF81
#byte PORTC =0xF82
#byte PORTD =0xF83
void main(){
// Define PORTB as inpout
// DEfine PORTC and PORTD as output
set_tris_b(0xFF);
set_tris_c(0x00);
set_tris_d(0x00);
int8 table[16] ={
//Table of codes to display in a 7-segment display
0b00111111, //0
0b00000110, //1
0b01011011, //2
0b01001111, //3
0b01100110, //4
0b01101101, //5
0b01111101, //6
0b00000111, //7
0b01111111, //8
0b01101111, //9
0b01110111, //Α
0b01111100, //Β
0b00111001, //C
0b01011110, //D
0b01111001, //Ε
0b01110001};//F
int input_value;
// variable to store the input value
int monades;
// variable to store the units of the input value
int decades;
// variable to store the tens of the input value
int ekatontades;
// variable to store the hundredths of the input value
while (TRUE){
// the codes of each digit are sent every 5 ms
// by activating the corresponding display
input_value=PORTB;
ekatontades=input_value/100;
decades=(input_value-ekatontades*100)/10;
monades=input_value-ekatontades*100-decades*10;
PORTC=0b00000100; //activate the left display
PORTD=table[ekatontades];
delay_ms(5);
PORTC=0b00000010; //activate the middle display
PORTD=table[decades];
delay_ms(5);
PORTC=0b00000001; //activate the right display
PORTD=table[monades];
delay_ms(5);
}
}Step 3. Compile the program in C in order to create the program in the microcontroller machine code (hex file).
Step 4. Load to the microcontroller the hex file (program in machine code) that was created from the CCS C Compiler.