News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Positron compiler

Started by Pepe, Today at 01:22 PM

Previous topic - Next topic

Pepe

It's a shame the Positron compiler can't be used to compile the clock program I translated from CCS C to Positron BASIC for the PIC16F648A. Below is a demo in Proteus with the working CCS-created hex file. When I compile it with Positron for the PIC18F, it works, but not for the PIC16F.

RGV250

Hi,
Why not post the C and positron code for  16f and 18f so we can have a look.

Regards,
Bob

Pepe

Proteus demo running on 18f2550 (reloj_2550.zip) and sources in CCS C (reloj.zip) and in positron basic (clock_source_2550_bas.zip)

RGV250

Hi,
Unfortunately I miss read and thought it was the 2550 you could not get working, I cannot sim 16 series.
My only thought is the gosubs in the interrupt routine as there is a warning when I compile the 2550. I wonder if the 16F is losing track of some variables?
I cannot see why they have to be in there, have you tried moving them outside and try running it?

Regards,
Bob

RGV250

Hi,
What happens if you create a couple of variables

Dim GosubCall As Bit
Dim MS_Count As Word

Modify the Isr

                   GosubCall = 1
           '        settings
           '        scan_display

and change the main loop

Do

DelayMS 1
Inc MS_Count

If MS_Count = 2000 Then
    read_temp_humidity
    MS_Count = 0
EndIf

If GosubCall = 1 Then
    settings
    scan_display
    GosubCall = 0
EndIf
                   
Loop

Regards,
Bob

Pepe

I already did a lot of tests and I couldn't get it to work.

top204

#6
I'm not fully sure what the project does in detail, but after re-formatting the firmware, it seems to work in the Proteus simulator. I have not changed the operation of the code, but made it more structured, and clearer to read.

On running the simulator with the modified 18F2550 firmware, there is a pause while the program sets things up, then the display cycles through temperature, humidity and time etc... Then when a button is pressed, the display changes.

    Device = 18F2550                                ' Tell the compiler what device to compile for
    Declare Xtal = 16                               ' Tell the compiler what frequency the device will be operating at (in MHz)
    Declare Onboard_USB = Off                       ' Tell the compiler not to create the USB variables
    Declare Auto_Heap_Strings = On                  ' Tell the compiler to create Strings above standard variables, so assembler code is more efficient
    Declare Auto_Variable_Bank_Cross = On           ' Tell the compiler to create any multi-byte variables in the same RAM bank. For more efficiency
    On_Hardware_Interrupt GoTo ISR_Handler          ' Point to the Interrupt Handler routine
'
' Pins
'
    Symbol SR_Data_Pin     = PORTB.0
    Symbol SR_Clock_Pin    = PORTB.2
    Symbol SR_Latch_Pin    = PORTB.1

    Symbol RTC_DTA_Pin     = PORTA.0
    Symbol RTC_CLK_Pin     = PORTA.2
    Symbol RTC_RST_Pin     = PORTA.1

    Symbol Temp_Pin        = PORTA.4
    Symbol DHT11_Pin       = PORTA.3

    Symbol Button_Up_Pin   = PORTB.4
    Symbol Button_Down_Pin = PORTB.5
    Symbol Button_Set_Pin  = PORTB.3
    Symbol Buzzer_Pin      = PORTB.7

    Symbol TMR1IE = PIE1.0                          ' Timer1 Overflow Interrupt Enable
    Symbol TMR1IF = PIR1.0                          ' Timer1 Overflow Interrupt tFlag bit
    Symbol PEIE = INTCON.6                          ' Peripheral Interrupt Enable
    Symbol GIE  = INTCON.7                          ' Global Interrupt Enable
'
' Variables
'
    Dim bSetupState     As Byte
    Dim tBlinkBit       As Bit
    Dim bTempVar        As Byte
    Dim bTens           As Byte
    Dim bOnes           As Byte
    Dim wMsTick         As Word
    Dim wScreenTick     As Word
    Dim bBa             As Byte
    Dim tSign           As Bit
    Dim wTempe          As Word
    Dim bKounter        As Byte = 0
    Dim bScreen_Mode    As Byte = 0
    Dim bSetup_Mode     As Byte
    Dim bButton_Counter As Byte = 0
    Dim bBlink_Mask     As Byte = $80
    Dim bTotal_Time     As Byte = 0
    Dim bDisplay_State  As Byte = 0
    Dim bT0             As Byte
    Dim bT1             As Byte
    Dim bT2             As Byte
    Dim bT3             As Byte
    Dim tFlag           As Bit = 0
    Dim bH1             As Byte
    Dim bH2             As Byte
    Dim bH3             As Byte
    Dim bButton         As Byte
    Dim bClock_Time     As Byte
    Dim bHumidity_Time  As Byte
    Dim bTemp_Time      As Byte
    Dim bDate_Time      As Byte
    Dim bDataIn         As Byte
    Dim bChkSum         As Byte
    Dim bIndex          As Byte
    Dim dSenData        As Dword
    Dim bHumidity       As Byte
    Dim bTemp           As Byte
    Dim tBlink_Toggle   As Bit = 0
    Dim tAdjust_Blink   As Bit = 0
    Dim bNum            As Byte
    Dim bHour           As Byte = 0
    Dim bMinute         As Byte = 0
    Dim bDay            As Byte
    Dim bMonth          As Byte
    Dim bYear           As Byte
    Dim bDay_Of_Week    As Byte
    Dim bSecond         As Byte
    Dim bVez            As Byte
    Dim wData1          As Word
    Dim wData2          As Word
    Dim wData3          As Word
    Dim wBlink_Delay    As Word
    Dim wTemperature    As SWord
    Dim bState          As Byte
    Dim wSR1            As Word
    Dim wSR2            As Word
    Dim wSR3            As Word

    Dim wTMR1_SFR       As TMR1L.Word  ' Permite acceder a TMR1H:TMR1L como palabra de 16 bits
'
' Display
'
    Dim bDigit_Dis[21] As Byte Heap = 64, 121, 36, 48, 25, 18, 2, 120, 0, 16, 175, 139, 156, 198, 255, 146, 136, 135, 131, 134, 140
                          '  [0,  1, 2, 3, 4, 5,6,  7,8, 9,  r,  H,  o,  bBlink_Mask,blank,S,  A,  t,  b,  E,  P]

'-----------------------------------------------------------------------------------------
' The main program starts here
'
Main:
    Setup()                                         ' Setup the program and any peripherals
    Do                                              ' Create a loop
        Read_Temp_Humidity()
        DelayMS 2000
    Loop                                            ' Do it forever

'-----------------------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    TRISA = %00011000
    TRISB = %1111000
    PORTA = 0
    PORTB = 0
'
' Initialise shift registers
'
    wData1 = $FFFF
    wData2 = $FFFF
    wData3 = $FFFF
    ShiftRegister_Write()
'
' Read times from EEPROM
'
    bClock_Time = ERead 1
    bDate_Time  = ERead 2
    bTemp_Time = ERead 3
    bHumidity_Time = ERead 4

    If bClock_Time > 20 Then bClock_Time = 20
    If bDate_Time > 20 Then bDate_Time = 20
    If bTemp_Time > 10 Then bTemp_Time = 5
    If bHumidity_Time > 10 Then bHumidity_Time = 5

    Read_Time()

    bTotal_Time = bClock_Time + bDate_Time + bTemp_Time + bHumidity_Time
    If bTotal_Time = 0 Then bDisplay_State = 0

    PinInput DHT11_Pin
    DelayMS 2000
'
' Timer1_Init
' Prescaler 1:4, reloj interno, Timer1 encendido
'
    T1CON = $31                                         ' TMR1ON=1, TMR1CS=0 (internal), T1CKPS1:T1CKPS0=01
'
' Cargar Timer1 para overflow de 500 ms
' Valor calculado: 65536 - 500ms*(Fosc/4)/Prescaler
' Con Fosc=4MHz ? 1 tick = 1 µs * 4/1 ? tick ~1 µs
' wTMR1_SFR = 65536 - 62000 ˜ 3936 = &H0F60
'
    wTMR1_SFR = $3CB6
'
' Activar interrupción de Timer1
'
    TMR1IE = 1
    PEIE = 1                                            ' Activar periféricos
    GIE = 1
EndProc

