News:

;) This forum is the property of Proton software developers

Main Menu

help:7 segment driver scanning different ports 16f1508 LookUpL

Started by okmn, May 03, 2021, 03:57 AM

Previous topic - Next topic

okmn

guys ,
i am trying driving 2 digit 7-segment display scanning way(again with new series pic16f1508)
i am sure forgetting something but i could not find it..
could you help me please ?

Device 16F1508
Xtal = 16
'All_Digital = 1
 Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_ON, CP_OFF, BOREN_OFF, CLKOUTEN_OFF
 Config2 WRT_OFF, STVREN_OFF, BORV_LO, LPBOR_OFF, LVP_OFF


'Config1 IESO_ON, FCMEN_OFF
 

OPTION_REG.7 = 0
ANSELA = 0 ' Set all digital
ANSELB = 0
ANSELC = 0
SSP1CON1.5 = 0
SSP1CON1.4 = 0
OSCCON = %00111010
TRISA = 0
PORTA = 0
TRISB = 0
PORTB = 0
TRISC = %00110000
PORTC = 0
'INTCON = 0
Symbol up_button = PORTC.4
Symbol down_button = PORTC.5
Symbol ENABLE_ones = PORTB.4
Symbol ENABLE_tens = PORTA.5

Dim value As Byte
Dim ones As Byte
Dim tens As Byte
Dim count As Word
Dim DISPLAY As Byte
Main:

GoSub read_button
GoSub SEVEN_SEG

GoTo Main

read_button:
If up_button = 0 And down_button = 1 Then
    value = value +1
    If value > 90 Then value = 0
EndIf   
If up_button = 1 And down_button = 0 Then
    value = value -1
    If value > 90 Then value = 90
EndIf   

 
Return

SEVEN_SEG:
For count = 0 To 20
ones = Dig value,0
tens = Dig value,1
DISPLAY = LookUpL ones,[103 ,127,7,125,109,102,79,91,6,63] '63,6,91,79,102,109,125,7,127,
PORTC = DISPLAY
ENABLE_ones = 1
DelayUS 200
ENABLE_ones = 0
DelayUS 1
DISPLAY = LookUpL tens,[103 ,127,7,125,109,102,79,91,6,63]'63,6,91,79,102,109,125,7,127,103
PORTC = DISPLAY
ENABLE_tens = 1
DelayUS 200
ENABLE_tens = 0
DelayUS 1
Next count
Return

lookuptable.jpg      prot_pic.jpg

trastikata

F and G  segment are on a different port, so when you do a lookup and set Port C, the F and G segment are not set.

You need small delay do de-bounce those buttons when pressed, the delay of about 8ms created by the display routine is not enough..

The common Cathode on those LED's goes directly to the PIC port, and the port can not handle that much current (8 x 15 ma), you need to drive it through a small NPN or N-FET.
 
If you don't need the hardware timer for anything else, it's better using the timer interrupt to drive the LED display.

Giuseppe

I tried to modify my code to help you try and see if it can be useful to you
'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : [Giuseppe]                                        *
'*  Notice  : Copyright (c) 2021 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                              *
'*  Date    : 03/05/2021                                        *
'*  Version : 1.0                                              *
'*  Notes  :                                                  *
'*          :                                                  *
'****************************************************************
Device = 18F25K22

Config_Start
  FOSC = INTIO67 ;Internal oscillator block
  PLLCFG = OFF ;Oscillator used directly
  PRICLKEN = On ;Primary clock enabled
  FCMEN = OFF ;Fail-Safe Clock Monitor disabled
  IESO = OFF ;Oscillator Switchover mode disabled
  PWRTEN = On ;Power up timer enabled
  BOREN = On ;Brown-out Reset enabled and controlled by software (SBOREN is enabled)
  BORV = 190 ;VBOR set to 1.90 V nominal
  WDTEN = OFF ;Watch dog timer is always disabled. SWDTEN has no effect.
  WDTPS = 32768 ;1:32768
  CCP2MX = PORTC1 ;CCP2 input/output is multiplexed with RC1
  PBADEN = OFF ;PORTB<5:0> pins are configured as digital I/O on Reset
  CCP3MX = PORTB5 ;P3A/CCP3 input/output is multiplexed with RB5
  HFOFST = On ;HFINTOSC output and ready status are not delayed by the oscillator stable status
  T3CMX = PORTC0 ;T3CKI is on RC0
  P2BMX = PORTB5 ;P2B is on RB5
  MCLRE = INTMCLR ;RE3 input pin enabled; MCLR disabled
  STVREN = On ;Stack full/underflow will cause Reset
  LVP = OFF ;Single-Supply ICSP disabled
  XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  Debug = OFF ;Disabled
  Cp0 = OFF ;Block 0 (000800-001FFFh) not code-protected
  CP1 = OFF ;Block 1 (002000-003FFFh) not code-protected
  CP2 = OFF ;Block 2 (004000-005FFFh) not code-protected
  CP3 = OFF ;Block 3 (006000-007FFFh) not code-protected
  CPB = OFF ;Boot block (000000-0007FFh) not code-protected
  CPD = OFF ;Data EEPROM not code-protected
  WRT0 = OFF ;Block 0 (000800-001FFFh) not write-protected
  WRT1 = OFF ;Block 1 (002000-003FFFh) not write-protected
  WRT2 = OFF ;Block 2 (004000-005FFFh) not write-protected
  WRT3 = OFF ;Block 3 (006000-007FFFh) not write-protected
  WRTC = OFF ;Configuration registers (300000-3000FFh) not write-protected
  WRTB = OFF ;Boot Block (000000-0007FFh) not write-protected
  WRTD = OFF ;Data EEPROM not write-protected
  EBTR0 = OFF ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
  EBTR1 = OFF ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
  EBTR2 = OFF ;Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
  EBTR3 = OFF ;Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
  EBTRB = OFF ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

Xtal = 16


OSCCON = %01110110  ' set hfintosc 16Mhz Pag.32
OSCCON2 = %00000000 ' set Pag.33
OSCTUNE = %10000000 ' PLL disabled-31.25 kHz device clock HFINTOSC source-factory calibrated frequency Pag.37

'--------Set Reg. Interrupt----------

INTCON = %00000000  '
INTCON2 = %00000000 '
INTCON3 = %00000000 '
PIE1 = %00000000    '
PIR1 = %00000000    '
IPR1 = %00000000    '

'--------------Set port----------

LATB = %00000000
TRISB = %11000000
LATA = %00000000
TRISA = %00000000
LATC = %00000000
TRISC = %00000000 '
TRISE = %10000100 '
CM1CON0.7 = 0    '
CM2CON0.7 = 0    '

WPUB = %11000000 '

'------Set TMR0-------------
T0CON = %01000011 '
TMR0H = 0
TMR0L = 6

'------Variable-----------------------

Dim dato As Byte
Dim load As Byte
Dim load1 As Byte
Dim display [2] As Byte
Dim value As Byte
Dim DIG_1 As Byte
Dim DIG_0 As Byte
Dim tic As Byte
Dim display_set As Byte
Dim t_down_button As Word
Dim t_up_button As Word
Dim flag As Byte

'---------Symbol-------------------------------------

Symbol catodo0 = PORTA.2  'Pin4
Symbol catodo1 = PORTA.3  'Pin5

Symbol GIE = INTCON.7
Symbol PEIE = INTCON.6
Symbol TMR0IE = INTCON.5
Symbol TMR0IF = INTCON.2
Symbol TMR0ON = T0CON.7    ' Stops Timer0-Timer0 = 0
Symbol down_button = PORTB.6
Symbol up_button = PORTB.7
Symbol flag_sec = flag.0

'------------Abilito interrupt---------------------------

Set TMR0IE
Set TMR0ON
Set GIE

'--------------Interrupt Routine---------------------
On_Interrupt GoTo int_routine

GoTo main

int_routine:

Context Save

