The following function may be useful for those who are starting in the microcontroller's world and wish to implement applications using 7-segment display with the CCS compiler in PIC platform. I've used long time ago:
This function must be called this way:
Code:
void Display7seg ( char value )
{
char pin=0 ;
while ( pin< 8 )
{
if ( SEGMENTCHARS[value ] & ( FIRST_SEGMENT >> pin) )
output_high ( DISPLAY_PINS[pin] ) ;
else
output_low ( DISPLAY_PINS[pin] ) ;
pin++ ;
}
}
Code:
// Any other pinout could be used instead
#define DISP7_A PIN_A7
#define DISP7_B PIN_A6
#define DISP7_C PIN_A5
#define DISP7_D PIN_A4
#define DISP7_E PIN_B3
#define DISP7_F PIN_B4
#define DISP7_G PIN_C6
// just to parametrize
#define FIRST_SEGMENT 0b10000000
const int DISPLAY_PINS [] = {
DISP7_A,
DISP7_B,
DISP7_C,
DISP7_D,
DISP7_E,
DISP7_F,
DISP7_G } ;
const char SEGMENTCHARS [] = {
0b00000000,
0b01100000,
0b11011010,
0b11110010,
0b01100110,
0b10110110,
0b00111110,
0b11100000,
0b11111110,
0b11110110 } ;
This function must be called this way:
Code:
Display7seg (number); // argument is an integer from 0 to 9