'-----------------------------------------------------------------------------------------
' Reset screen mode when in setup
' Input     :
' Output    :
' Notes     :
'
Proc Settings()
    If bSetup_Mode > 0 Then
        bScreen_Mode = 0
    EndIf
'
' Reset button counter if set button is not pressed
'
    If Button_Set_Pin <> 0 Then bButton_Counter = 0
'
' Check if any button is pressed
'
    If Button_Up_Pin = 0 Or Button_Down_Pin = 0 Or Button_Set_Pin = 0 Then
        '
        ' If set button pressed
        '
        If Button_Set_Pin = 0 Then
            Inc bButton_Counter
            If bButton_Counter = 2 Then
                Blink_Buzzer()
                bDisplay_State = 0
                bScreen_Mode = 0
                Inc bSetup_Mode
                bButton_Counter = 0
            EndIf
        EndIf
        '
        ' If up button pressed
        '
        If Button_Up_Pin = 0 Then
            Select bSetup_Mode
                Case 1
                    Inc bHour
                    If bHour >= 24 Then bHour = 0
                Case 2
                    Inc bMinute
                    If bMinute >= 60 Then bMinute = 0
                Case 3
                    Inc bSecond
                    If bSecond >= 60 Then bSecond = 0
                Case 4
                    Inc bDay
                    If bDay > 31 Then bDay = 1
                Case 5
                    Inc bMonth
                    If bMonth > 12 Then bMonth = 1
                Case 6
                    Inc bYear
                    If bYear > 99 Then bYear = 17
                Case 7
                    Inc bClock_Time
                    If bClock_Time > 20 Then bClock_Time = 0
                Case 8
                    Inc bDate_Time
                    If bDate_Time > 20 Then bDate_Time = 0
                Case 9
                    Inc bTemp_Time
                    If bTemp_Time > 10 Then bTemp_Time = 0
                Case 10
                    Inc bHumidity_Time
                    If bHumidity_Time > 10 Then bHumidity_Time = 0
            EndSelect
        EndIf
        '
        ' If down button pressed
        '
        If Button_Down_Pin = 0 Then
            Select bSetup_Mode
                Case 1
                    Dec bHour
                    If bHour < 0 Then bHour = 23
                Case 2
                    Dec bMinute
                    If bMinute < 0 Then bMinute = 59
                Case 3
                    Dec bSecond
                    If bSecond < 0 Then bSecond = 59
                Case 4
                    Dec bDay
                    If bDay < 1 Then bDay = 31
                Case 5
                    Dec bMonth
                    If bMonth < 1 Then bMonth = 12
                Case 6
                    Dec bYear
                    If bYear < 17 Then bYear = 99
                Case 7
                    Dec bClock_Time
                    If bClock_Time < 0 Then bClock_Time = 20
                Case 8
                    Dec bDate_Time
                    If bDate_Time < 0 Then bDate_Time = 20
                Case 9
                    Dec bTemp_Time
                    If bTemp_Time < 0 Then bTemp_Time = 10
                Case 10
                    Dec bHumidity_Time
                    If bHumidity_Time < 0 Then bHumidity_Time = 10
            EndSelect
        EndIf
        '
        ' If setup finished
        '
        If bSetup_Mode > 10 Then
            bTotal_Time = bClock_Time + bDate_Time + bTemp_Time + bHumidity_Time
            bScreen_Mode = 0
            If bTotal_Time = 0 Then bDisplay_State = 0
            '
            ' Save date and time
            '
            Write_Time()
            Read_Time()
            '
            ' Save settings to EEPROM
            '
            EWrite 1, [bClock_Time, bDate_Time, bTemp_Time, bHumidity_Time]
            bSetup_Mode = 0
        EndIf
    EndIf
EndProc

'-----------------------------------------------------------------------------------------
'
' Input     :
' Output    :
' Notes     :
'
Proc Read_Temp_Humidity()
    bState = Get_Hum()
    Do: Loop While bState <> 0
    Read_Sensor()
EndProc