If TMR0IF = 1 Then
  TMR0L = 6
  Clear TMR0IF
  tic = tic + 1            ' 1 tic = 1mS
 
 If tic < 5 Then exit_int 
 If tic > = 5 Then          '5 tic = 5 mS
  tic = 0
 
  If down_button = 0 Then Inc t_down_button
  If up_button = 0 Then Inc t_up_button
 
  refresh_display:      'every 5 ms
 
  Select display_set   
 
  Case 0
  Low catodo1          'cathode management through npn transistors
  High catodo0          'for common cathode display
  PORTC = display[0]
 
  Case 1
  Low catodo0
  High catodo1
  PORTC = display[1]
 
  End Select
 
  display_set = display_set + 1
  If  display_set > 1 Then display_set = 0 
 End If
EndIf

exit_int:

Context Restore
'--------------------------------------------


main:

read_button:

If up_button = 0 Then GoTo read_button 
If down_button = 0 Then GoTo read_button


If t_up_button > 40 Then        'if I press for at least 200ms
  Clear t_up_button
  value = value + 1
  If value > 90 Then value = 0
EndIf


If t_down_button > 40 Then
  Clear t_down_button
  value = value - 1
EndIf


view_time(value)
       
         
GoTo main


'----------------------------------------------------------------------------------------------
Proc view_time(digit)
           
DIG_1 = digit ? 1  'I select first digit of digit
DIG_0 = digit ? 0  '

           
dato = DIG_1 & $0f
GoSub table
display[1] = load1
dato = DIG_0 & $0f
GoSub table                                                               
display[0] = load1           

EndProc

'--------------Routine values from 0-9----------------------

table:

load = LookUp dato,[$C0,$F9,$A4,$B0,$99,$92,$82,$F8,$80,$98] 

load1 = ~ load  'for common cathode display

Return


See_Mos

Doesn't that just show how stupid the Microchip designers have become?

The pin sequence is all over the place.

Unless you need to use any of the PortC peripherals I would put the buttons on one of the other ports and all of the segments on PORTC and change the lookup table to make the display work.


okmn

Quote from: See_Mos on May 03, 2021, 10:26 AMDoesn't that just show how stupid the Microchip designers have become?

The pin sequence is all over the place.

Unless you need to use any of the PortC peripherals I would put the buttons on one of the other ports and all of the segments on PORTC and change the lookup table to make the display work.



i can not use all the segments at c ports beacouse of pcb desgin requireds.
for the pcb design comfort i have to use different ports.

thank you guys
i will try somethings.

trastikata

Here's a part of code I wrote some time ago that might give you some ideas. Basically instead of a look-up use subroutines to set corresponding LEDs.


Symbol A = PORTA.4
Symbol B = PORTC.0
Symbol C = PORTB.4
Symbol D = PORTB.2
Symbol E = PORTA.5
Symbol F = PORTC.1
Symbol G = PORTB.5


Main:
   While 1 = 1
'Do something here
   Wend


SELECT_DIGIT:
    GoSub RESET_LED
   
    Select MyDigit
        Case 0
            GoSub ZERO
        Case 1
            GoSub ONE
        Case 2
            GoSub TWO
        '.... and so on   
    EndSelect
Return

RESET_LED:
Low A : Low B : Low C : Low D : Low E : Low F : Low G
Return

ZERO:
High A : High B : High C : High D : High E : High F
Return

ONE:
High B : High C
Return

TWO:
High A : High B : High G : High E : High D
Return

THREE:
High A : High B : High C : High D : High G
Return

FOUR:
High F : High G : High B : High C
Return

FIVE:
High A : High F : High G : High C : High D
Return

SIX:
High A : High F : High G : High C : High D : High E
Return

SEVEN:
High A : High B : High C
Return

EIGHT:
High A : High B : High C : High D : High E : High F : High G
Return

NINE:
High A : High B : High C : High D : High F : High G
Return

top204

For access to individual pins that are acting as a single port, you will need to create some procedures to make a virtual port:

'
' Create the pins to use for the virtual port
'
    Symbol Pin0 = PORTC.0
    Symbol Pin1 = PORTC.1
    Symbol Pin2 = PORTC.2
    Symbol Pin3 = PORTC.3
    Symbol Pin4 = PORTC.4
    Symbol Pin5 = PORTC.5
    Symbol Pin6 = PORTB.6
    Symbol Pin7 = PORTB.7
   
