Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Routine for handling 7-seg display on CCS

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:

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

Comments

There are no comments to display.

Part and Inventory Search

Blog entry information

Author
andre_luis
Read time
1 min read
Views
1,379
Last update

More entries in Uncategorized

More entries from andre_luis

Share this entry

Back
Top