'-----------------------------------------------------------------------------------------
' Write to the shift register
' Input     :
' Output    :
' Notes     :
'
Proc ShiftRegister_Write()
    For bBa = 0 To 47
        If bBa < 16 Then
            If wData1.15 = 0 Then
                PinLow SR_Data_Pin
            Else
                PinHigh SR_Data_Pin
            EndIf
            wData1 = wData1 << 1

        ElseIf bBa > 15 And bBa < 32 Then
            If wData2.15  = 0 Then
                PinLow SR_Data_Pin
            Else
                PinHigh SR_Data_Pin
            EndIf
            wData2 = wData2 << 1

        ElseIf bBa > 31 And bBa < 48 Then
            If wData3.15  = 0 Then
                PinLow SR_Data_Pin
            Else
                PinHigh SR_Data_Pin
            EndIf
            wData3 = wData3 << 1
        EndIf
        PinHigh SR_Clock_Pin
        PinLow SR_Clock_Pin
    Next
    PinHigh SR_Latch_Pin
    PinLow SR_Latch_Pin
EndProc

'-----------------------------------------------------------------------------------------
'
' Input     :
' Output    :
' Notes     :
'
Proc Scan_Display()
     bButton = Button_Up_Pin & Button_Down_Pin
'
' Blank display
'
    If bDisplay_State = 0 Then
        wData1 = 65535
        wData2 = 65535
        wData3 = 65535
    EndIf
    tFlag = 0
'
' Hour setting
'
    If bSetup_Mode > 0 And bSetup_Mode < 4 Then
        tFlag = 1
    Else
        tFlag = 0
    EndIf

    If bDisplay_State = 1 Or tFlag = 1 Then
        If tBlink_Toggle = 1 Then
            bBlink_Mask = $00
        Else
            bBlink_Mask = $80
        EndIf
        bNum = Dig bSecond, 0
        wData1 = bDigit_Dis[bNum] << 8
        bNum = Dig bSecond, 1
        wData1 = wData1 + bDigit_Dis[bNum] + bBlink_Mask
        bNum = Dig bMinute, 0
        wData2 = (bDigit_Dis[bNum] + bBlink_Mask) << 8
        bNum = Dig bMinute, 1
        wData2 = wData2 +  bDigit_Dis[bNum] + bBlink_Mask
        bNum= Dig bHour, 0
        wData3 = (bDigit_Dis[bNum] + bBlink_Mask) << 8
        bNum = Dig bHour, 1
        wData3 = wData3 +  bDigit_Dis[bNum]

        If tAdjust_Blink = 1 Then
            If bSetup_Mode = 1 And bButton = 1 Then
                wData3 = 32639 | bBlink_Mask
            EndIf
            If bSetup_Mode = 2 And bButton = 1 Then
                wData2 = 32639 | bBlink_Mask
            EndIf
            If bSetup_Mode = 3 And bButton = 1 Then
                wData1 = 32639 | bBlink_Mask
            EndIf
        EndIf
    EndIf

    Select bSetup_Mode
        '
        ' Clock time setting
        '
        Case  7
            bNum = Dig bClock_Time, 0
            wData1 = bDigit_Dis[bNum] << 8
            bNum = Dig bClock_Time, 1
            wData1 = wData1 + bDigit_Dis[bNum] + $80
            wData2 = (bDigit_Dis[17] << 8) + bDigit_Dis[16]
            wData3 = (bDigit_Dis[16] << 8) + bDigit_Dis[15]
            If tAdjust_Blink = 1 And bButton = 1 Then
                wData1 = 32767
            EndIf
        '
        ' Date time setting
        '
        Case 8
            bNum = Dig bDate_Time, 0
            wData1 = bDigit_Dis[bNum] << 8
            bNum = Dig bDate_Time, 1
            wData1 = wData1 + bDigit_Dis[bNum] + $80
            wData2 = (bDigit_Dis[11] << 8) + bDigit_Dis[10]
            wData3 = (bDigit_Dis[16] << 8) + bDigit_Dis[17]
            If tAdjust_Blink = 1 And bButton = 1 Then
                wData1 = 32767
            EndIf
        '
        ' Temperature time setting
        '
        Case 9
            bNum= Dig bTemp_Time, 0
            wData1 = bDigit_Dis[bNum] << 8
            bNum = Dig bTemp_Time, 1
            wData1 = wData1 + bDigit_Dis[bNum] + $80
            wData2 = (bDigit_Dis[14] << 8) + bDigit_Dis[14]
            wData3 = (bDigit_Dis[13] << 8) + bDigit_Dis[12]
            If tAdjust_Blink = 1 And bButton = 1 Then
                wData1 = 32767
            EndIf
        '
        ' Humidity time setting
        '
        Case  10
            bNum = Dig bHumidity_Time, 0
            wData1 = bDigit_Dis[bNum] << 8
            bNum = Dig bHumidity_Time, 1
            wData1 = wData1 + bDigit_Dis[bNum] + $80
            wData2 = (bDigit_Dis[14] << 8) + bDigit_Dis[14]
            wData3 = (bDigit_Dis[11] << 8) + bDigit_Dis[10]
            If tAdjust_Blink = 1 And bButton = 1 Then
                wData1 = 32767
            EndIf
    EndSelect

    tFlag = 0
    If bSetup_Mode > 3 And bSetup_Mode < 7 Then
        tFlag = 1
    EndIf
    If bDisplay_State = 2 Then
        tFlag = 1
    EndIf