'-------------------------------------------------------------
' Read from the virtual port
'
Proc Virtual_Port_Read(), Byte   
    Result.0 = Pin0
    Result.1 = Pin1
    Result.2 = Pin2
    Result.3 = Pin3
    Result.4 = Pin4
    Result.5 = Pin5
    Result.6 = Pin6
    Result.7 = Pin7
EndProc
 
'-------------------------------------------------------------
' Write to the virtual port
'
Proc Virtual_Port_Write(pValue As Byte)   
    Pin0 = pValue.0
    Pin1 = pValue.1
    Pin2 = pValue.2
    Pin3 = pValue.3
    Pin4 = pValue.4
    Pin5 = pValue.5
    Pin6 = pValue.6
    Pin7 = pValue.7
EndProc

'---------------------------------------------------------------------------------
Main:
    Virtual_Port_Write(%10101010)
    Byteout = Virtual_Port_Read()

It is slower than reading and writing the port directly, but it gives the code a bit more clarity and is a way to manipulate indvidual pins from different ports as a "single entity"

trastikata

Quote from: top204 on May 03, 2021, 05:45 PMFor access to individual pins that are acting as a port, you will need to create some procedures to make a virtual port:

I keep forgetting Proc's are now available in Positron :).

The only subtlety with the virtual ports is that the common cathode (anode) needs to be non-conducting while setting the port, otherwise "artifacts" will appear on the LED display because of the delay created while setting each individual segment, basically for a brief moment a segment can be ON while it shouldn't and creates a flicker...
 

okmn

dear Les,

i will say to me "the new pics" is "OK" when i understood using "procedure"completely.


i was waiting the latest positron and it's pdf and board,to start using "procedure" ( i think i saw wrong!?)
but the 3.7.5.5. also is ready to fully using the procedure is it like that?

thank you to everyone.

top204

Procedures were added to the 8-bit Proton compiler about 2 years ago, and some good users paid for the upgrade containing them, so I could re-coupe some of the time I spent on them. I cannot thank them enough because it gave me a "purpose in life" again, after my injury caused so many physical and psychological problems. :-(

The manual for version 3.7.5.5 of the compiler has a section on Procedures.

okmn

What can be done to treat the conditions in which your ailment physically compels you?
You have already researched and learned this, maybe we will not be able to do anything at this point, but,

I know very well what is psychological breakdown.
I know very well about burnout syndrome, unwillingness, detachment from life, and many other negative situations.
but I also knew / learned this very well.

"I cannot drive the vehicle constantly looking in the rearview mirror, I have to look in front of me .."

Stuck with problems just melts me down and that would end me one day.

finally I stopped looking back and looking in front of me I put the idea of "do something, do whatever you can do, even if it is small" into my life.

  My "back to life" started to accelerate, the more everything I did

There is a proverb I know;

 "the devil's office is empty minds".


Stay with us, you are definitely doing very good work, we are with you as we can.

God help you, our widows are always for you.


okmn

Quote'------------Abilito interrupt---------------------------

Set TMR0IE
Set TMR0ON
Set GIE
dear Giuseppe i will ask some questions (jut to learn good)
you had been used this  command lines

the "set" command it is mean to make the registers 1 or 0 ?(to make enable or disable)

Set TMR0IE....TMR0IE = 1
Set TMR0ON....TMR0ON = 1
Set GIE.......GIE = 1
 if 2 typing style are same so why you did not use  just "1" and used "set" command ?
what is it different between both typing?

OG


okmn

dear OG ,
me to i read it,"
i asked , why he did not choose "TMR0IE = 1 " instead of this command "Set TMR0IE"
what it is different ?

trastikata

It is explained under the Overview paragraph.

- For a variable it means setting all bits to 1
- For a bit it means setting it to 1.

See the examples on the screenshot OG posted.

Stephen Moss

#15
Quote from: okmn on May 03, 2021, 03:57 AMguys ,
i am trying driving 2 digit 7-segment display scanning way(again with new series pic16f1508)
i am sure forgetting something but i could not find it..
could you help me please ?
I believe there is an error in your Read_Buttons code, if the intention is to wrap around the count from 90 back to 0 when counting up and from 0 back to 90 when counting down should not...
If up_button = 1 And down_button = 0 Then
    value = value -1
    If value > 90 Then value = 90
EndIf
be
If up_button = 1 And down_button = 0 Then
    If value = 0 Then
    value = 90
    Else
   value = value -1
   EndIf
EndI
As Value is a byte and not signed you cannot check that it has gone negative so you need to check if it is 0 before subtracting, alternative you could try of value = 255 then Value = 90 as subetracting 1 from 0 should create a roll around of the byte to 255.

Your Seven_Seg subroutine uses the same lines of code twice, changing to a procedure that to which you pass the digit (1's or 10's) and its value (0-9) would be more efficient code wise or keeping it as a subroutine...
SEVEN_SEG:
For count = 0 To 20
Digit = Dig value,0  'Assign 1's value to Digit
Gosub Display_Digit
ENABLE_ones = 1
DelayUS 200
ENABLE_ones = 0
DelayUS 1
Digit = Dig value,1   'Assign 10's value to Digit
Gosub Display_Digit
ENABLE_tens = 1
DelayUS 200
ENABLE_tens = 0
DelayUS 1
Next count
Return

Display_Digit:
DISPLAY = LookUpL Digit,[103 ,127,7,125,109,102,79,91,6,63]'63,6,91,79,102,109,125,7,127,103
PORTC = DISPLAY
Return
saves repeating a few lines of code as the look up is to output the correct value for the digit and the digit data is the same (0-9) whether it is uses for a 1's or a 10's value repeating it is inefficient coding.

What is the reason for the SEVEN_SEG code 20 times?
Why use DelayUS 200, you need to refresh the display (both digits) at least once every 20mS for persistence of vision. Obviously you need time to allow other code to run but I would think in such a small program you could have each digit displayed for significantly longer, for example 5mS and do away with the For-Next loop. Additionally the less time each display is illuminated the dimmer the display gets. which is why when using, say displaying an and 8 digit number with 7 segment displays you need to drive the segments at higher then normal currents to stop the display dimming. 

Top204's virtual port is a good way of doing thing where you cannot use a single port for driving your display segments, alternatively you might consider sending the data serially to an Serial In Parallel out shift register or to and 8574 I2C expander. Programatically that may be faster and more readable than using pins on different ports for driving the segments.

Quote from: trastikata on May 03, 2021, 07:00 AMThe common Cathode on those LED's goes directly to the PIC port, and the port can not handle that much current (8 x 15 ma), you need to drive it through a small NPN or N-FET.
trastikata is correct. I have not looked at the datasheet for the device in question but generally an individual pin can on sink and source 25mA so even with a typical LED current of 10mA a segment you can only sink enough to drive 2 segments if taking the cathodes low directly via a port pin. 

Quote from: okmn on May 04, 2021, 12:51 AMi asked , why he did not choose "TMR0IE = 1 " instead of this command "Set TMR0IE"
what it is different ?
Functionally I don't believe there is any difference, it is just a matter of personal preference.

Giuseppe

Using set TMR0IE instead of TMR0IE = 1 is just a personal choice for me.
It's like using clear TMR0IE instead of TMR0IE = 0

See_Mos

I came up with a different way that works with the display connections the same as the diagram in the original post.  I started with the code posted by Giuseppe and added some of my own code.

My ISIS licence only covers 18F series so I used my current favorite device 18F25K22.  The code is for a four digit display but is easily changed for 2 digits.

' adapted from code by Giuseppi
'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : [Giuseppe]                                        *
'*  Notice  : Copyright (c) 2021 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                              *
'*  Date    : 03/05/2021                                        *
'*  Version : 1.0                                              *
'*  Notes  :                                                  *
'*          :                                                  *
'****************************************************************

'$define _LCD_PORT_ 1                ' LCD PortA = 0, PortB = 1, PORTC = 2
'                                    ' Custom = 3
'Include "18F25K22 INTOSC 16.inc"

Device = 18F25K22

Config_Start
  FOSC = INTIO67 ;Internal oscillator block
  PLLCFG = OFF ;Oscillator used directly
  PRICLKEN = On ;Primary clock enabled
  FCMEN = OFF ;Fail-Safe Clock Monitor disabled
  IESO = OFF ;Oscillator Switchover mode disabled
  PWRTEN = On ;Power up timer enabled
  BOREN = On ;Brown-out Reset enabled and controlled by software (SBOREN is enabled)
  BORV = 190 ;VBOR set to 1.90 V nominal
  WDTEN = OFF ;Watch dog timer is always disabled. SWDTEN has no effect.
  WDTPS = 32768 ;1:32768
  CCP2MX = PORTC1 ;CCP2 input/output is multiplexed with RC1
  PBADEN = OFF ;PORTB<5:0> pins are configured as digital I/O on Reset
  CCP3MX = PORTB5 ;P3A/CCP3 input/output is multiplexed with RB5
  HFOFST = On ;HFINTOSC output and ready status are not delayed by the oscillator stable status
  T3CMX = PORTC0 ;T3CKI is on RC0
  P2BMX = PORTB5 ;P2B is on RB5
'  MCLRE = INTMCLR ;RE3 input pin enabled; MCLR disabled
  MCLRE = EXTMCLR ; use external MCLR
  STVREN = On ;Stack full/underflow will cause Reset
  LVP = OFF ;Single-Supply ICSP disabled
  XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  Debug = OFF ;Disabled
  Cp0 = OFF ;Block 0 (000800-001FFFh) not code-protected
  CP1 = OFF ;Block 1 (002000-003FFFh) not code-protected
  CP2 = OFF ;Block 2 (004000-005FFFh) not code-protected
  CP3 = OFF ;Block 3 (006000-007FFFh) not code-protected
  CPB = OFF ;Boot block (000000-0007FFh) not code-protected
  CPD = OFF ;Data EEPROM not code-protected
  WRT0 = OFF ;Block 0 (000800-001FFFh) not write-protected
  WRT1 = OFF ;Block 1 (002000-003FFFh) not write-protected
  WRT2 = OFF ;Block 2 (004000-005FFFh) not write-protected
  WRT3 = OFF ;Block 3 (006000-007FFFh) not write-protected
  WRTC = OFF ;Configuration registers (300000-3000FFh) not write-protected
  WRTB = OFF ;Boot Block (000000-0007FFh) not write-protected
  WRTD = OFF ;Data EEPROM not write-protected
  EBTR0 = OFF ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
  EBTR1 = OFF ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
  EBTR2 = OFF ;Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
  EBTR3 = OFF ;Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
  EBTRB = OFF ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

;**** End of Fuse Configurator Settings ****
';-------------------------------------------------------------------------------

Xtal = 16


OSCCON = %01110110  ' set hfintosc 16Mhz Pag.32
OSCCON2 = %00000000 ' set Pag.33
OSCTUNE = %10000000 ' PLL disabled-31.25 kHz device clock HFINTOSC source-factory calibrated frequency Pag.37

'--------Set Reg. Interrupt----------

INTCON = %00000000  '
INTCON2 = %00000000 '
INTCON3 = %00000000 '
PIE1 = %00000000    '
PIR1 = %00000000    '
IPR1 = %00000000    '

CM1CON0.7 = 0    '
CM2CON0.7 = 0    '

WPUB = %11000000 '

'------Set TMR0-------------
T0CON = %01000011 '
TMR0H = 0
TMR0L = 6

'------Variable-----------------------

Dim dato As Byte
Dim load As Byte
Dim load1 As Byte
'Dim display [2] As Byte
Dim value As Word
Dim DIG_1 As Byte
Dim DIG_0 As Byte
Dim tic As Byte
Dim display_set As Byte
Dim t_down_button As Word
Dim t_up_button As Word
Dim flag As Byte

Dim Decimal_Point As Byte
Dim X As Byte
Dim Units  As Byte
Dim Tens    As Byte
Dim Hundreds As Byte
Dim Thousands As Byte
'---------Symbol-------------------------------------

Symbol catodo0 = LATA.5
Symbol catodo1 = LATB.4
Symbol catodo2 = LATB.0
Symbol catodo3 = LATB.1

Symbol GIE = INTCON.7
Symbol PEIE = INTCON.6
Symbol TMR0IE = INTCON.5
Symbol TMR0IF = INTCON.2
Symbol TMR0ON = T0CON.7    ' Stops Timer0-Timer0 = 0
'Symbol down_button = PORTB.6
'Symbol up_button = PORTB.7
Symbol flag_sec = flag.0

'------------Abilito interrupt---------------------------

Set TMR0IE
Set TMR0ON
Set GIE

'--------------Interrupt Routine---------------------
On_Interrupt GoTo int_routine

GoTo Main

int_routine:

Context Save

If TMR0IF = 1 Then
  TMR0L = 6
  Clear TMR0IF
  tic = tic + 1            ' 1 tic = 1mS
 
 If tic < 5 Then exit_int
 
 If tic > = 5 Then          '5 tic = 5 mS
      tic = 0
   
' --------------  refresh_display every 5 ms
      Select display_set 
   
        Case 0
            Low catodo3          ' cathode low turns off display while updating
            '  PORTC = display[0]  ' replaced by Set_Segments()
            Set_Segments(Units)
            If Decimal_Point = 1 Then
                LATB.7 = 1
            Else
                LATB.7 = 0
            EndIf
            High catodo0          'cathode management through npn transistors
       
        Case 1
            Low catodo0
            Set_Segments(Tens)
            If Decimal_Point = 2 Then
                LATB.7 = 1
            Else
                LATB.7 = 0
            EndIf
            High catodo1
       
        Case 2
            Low catodo1
            Set_Segments(Hundreds)
            If Decimal_Point = 3 Then
                LATB.7 = 1
            Else
                LATB.7 = 0
            EndIf
            High catodo2
           
        Case 3
            Low catodo2
            Set_Segments(Thousands)
            If Decimal_Point = 4 Then
                LATB.7 = 1
            Else
                LATB.7 = 0
            EndIf
            High catodo3           
        End Select
   
      Inc display_set
      If  display_set > 3 Then display_set = 0
    End If
EndIf

exit_int:

Context Restore
'--------------------------------------------
Main:
    TRISA = 0 : TRISB = 0 : TRISC = 0
    LATA = 0 : LATB = 0 : LATC = 0
While 1 = 1
    Decimal_Point = 2          ' set position of decimal point
    Units = Dig value,0        ' get the digit values
    Tens = Dig value,1
    Hundreds = Dig value,2
    Thousands = Dig value,3                 
    DelayMS 100                ' slow it down
    Inc value
    If value = 9999 Then
        value = 0
    EndIf
Wend

'------------------set port pins ----------------

Proc Set_Segments(dato As Byte)
table:
    load1 = LookUp dato,[63,20,91,94,116,110,111,28,127,124]  ' CC values
    LATB.6 = load1.6
    LATA.4 = load1.5
    LATC.7 = load1.4
    LATC.6 = load1.3
    LATC.2 = load1.2
    LATC.1 = load1.1
    LATC.0 = load1.0
EndProc


See_Mos

I have now tested it on real hardware and discovered some errors in the code I posted previously.  While trying to find a different way of achieving the required result I messed up the display connections and the LookUp table. I also put the decimal point on the wrong pin.  With the display connected as the original post and DP back on A2 change all LATB.7 to LATA.2 and change the PROC to:

Proc Set_Segments(dato As Byte)
table:
 ' CC values
    load1 = LookUp dato,[63,6,91,79,102,109,125,7,127,103]
    LATB.6 = load1.6
    LATA.4 = load1.5
    LATC.0 = load1.4
    LATC.1 = load1.3
    LATC.2 = load1.2
    LATC.7 = load1.1
    LATC.6 = load1.0
EndProc