How to Interfacing seven segment display with pic microcontroller and Mikro C
In this tutorials I am show how to interface a seven segment display with pic Microcontroller. Here we are use PIC16F877A microcontroller and MikroC pro for PIC compiler.
You can watch the flowing video and read the written tutorial below.
7 segment displays are two type . they are liquid crystal and light emitting diode. In this this tutorials I am used light emitting seven segment display. 7 segment display contain 7 LED of a digit. When LED is active and it emit light. In this tutorial we are used common cathode 7 segment display.
Internal structure of seven segment display below
7 segment display are used in digital clocks,electronics meter,measuring tools,calculator and electronics elements. It show decimal value from binary value.
Circuit Diagram
MikroC code
unsigned int display[10] ={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
int i;
void main() {
TRISB = 0X00; // PORTB is output
PORTB = 0X00; // Clear PORTB
while(1){
for(i=0;i<10;i++){
PORTB = display[i];
delay_ms(500);
}
}
}
Code Explain:
Here I am use Mikro C compiler for code editing. In define section we define a array for common cathode display. The display show the value in decimal numbers. Then in void main function we define PORTB is output by clearing TRISB register. Than we clear the PORTB by clearing PORTB register. Next we create a while loop for continues program execution. In while loop function we create a for loop. The for loop increase the value of i variable. The value of i is increase 0 to 9 and show the value on 7 segment display.
Download free source code
Post Comments