'
' Date display
'
    If tFlag = 1 Then
        bNum = Dig bYear, 0
        wData1 = bDigit_Dis[bNum] << 8
        bNum = Dig bYear, 1
        wData1 = wData1 + bDigit_Dis[bNum] + $80
        bNum = Dig bMonth, 0
        wData2 = bDigit_Dis[bNum] << 8
        bNum = Dig bMonth, 1
        wData2 = wData2 + bDigit_Dis[bNum] + $80
        bNum = Dig bDay, 0
        wData3 = bDigit_Dis[bNum] << 8
        bNum = Dig bDay, 1
        wData3 = wData3 + bDigit_Dis[bNum]

        If tAdjust_Blink = 1 And bButton = 1 Then
            If bSetup_Mode = 4 Then
                wData3 = 32639
            EndIf
            If bSetup_Mode = 5 Then
                wData2 = 32767
            EndIf
            If bSetup_Mode = 6 Then
                wData1 = 32767
            EndIf
        EndIf
    EndIf
'
' Temperature display
'
    If bDisplay_State = 3 Then
        bT3 = Dig wTemperature, 0
        bT2 = Dig wTemperature, 1
        bT1 = Dig wTemperature, 2
        bT0 = Dig wTemperature, 3
        Select wTemperature
            Case 0
                wData3 = (bDigit_Dis[0] << 8) + bDigit_Dis[14]
                wData1 = (bDigit_Dis[13] << 8) + bDigit_Dis[12]
                wData2 = (bDigit_Dis[14] << 8) + bDigit_Dis[bT3] + $80
            Case 1 To 550
                If tSign= 0 Then
                    If wTemperature <100 Then
                        wData1 = (bDigit_Dis[13] << 8) + bDigit_Dis[12]
                        wData2 = (bDigit_Dis[14] << 8) + bDigit_Dis[bT3] + $80
                        wData3 = (bDigit_Dis[bT2] << 8) + bDigit_Dis[14]
                    Else
                        wData1 = (bDigit_Dis[13] << 8) + bDigit_Dis[12]
                        wData2 = (bDigit_Dis[14] << 8) + bDigit_Dis[bT3] + $80
                        wData3 = (bDigit_Dis[bT2] << 8) + bDigit_Dis[bT1]
                    EndIf
                Else
                    If wTemperature <100 Then
                        wData1 = (bDigit_Dis[13] << 8) + bDigit_Dis[12]
                        wData2 = (bDigit_Dis[14] << 8) + bDigit_Dis[bT3] + $80
                        wData3 = (bDigit_Dis[bT2] << 8) + 191
                    Else
                        wData1 = (bDigit_Dis[13] << 8) + bDigit_Dis[12]
                        wData2 = (( bDigit_Dis[14]) << 8) + bDigit_Dis[bT2]  + $80
                        wData3 = ((bDigit_Dis[bT1] + $80) << 8) + 191
                    EndIf
                EndIf
            Case  551 To 999
                wData1 = (bDigit_Dis[13] << 8) + bDigit_Dis[12]
                wData2 = (bDigit_Dis[14] << 8) + bDigit_Dis[bT3] + $80
                wData3 = (bDigit_Dis[bT2] << 8) + bDigit_Dis[bT1]
            Case Else
                wData1 = (bDigit_Dis[13] << 8) + bDigit_Dis[12]
                wData2 = (bDigit_Dis[14] << 8) + bDigit_Dis[bT2] + $80
                wData3 = ((bDigit_Dis[bT1] + $80) << 8) + bDigit_Dis[bT0]
        EndSelect
    EndIf
