Two line LCD double height numbers, possible ???


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Two line LCD double height numbers, possible ???

    That looks great Shawn for my future projects but not for my timer.
    I was incorrect about my display, I used a 2x16 as well but I need to display say, 123.45 so the thinner dual height figures are just what I want. I believe i can't use them anyway.
    Melanies code is quite 'timing' critical as it should be, so I think adding the character code lookup would cause it's timing to be incorrect. I need to study it all again when I get time as I made this a year ago. I do believe there's an 'offset' in the code I can use to bring it back to correct timing I just need to experiment.

    This is Melanies slightly modified code for seconds and hundreths, this uses a 16f628

    Code:
        ' Show Jumping Timer 2011 based on Olympic Timer by Melanie Newman
    '       05/Aug/2004
    '       Topical Program demonstrates use of Interrupt
    '       Driven Background TIMER, to time events down to
    '       one one-hundredth of a Second (1/100 Sec).
    '
    '       Bonus CALIBRATION Feature allows simple adjustments
    '       in 360mS steps per hour. This calibration adjustment
    '       range is limited to +/- 36 seconds per Hour.
    '
    '       This program is for 4MHz clock (1uS Timer Ticks).
    '
    '       PIC Defines
    '       ===========
    '
    '       Change these defines to suit your chosen PIC
    '
    @ DEVICE  pic16F628, XT_OSC    ' System Clock Options
    @ DEVICE  pic16F628, WDT_ON    ' Watchdog Timer
    @ DEVICE  pic16F628, PWRT_ON   ' Power-On Timer
    @ DEVICE  pic16F628, BOD_ON    ' Brown-Out Detect
    @ DEVICE  pic16F628, LVP_OFF   ' Low-Voltage Programming
    @ DEVICE  pic16F628, CPD_OFF   ' Data Memory Code Protect
    @ DEVICE  pic16F628, PROTECT_OFF
                                   ' Program Code Protection
    @ DEVICE pic16F628, WRT_OFF    ' Flash Memory Word Enable
    '
    '       Hardware Defines
    '       ================
            '
            '       LCD Display
            '       -----------
            '       Adjust these to suit your chosen LCD pinout
            '
    Define LCD_DREG PORTB          ' Port for LCD Data
    Define LCD_DBIT 4              ' Use upper 4 bits of Port
    Define LCD_RSREG PORTB         ' Port for RegisterSelect (RS) bit
    Define LCD_RSBIT 3             ' Port Pin for RS bit
    Define LCD_EREG PORTB          ' Port for Enable (E) bit
    Define LCD_EBIT 1              ' Port Pin for E bit
    Define LCB_BITS 4              ' Using 4-bit bus
    Define LCD_LINES 2             ' Using 2 line Display
    Define LCD_COMMANDUS 2000
                                   ' Command Delay (uS)
    Define LCD_DATAUS 50           ' Data Delay (uS)
              '
            '      Control Buttons/Lines
            '      ---------------------
    ButStart var PortA.0          ' Take this pin low momentarily to START timing
    ButStop var PortA.1           ' Take this pin low momentarily to STOP timing
    ButReset var PortA.2          ' Take this pin low momentarily to RESET clock
            '
            '      Hold the RESET Button pressed for at least FIVE seconds
            '      to jump into CALIBRATION Mode
    '
    '       Software Defines
    '       ----------------
    BannerOffset var BYTE         ' Variable holding start address of Banner Display
    CounterA var BYTE             ' Just a Counter
    CounterB var BYTE             ' Just a Counter
    CounterC var BYTE
    DataA var BYTE
    'Hours var BYTE
    Hundredths var BYTE
    'Minutes var BYTE
    OverflowError var BIT
    RunningFlag var BIT
    Seconds var BYTE
    SetupTimeOut var WORD         ' Timeout counter for Calibration/Set-Up Mode
    TMR1Cal var BYTE              ' Calibration Value
                  TMR1CalAR var Byte             ' Calibration 0=ADVANCE, 1=RETARD
            TMR1RunOn var WORD             ' variable holding TMR1 Run-On value
            '
            '       EEPROM Presets
            '       --------------
            Data @0,0                      ' Advance/Retard Indicator
            Data 0                         ' Calibration Value
            Data "Show Jumping Seconds Timer - Robert Lane 2011"
            '
            '       Software Constants
            '       ------------------
            TMR1CalMax con 100             ' Maximum adjustment (+/-100uS per 10mS interrupt)
            TMR1Preset con $D910           ' 10mS Timer Reload value, offset by 20uS
                                           ' to allow for TMR1 Setting Calculations
            '
            '       Start Program
            '       =============
                    '
                    '       Initialise Processor
                    '       --------------------
            TRISA=000000
            TRISB=000111
            'TRISC=000000
            ADCON0=000000
            ADCON1=000111
            OPTION_REG.7=0                 ' Enable Pull-Up's
            RunningFlag=0                   ' Disable actual Interrupt Time-Keeping
            Pause 1000                     ' Pause for LCD to initialise
                           '
                           '        Silly Intro Banner just for Fun
                           '        -------------------------------
            LCDOut $FE,1                   ' Clear LCD
            BannerOffset=2:Gosub DisplayBanner
            Pause 2000
            For CounterA=0 to 30
                    BannerOffset=2+CounterA
                    Gosub DisplayBanner
                    Pause 150
                    Next CounterA
            Pause 1000
                    '
                    '       Initialise TMR1 Interrupts
                    '       --------------------------
            Gosub SetTimer                 ' Set the Timer for next 10mS Interrupt
            On Interrupt goto TickCount
            PIE1.0=1                       ' Enable TMR1 Interrupts
            INTCON.6=1                     ' Enable all unmasked Interrupts
            INTCON.7=1                     ' Enable Global Interrupts
                    '
                    '       -----------------------------------------------------
                    '       Following the above "On Interrupt", no Basic Command
                    '       is allowed that takes more than 10mS to execute
                    '       otherwise the 10mS Interrupt interval is compromised.
                    '       -----------------------------------------------------
                    '
                    '       Reset Timer Variables for Start
                    '       -------------------------------
    DisplayReset:
            LCDOut $FE,1                   ' Clear LCD
            Read 0,TMR1CalAR               ' Read Calibration Advance/Retard Indicator
            Read 1,TMR1Cal                 ' Read Calibration Value
            Hundredths=0                   ' Reset Timer Counter variables
            Seconds=0
            'Minutes=0
            'Hours=0
            OverflowError=0
            '
            '       Main Program Loop
            '       =================
            Enable
    DisplayLoop:
            If ButStart=0 then RunningFlag=1
            If ButStop=0 then RunningFlag=0
           ' LCDOut $FE,$80,DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds,".",DEC2 Hundredths
           LCDOut $FE,$80,DEC2 Seconds,".",DEC2 Hundredths
               If OverflowError=1 then
                    If Seconds.0=1 then
                           LCDOut $FE,$8C,"ERR"
                           else
                           LCDOut $FE,$8C,"    "
                           endif
                    endif
            If RunningFlag=1 then goto DisplayLoop
            If ButReset=1 then goto DisplayLoop
            Disable
            '
            '       Reset Clock
            '       ===========
            '       Momentarily Press the Reset Button for RESET action.
            '       Continue holding the Reset Button for MORE than 5 seconds
            '       to jump into Calibration/Set-Up Mode
            '
    ResetClock:
            LCDOut $FE,1,"Reset OK"
            Pause 1000
            Seconds=1
            While Seconds < 5
                    Pause 1000
                    If ButReset=1 then goto DisplayReset
                    Seconds=Seconds+1
                    Wend
            '
            '       Calibration Adjustment
            '       ======================
            '       If No Button is Pressed for 20 Seconds, then the program
            '       will automatically exit Calibration/Set-Up Mode WITHOUT saving
            '       any new values.
            '
            SetUpTimeout=0
    Calibration:
            LCDOut $FE,1,"Calibrate: "
            While ButReset=0:Wend          ' Wait for User to release finger
    CalibrationLoop:
            LCDOut $FE,$8B
            If TMR1Cal=0 then
                    LCDOut " "
                    else
                    If TMR1CalAR=0 then
                           LCDOut "+"
                           else
                           LCDOut "-"
                           endif
                    endif
            LCDOut #TMR1Cal," "
                    '       ----------------------------------------------------------
                    '       Press Start Button to ADVANCE (speed-up) Clock
                    '       Press STOP Button to RETARD (slow-down) Clock
                    '       Press RESET Button to SAVE new Calibration Setting
                    '       ----------------------------------------------------------
                    '       Remember each Calibration 'tick' will advance or
                    '       retard the Timing by 1uS in every 10mS period - that's
                    '       360mS/Hour per setting. Example: A setting of +8 will
                    '       SPEED-UP the Timer by 2.88 Seconds (8 x 360mS) in an Hour.
                    '       ----------------------------------------------------------
            If TMR1CalAR=0 then
                    If ButStart=0 then Gosub CalAdvance
                    If ButStop=0 then Gosub CalRetard
                    else
                    If ButStart=0 then Gosub CalRetard
                    If ButStop=0 then Gosub CalAdvance
                    endif
            If ButReset=0 then
                    Write 0,TMR1CalAR
                    Write 1,TMR1Cal
                    LCDOut $FE,1,"Bye Rob"
                    Pause 1000
                    Goto DisplayReset
                    endif
            SetupTimeout=SetupTimeout+1
            If SetupTimeout>200 then goto DisplayReset
            Pause 100
            Goto CalibrationLoop
                    '
            '       Subroutine Increments Calibration Value
            '       ---------------------------------------
    CalAdvance:
            SetupTimeout=0
            If TMR1Cal=>TMR1CalMax then
                    TMR1Cal=TMR1cALmAX
                    TMR1CalAR=TMR1CalAR^1
                    else
                    TMR1Cal=TMR1Cal+1
                    endif
            Return
            '
            '       Subroutine Decrements Calibration Value
            '       ---------------------------------------
    CalRetard:
            SetupTimeout=0
            If TMR1Cal=0 then
                    TMR1Cal=1
                    TMR1CalAR=TMR1CalAR^1
                    else
                    TMR1Cal=TMR1Cal-1
                    endif
            Return
            '
            '       Subroutine Displays Banner Intro
            '       --------------------------------
    DisplayBanner:
            CounterC=BannerOffset+15
            LCDOut $FE,$80
            For CounterB=BannerOffset to CounterC
                    Read CounterB,DataA
                    LCDOut DataA
                    Next CounterB
            Return
            '
            '       Subroutine Loads TMR1 values
            '       ============================
    SetTimer:
            T1CON.0=0                     ' Stop the Clock
            TMR1RunOn.Highbyte=TMR1H       ' Load the Run-On (Over-Run) value (if any)
            TMR1RunOn.Lowbyte=TMR1L
            TMR1RunOn=TMR1Preset+TMR1RunOn
                                          ' Calculate the New (adjusted) value for TMR1
            If TMR1CalAR=0 then            ' Calibration ADVANCE (add) or RETARD (subtract)
                    TMR1RunOn=TMR1RunOn+TMR1Cal
                    else
                    TMR1RunOn=TMR1RunOn-TMR1Cal
                    endif
            TMR1H=TMR1RunOn.Highbyte       ' Save new values to TMR1
            TMR1L=TMR1RunOn.Lowbyte
            T1CON.0=1                     ' Restart the Clock
            PIR1.0=0                      ' Reset TMR1's Interupt Flag
            Return
            '
            '       Timer Interrupt Handler
            '       =======================
    TickCount:
            Gosub SetTimer                ' Set the Timer for next 10mS Interrupt
            If RunningFlag=1 then          ' If timing actually enabled... then...
                    Hundredths=Hundredths+1
                                          ' Increment 10mS Seconds Counter
                    If Hundredths>99 then
                           Hundredths=0
                           Seconds=Seconds+1
                           
                            ' Increment the Seconds -- Show Jumping to 500
                           If Seconds>500 then
                                   Seconds=0
                                   endif
                           
                           
                           
                                          ' Increment the Seconds
                        '   If Seconds>59 then
                         '          Seconds=0
                           '        Minutes=Minutes+1
                                          ' Increment the Minutes
                             '      If Minutes>59 then
                              '            Minutes=0
                                '          Hours=Hours+1
                                          ' Increment the Hours
                            ' If Hours>99 then
                             ' Handle any Overflow
                              '      Hours=0
                             '       OverFlowError=1
                              '      endif
                            ' endif
                      ' endif
                 endif
           endif
    Resume
    End

  2. #2
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158


    Did you find this post helpful? Yes | No

    Default Re: Two line LCD double height numbers, possible ???

    Yes these digits are a display hog They will work well for me since I will be displaying time and temperature.
    Shawn

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts