//******************************************************************************
// microcontroller : PIC16F84A
//
// Project: 7seg_display1
// This project is designed to work with PIC16F84A;
// with minor adjustments, it should work with any other PIC MCU.
//
// This code demonstrates how to display number on one 7-segment display
// (common cathode).
// Display is connected to portb(RB0..RB7, segment A to RB0,
// segment B to RB1, etc); common cathode is connected to the pin RA1 on porta.
// Number is incremented every 1 second
//******************************************************************************
unsigned short i;
// Function returns mask of num for common cathode 7seg. display
unsigned short Mask_7seg(unsigned short num) {
switch (num) {
case 0: return 0x3F;
case 1: return 0x06;
case 2: return 0x5B;
case 3: return 0x4F;
case 4: return 0x66;
case 5: return 0x6D;
case 6: return 0x7D;
case 7: return 0x07;
case 8: return 0x7F;
case 9: return 0x6F;
}
}//~
void main() {
INTCON = 0; // Disable PEIE, INTE, RBIE, T0IE
TRISA = 0;
TRISB = 0;
PORTB = 0;
PORTA = 2;
// Main loop
do {
for (i = 0; i <= 9u; i++) {
PORTB = Mask_7seg(i); // Display digit on 7seg display
Delay_ms(1000); // 1 second pause
}
} while (1);
}//~!