'
' Humidity display
'
    If bDisplay_State = 4 Then
        bH3 = Dig bHumidity, 0
        bH2 = Dig bHumidity, 1
        bH1 = Dig bHumidity, 2
        wData1 = (bDigit_Dis[11] << 8) + bDigit_Dis[10]
        wData2 = (bDigit_Dis[14] << 8) + bDigit_Dis[bH1] + $80
        wData3 = (bDigit_Dis[bH3] << 8) + bDigit_Dis[bH2]
    EndIf
    ShiftRegister_Write()
EndProc

'-----------------------------------------------------------------------------------------
'
' Input     :
' Output    :
' Notes     :
'
Proc Blink_Buzzer()
    High Buzzer_Pin
    For wBlink_Delay = 0 To 199
        DelayUS 1
    Next
    PinLow Buzzer_Pin
EndProc

'-----------------------------------------------------------------------------------------
' Setup Machine 1 a 10
' Input     :
' Output    :
' Notes     :
'
Proc SetupMode()
    bSetupState = 1

    While bSetupState <= 10
        If Button_Up_Pin = 0 Then
            Select bSetupState
                Case 1
                    Inc bHour
                Case 2
                    Inc bMinute
                Case 3
                    Inc bSecond
                Case 4
                    Inc bDay
                Case 5
                    Inc bMonth
                Case 6
                    Inc bYear
                Case 7
                    Inc bClock_Time
                Case 8
                    Inc bDate_Time
                Case 9
                    Inc bTemp_Time
                Case 10
                    Inc bHumidity_Time
            EndSelect
            PinSet Buzzer_Pin
            DelayMS 60
            PinClear Buzzer_Pin
            DelayMS 200
        EndIf

        If Button_Down_Pin = 0 Then
            Select bSetupState
                Case 1
                    Dec bHour
                Case 2
                    Dec bMinute
                Case 3
                    Dec bSecond
                Case 4
                    Dec bDay
                Case 5
                    Dec bMonth
                Case 6
                    Dec bYear
                Case 7
                    Dec bClock_Time
                Case 8
                    Dec bDate_Time
                Case 9
                    Dec bTemp_Time
                Case 10
                    Dec bHumidity_Time
            EndSelect
            PinSet Buzzer_Pin
            DelayMS 60
            PinClear Buzzer_Pin
            DelayMS 200
        EndIf

        If Button_Set_Pin = 0 Then
            Inc bSetupState
            PinSet Buzzer_Pin
            DelayMS 60
            PinClear Buzzer_Pin
            DelayMS 200
        EndIf
    Wend
EndProc

'-----------------------------------------------------------------------------------------
'
' Input     :
' Output    :
' Notes     :
'
Proc Get_Hum(), Byte
    dSenData = 0
    bChkSum = 0
    Result = 0
    PinOutput DHT11_Pin                         ' Configure connection pin as output
    PinLow DHT11_Pin                            ' Connection pin output low
    DelayMS 20
    PinHigh DHT11_Pin                           ' Connection pin output high
    DelayUS 26
    PinInput DHT11_Pin                          ' Configure connection pin as input

    bDataIn = PulseIn DHT11_Pin,High
    If bDataIn < 30 Then
        Result = 1
    Else
        For bIndex = 31 To 0 Step -1
            bDataIn = PulseIn DHT11_Pin, High    ' Recieve pulses from sensor
            If bDataIn > 18 Then
                LoadBit dSenData, bIndex, 2
            EndIf
        Next bIndex
        For bIndex = 7 To 0 Step -1
            bDataIn = PulseIn DHT11_Pin, High
            If bDataIn > 18 Then
                LoadBit bChkSum, bIndex, 2
            EndIf
        Next bIndex
        bHumidity = dSenData.Byte3
        bTemp = dSenData.Byte1
        If bChkSum <> bHumidity + bTemp Then
            Result = 2
        EndIf
    EndIf
