Multiple


 

Home
16F's
18F's
Both
Basics
Video's
Links
Contact

Up Single Multiple

    Displaying information on segment displays via multiplexing is one method to display values that require more than one segment display. The downsides to this are;

bulletThe information must be continuously updated on all of the segment
displays.
bulletBy doing so, you loose the ability to perform other functions while
displays are being updated.
bulletDevelop code to breakdown a 16bit word into 4 bytes containing
each numerical value for ones, tens, hundreds and thousands
bulletMore pins.. (12 pins are required for 4 segment displays)

    However, its low cost definitely makes up for it. The transistors that I use for switching between displays are BC550 NPN, and the value of the resistor in the circuit is dependent on how bright you want your displays, a low value of 50-300 ohms is ok. The 4 digit segment display can be found here.

Schematic (PSU/Osc not shown):

    If your going to be using any more than 2 displays, I'd really recommend something like this, as all of the segments are already connected in parallel, and you still control each display by switching the common cathode for each.

    Its the common cathode pin that is used to drive each display, and each piece of data is shifted in PORTB, then shown on the corresponding display. To break down the 4 digit number, we use the command DIG. Its use;

Variable = DIG Value , Digit number

Overview;
Returns the value of a decimal digit.

Operators;
    Value is a constant, variable, or expression, from which the digit number is to be extracted.
    Digit number is a constant, variable, or expression, that represents the digit to extract from value.
                          (0 - 9 with 0 being the rightmost digit).

    So now we can extract each piece of data for the segments, and the switch the common for the corresponding display once the data has been shifted into PORTB.

Device 16F877

Xtal = 4

Dim Number As Word

Dim Temp_Byte As Byte
Dim Temp_Word As Word
Dim Ones As Byte
Dim Tens As Byte

Symbol Display_Ones = PORTA.3
Symbol Display_Tens = PORTA.2

Symbol TMR0_Enable = INTCON.5
Symbol TMR0_Overflow = INTCON.2
Symbol GIE = INTCON.7

Symbol Segment_1 = PORTC.0
Symbol Segment_2 = PORTC.1

ON_INTERRUPT Goto Int_Sub
			
Goto Initialization
			
Int_Sub:

	If TMR0_Overflow = 1 And TMR0_Enable = 1 Then
	   
	   TMR0_Overflow = 0                ' Check if TMR0 Overflow occurred
	   If Segment_1 = 1 Then            '  and alternate displays
	   	  Segment_1 = 0
		  PORTB = Tens
	   	  Segment_2 = 1
	   Else 
	   	  Segment_2 = 0
		  PORTB = Ones
	   	  Segment_1 = 1
	   EndIf
	
	EndIf
	
        GIE = 1	
	
	Context Restore
	
Initialization:

		ALL_DIGITAL = True
		PORTB_PULLUPS = False

		TRISB = %00000000               ' Make PORTB all outputs
		Low Segment_1                   '  and setup segment control Pins
		Low Segment_2

		TMR0_Enable = 0
		
		OPTION_REG.0 = 0                ' Setup TMR0
		OPTION_REG.1 = 0                ' 100 = ~8mS Interrupt
		OPTION_REG.2 = 1                ' 
		OPTION_REG.5 = 0                ' 
		TMR0 = 0
		TMR0_Enable = 1
				
		Ones = 0                        ' Reset variables
		Tens = 0                        '
		
        GIE = 1
		
Main:
	 
	 Number = 0

	 Repeat                                    ' Create a loop
	 	 
		 Temp_Word = Number                ' Move the Number register into Temp_Word
		 
		 Gosub Breakdown                   ' Break down to units (ones and tens)

		 Temp_Byte = Ones                  ' Now convert the ones data into segment
		 Gosub Encode_Segment_Display      '  information
		 Ones = Temp_Byte                  '
		 
		 Temp_Byte = Tens                  ' And the same for Tens
		 Gosub Encode_Segment_Display      ' 
		 Tens = Temp_Byte                  '
		 
		 Inc Number                        ' Increment the Number register
		 
		 DelaymS 500                       ' Small delay to slow down counting
		  
	 Until Number = 100                        ' Loop until number = 100, then reset

	 Goto Main                                 ' Loop forever
	 
Breakdown:

	Temp_Byte = DIG Temp_Word, 1               ' DIG Val, X will return the value of X in the number
	Tens = Temp_Byte                           '  For example DIG 9790, 3 = 9 
	Temp_Byte = DIG Temp_Word, 0               '  and DIG 7845, 0 = 5
	Ones = Temp_Byte                           ' Now we know how many ones/tens in the number
			
	Return                                     ' Leave the routine

Encode_Segment_Display:

	SELECT Temp_Byte
	    CASE 0                                 ' Turn  Temp_Byte into segment display data
	   		 Temp_Byte = %00111111
	    CASE 1			
	   		 Temp_Byte = %00000110
	    CASE 2			
			 Temp_Byte = %01011011
	    CASE 3			
	   		 Temp_Byte = %01001111
	    CASE 4			
	   		 Temp_Byte = %01100110
	    CASE 5			
	   		 Temp_Byte = %01101101 
	    CASE 6			
   			 Temp_Byte = %01111100
	    CASE 7			
 			 Temp_Byte = %00000111
	    CASE 8			
			 Temp_Byte = %01111111
	    CASE 9			
 			 Temp_Byte = %01100111		 
	ENDSELECT
	
	Return

 

Spency's PICBasic

Home | 16F's | 18F's | Both | Basics | Video's | Links | Contact

 © Spency 2007
For problems or questions regarding this web contact Spency
Last updated: Thursday, 25 October 2007 11:27:59 PM.