Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LCD time setting code.

Status
Not open for further replies.
Hi all,

I hope all are in good health and spirits.

I wrote this code last night for my lcd clock/calendar. It works fine but maybe there is a more efficient code to achieve the objective. When setting the time the user can toggle the cursor betwen the tens of hours and the unit hours positions and increment the respective value. The code is to prevent any illegitimate values, i.e. any value more than 23.

Is there more efficient code you could suggest? With the benefit of hindsight it may have been more straightforward increment the hours value as a whole rather than as individual digits. But this is where I am at now.

Thanks in advance for any help / suggestions.


Code:
Increment_value

    movlw  high Digit_goto      ;get PCLATH at this location
    movwf  PCLATH               ;update PCLATH
    movf   cursor_cnt,w         ;no. of times user has right shifted cursor
    andlw  0x07                 ;clear upper nybble
    rlncf  WREG,W               ;double it
    rlncf  WREG,w               ;and again (because of x2 pc increments)
    addwf  PCL                  ;add it (cursor shift count x4) to prog counter low byte  
     
Digit_goto    
    goto    tenhrs
    goto    unithrs
    goto    tenmins
    goto    unitmins
    goto    tendays
    goto    unitdays
    goto    tenmonths
    goto    unitmonths
    goto    tenyrs
    goto    unityrs

;CUMBERSOME CODE STARTS HERE!

tenhrs              ;increment the ten hours value - check for legitimate number
    incf    H10
    movlw   0x34    ;(4)
    cpfslt  H1      ;unit hrs < 4? 
    goto    skip3   ;no, it's 4 or more so max value for tenhrs is 2 (23hrs max)
    movlw   0x32    ;yes, unit hrs less than 4 so 2 is valid value for tenhrs   
    cpfsgt  H10     ;user trying to set tenhrs>2?
    goto    skip1   ;no, so unit hrs value irrelevant
skip3
    movlw   0x31    ;(1)   
    cpfsgt  H10     ;tenhrs >1?
    goto    skip1
    movlw   0X30    ;set tenhrs = 0
    movwf   H10    
skip1               ;write the tenhrs value to the lcd
    movf    H10,W                     
    call    lcd_char                    ;write tenhrs value to lcd
    call    R2C10                       ;cursor back to Row2 Col10 (tenhrs position)
    call    Wait_for_yell_butt_release
    return    

           
unithrs ;increment the unit hours value - legitimate number? Depends on tenhrs value
    incf    H1          ;unit hours register
    movlw   0x32        ;determine if tens of hours is = 2, so   
    subwf   H10,w       ;subtract 2 from tenhrs value
    movlw   0x33        ;3 = default max value for unit hrs 
    btfss   STATUS,Z    ;was tenhrs = 2?
    movlw   0x39        ;no, max unit hrs value will be 9
    cpfsgt  H1          ;yes, unit hrs max will be default 3, compare with user value
    goto    skip2       ;write unit hrs value to lcd   
    movlw   0X30        ;user tried to enter more than 3 when tenhrs = 2 so reset to 0
    movwf   H1          ;set unit hrs to zero    
skip2               ;write the unithrs value to the lcd
    movf    H1,W                     
    call    lcd_char
    call    R2C11
    call    Wait_for_yell_butt_release
    return

tenmins
    nop
unitmins
    nop
tendays
    nop
unitdays
    nop
tenmonths
    nop
unitmonths
    nop
tenyrs
    nop
unityrs
    nop   
    
loiter    
    goto    loiter

**broken link removed**
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top