EndProc

'-----------------------------------------------------------------------------------------
' Read DS1302
' Input     :
' Output    :
' Notes     :
'
Proc Read_Time()
    PinHigh RTC_RST_Pin
    PinOutput RTC_DTA_Pin
    SHOut RTC_DTA_Pin, RTC_CLK_Pin, 0, [$BF]    ' Read Command
    DelayUS 10
    PinInput RTC_DTA_Pin
    SHIn RTC_DTA_Pin, RTC_CLK_Pin, 1, [bSecond, bMinute, bHour, bDay, bMonth, bDay_Of_Week, bYear, bTempVar]  ' Read
    DelayUS 10
    bSecond = Convert(bSecond)
    bMinute = Convert(bMinute)
    bHour = Convert(bHour)
    bDay = Convert(bDay)
    bMonth = Convert(bMonth)
    bDay_Of_Week = Convert(bDay_Of_Week)
    bYear = Convert(bYear)
    PinLow RTC_RST_Pin
EndProc

'-----------------------------------------------------------------------------------------
' Write DS1302
' Input     :
' Output    :
' Notes     :
'
Proc Write_Time()
    bSecond = Reverse_Convert(bSecond)
    bMinute = Reverse_Convert(bMinute)
    bHour = Reverse_Convert(bHour)
    bDay = Reverse_Convert(bDay)
    bMonth = Reverse_Convert(bMonth)
    bDay_Of_Week = Reverse_Convert(bDay_Of_Week)
    bYear = Reverse_Convert(bYear)

    PinHigh RTC_RST_Pin
    SHOut RTC_DTA_Pin, RTC_CLK_Pin, 0, [$8E, 0]    ' Write protection disabled
    PinLow RTC_RST_Pin
    DelayUS 10
    PinHigh RTC_RST_Pin
    SHOut RTC_DTA_Pin, RTC_CLK_Pin, 0, [$BE, bSecond, bMinute, bHour, bDay, bMonth, bDay_Of_Week, bYear, 128] ' Write
    PinLow RTC_RST_Pin
    DelayUS 10
EndProc

'-----------------------------------------------------------------------------------------
' DS1302 Convert
' Input     :
' Output    :
' Notes     :
'
Proc Convert(pValue As Byte),Byte
    bTens = pValue & %01110000
    bTens = bTens >> 4
    bOnes = pValue & %00001111
    Result = (bTens * 10) + bOnes
EndProc

'-----------------------------------------------------------------------------------------
' DS1302 Reverse Convert
' Input     :
' Output    :
' Notes     :
'
Proc Reverse_Convert(pValue As Byte),Byte
    bTens = Dig pValue, 1
    bTens = bTens << 4
    bOnes = Dig pValue, 0
    Result = bTens + bOnes
EndProc

'-----------------------------------------------------------------------------------------
'
' Input     :
' Output    :
' Notes     :
'
Proc Read_Sensor()
    OWrite Temp_Pin, 1, [$CC, $44]                          ' Start wTemperature conversion
    DelayMS 200

    OWrite Temp_Pin, 1, [$CC, $BE]                          ' Read memory one byte
    ORead Temp_Pin, 2, [wTempe.LowByte, wTempe.HighByte]    ' Read two bytes
'
' wTemperature value stored in wTempe and calculations performed
'
    tSign  = 0
    If wTempe.11 = 1 Then
        wTempe = ~wTempe + 2                                ' For negative value invert bits: If number=%01, NOT %01 = %10
        tSign  = 1
    EndIf
    wTemperature = (wTempe * 10) / 16
EndProc

