Menu

all about electronic and microcontrollers

Sunday, October 17, 2010

Lesson nr.11-7Segment in multiplexed mode

Hardware setup:
In this experiment we will learn how to use more than one 7-segment Led display, connected simultaneously at the microcontroller port,  using multiplexing technique. In the current experiment will interface four digit common cathode to PORT B, the command part, and to PORT A, the control of digits. The multiplexing circuit is configured on the breadboard, being composed of four NPN transistor and some resistance. Electric scheme emphasize  multiplexing interconnection mode. Multiplexing principle is that all digits are connected in parallel port on the microcontroller and the microcontroller alternately displays between units tens hundreds and thousands digits, selecting one at a time. The switching among the digits is so fast that it gives the impression of simultaneous emission of light.
Number displayed on the digits is 1234.



Circuit Diagram:
For those who want to build it on their own breadboard or other platform, here is the electronic scheme built in Eagle Cad, free version:


Software:
Here is the C program written for MikroC PRO for PIC 2010 (version v4.15).
/*
'*******************************************************************************
'  Lesson nr.11:
'          7Segment in multiplexed mode
'  Written by:
'          Aureliu Raducu Macovei, 2010.
'  Description:
'          In this experiment we will show how to implement the multiplexed mode 
'          to control 7 segmnet digits. PORTB will be used for character 
'          (RB0=a,RB1=b...RB6=g,RB7=dp)and for digits RA0=digit1...RA3=digit4.
'  Test configuration:
'    MCU:                        PIC16F628A
'    Test.Board:                 WB-106 Breadboard 2420 dots
'    SW:                         MikroC PRO for PIC 2010 (version v4.15)
'  Configuration Word
'    Oscillator:                 INTOSC:I/O on RA.6, I/O on RA.7
'    Watchdog Timer:             OFF
'    Power up Timer:             Disabled
'    Master Clear Enable:        Enabled
'    Browun Out Detect:          Enabled
'    Low Voltage Program:        Disabled
'    Data EE Read Protect:       Disabled
'    Code Protect:               OFF
'*******************************************************************************
*/
unsigned short mask(unsigned short num) // Mask for 7 segment common cathode;
{
 switch (num) {
               case 0 : return 0x3F;    // 0;
               case 1 : return 0x06;    // 1;
               case 2 : return 0x5B;    // 2;
               case 3 : return 0x4F;    // 3;
               case 4 : return 0x66;    // 4;
               case 5 : return 0x6D;    // 5;
               case 6 : return 0x7D;    // 6;
               case 7 : return 0x07;    // 7;
               case 8 : return 0x7F;    // 8;
               case 9 : return 0x6F;    // 9/
               }                        //case end
}
unsigned short digit1, digit2, digit3, digit4;
unsigned int number;

void main()                      // Main
{                     
 CMCON  |= 7;                    // Disable Comparators
 TRISB = 0;                      // Set PORTB direction to be output
 PORTB = 0xFF;                   // Turn OFF LEDs on PORTB
 TRISA = 0;
 PORTA = 0xFF;
 
 number = 1234;                  // value of number

 do {
     //Multiplexed mode;
     PORTB = digit4;
     RA0_bit = 0;
     RA1_bit = 0;
     RA2_bit = 0;
     RA3_bit = 1;                // Select Thousands Digit
     delay_ms(5);                // 5ms delay
     PORTB = digit3;
     RA0_bit = 0;
     RA1_bit = 0;
     RA2_bit = 1;                // Select Hundreds Digit
     RA3_bit = 0;
     delay_ms(5);                // 5ms delay
     PORTB = digit2;
     RA0_bit = 0;
     RA1_bit = 1;                // Select Tens Digit
     RA2_bit = 0;
     RA3_bit = 0;
     delay_ms(5);                // 5ms delay
     PORTB = digit1;
     RA0_bit = 1;                // Select Ones Digit
     RA1_bit = 0;
     RA2_bit = 0;
     RA3_bit = 0;
     delay_ms(5);                // 5ms delay
     
     digit1 = number%10;         // Extract Ones Digit
     digit1 = mask(digit1);
     digit2 = (number/10)%10;    // Extract Tens Digit
     digit2 = mask(digit2);
     digit3 = (number/100)%10;   // Extract Hundreds Digit
     digit3 = mask(digit3);
     digit4 = (number/1000);     // Extract Thousands Digit
     digit4 = mask(digit4);
     } while(1);                 // Infinite loop
}

2 comments:

  1. THERE'S SOMETHING WRONG... IN NUMBER IF WE PUT 1234 0R 1235 ITS SHOWING 8888 ON 7 SEGMENT. BUT IF WE KEEP 5555 ITS SHOWING PERFECT...

    ReplyDelete
  2. Working Perfectly thanks !

    ReplyDelete

If you do not understand something, or if you make some aplication helped by this blog, let me know.