'-----------------------------------------------------------------------------------------
' Interrupt handler
' Input     :
' Output    :
' Notes     :
'
ISR_Handler:
    Context Save

    If TMR1IF = 1 Then
        TMR1IF = 0
        wTMR1_SFR = $3CB6
        Inc bVez
        If bVez = 5 Then
            bVez = 0
            If bKounter = 0 Or bKounter = 2 Then
                Toggle tBlink_Toggle
            EndIf

            If bSetup_Mode = 0 Then
                tAdjust_Blink = 0
                Read_Time()
            ElseIf bSetup_Mode > 0 Then
                Toggle tAdjust_Blink
            EndIf
            Settings()
            Scan_Display()
            Inc bKounter

            If bKounter = 4 Then
                bKounter = 0
                If bScreen_Mode < bClock_Time And bSetup_Mode = 0 And bClock_Time <> 0 Then
                    bDisplay_State = 1
                ElseIf bScreen_Mode < bClock_Time + bDate_Time And bScreen_Mode >= bClock_Time And bSetup_Mode = 0 And bDate_Time <> 0 Then
                    bDisplay_State = 2
                ElseIf bScreen_Mode < bClock_Time + bDate_Time + bTemp_Time And bScreen_Mode >= bClock_Time + bDate_Time And bSetup_Mode = 0 And bTemp_Time <> 0 Then
                    bDisplay_State = 3
                ElseIf bScreen_Mode < bTotal_Time And bScreen_Mode >= bClock_Time + bDate_Time + bTemp_Time And bSetup_Mode = 0 And bHumidity_Time <> 0 Then
                    bDisplay_State = 4
                EndIf
                If bScreen_Mode < bTotal_Time Then
                    Inc bScreen_Mode
                Else
                    bScreen_Mode = 0
                EndIf
            EndIf
        EndIf
    EndIf
    Context Restore

'-----------------------------------------------------------------------------------------
' Setup the config fuses
'
Config_Start
    PLLDIV = 1                            ' No prescale (4 MHz oscillator input drives PLL directly)
    CPUDIV = OSC1_PLL2                    ' [Primary Oscillator Src: /1][96 MHz PLL Src: /2]
    USBDIV = 1                            ' USB clock source comes directly from the primary oscillator block with no postscale
    FOSC = HS                            ' HS oscillator (HS)
    FCMEN = Off                            ' Fail-Safe Clock Monitor disabled
    IESO = Off                            ' Oscillator Switchover mode disabled
    PWRT = Off                            ' PWRT disabled
    BOR = On                            ' Brown-out Reset enabled in hardware only (SBOREN is disabled)
    BORV = 3                            ' Minimum setting 2.05V
    VREGEN = Off                        ' USB voltage regulator disabled
    WDT = Off                            ' WDT disabled (control is placed on the SWDTEN bit)
    WDTPS = 32768                        ' 1:32768
    CCP2MX = On                            ' CCP2 input/output is multiplexed with RC1
    PBADEN = Off                        ' PORTB<4:0> pins are configured as digital I/O on Reset
    LPT1OSC = Off                        ' Timer1 configured for higher power operation
    MCLRE = Off                            ' RE3 input pin enabled'  MCLR pin disabled
    STVREN = Off                        ' Stack full/underflow will not cause Reset
    LVP = Off                            ' Single-Supply ICSP disabled
    XINST = Off                            ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    Debug = Off                            ' Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
    Cp0 = Off                            ' Block 0 (000800-001FFFh) is not code-protected
    CP1 = Off                            ' Block 1 (002000-003FFFh) is not code-protected
    CP2 = Off                            ' Block 2 (004000-005FFFh) is not code-protected
    CP3 = Off                            ' Block 3 (006000-007FFFh) is not code-protected
    CPB = Off                            ' Boot block (000000-0007FFh) is not code-protected
    CPD = Off                            ' Data EEPROM is not code-protected
    WRT0 = Off                            ' Block 0 (000800-001FFFh) is not write-protected
    WRT1 = Off                            ' Block 1 (002000-003FFFh) is not write-protected
    WRT2 = Off                            ' Block 2 (004000-005FFFh) is not write-protected
    WRT3 = Off                            ' Block 3 (006000-007FFFh) is not write-protected
    WRTC = Off                            ' Configuration registers (300000-3000FFh) are not write-protected
    WRTB = Off                            ' Boot block (000000-0007FFh) is not write-protected
    WRTD = Off                            ' Data EEPROM is not write-protected
    EBTR0 = Off                            ' Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
    EBTR1 = Off                            ' Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
    EBTR2 = Off                            ' Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
    EBTR3 = Off                            ' Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks
    EBTRB = Off                            ' Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
Config_End

The modified firmware and hex files etc, are also attached to this post. There are quite a few changes that could be done to the firmware to make it more efficient, in both space and speed.

Regards
Les