📄 fet4xx_rtcwlcd.s43
字号:
#include "device.h"
#define _def_clock
#include "fet4xx_rtclcd.h"
#include "parameter.h"
;*******************************************************************************
;
; Description "FET410_RTCwLCD": This program maintains a real time clock and
; displays the current time on a 3.5 digit static LCD. The colon between the
; minutes and seconds toggles on or off each second to indicate that the clock
; is running. The digits of the display are only rewritten each minute once
; the elapsed seconds roll over from 60 back to 0. The fourth digit is
; automatically blank for hours 1-9. The software is totally interrupt driven.
; It only comes out of low power mode 3 and executes code when a Basic Timer
; interrupt occurs, once each second.
;
;--------CPU register used------------------------------------------------------
;;;;;;; R13, R14, R15 ;used as temporary registers, can
;be reused
;--------RAM bytes used for variables-------------------------------------------
#if __VER__ < 200
RSEG UDATA0
#else
RSEG DATA16_Z
#endif
_SEC
SEC DS 1 ;
_MIN
MIN DS 1 ;
_HOUR
HOUR DS 1 ;
_DAY
DAY DS 1 ;
_MONTH
MONTH DS 1 ;
_YEAR
YEAR DS 1 ;
even
;-------------------------------------------------------------------------------
RSEG CODE ;Program reset
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
; Increment clock values every second
;-------------------------------------------------------------------------------
_UpdateClock:
UpdateClock
setc ;entry every second
dadc.b SEC ;increment seconds, add carry bit
cmp.b #060h,SEC ;one minute elapsed?
jlo EndUpdateClock ;no, (C = 0) w/o LCD update
clr.b SEC ;yes, clear seconds (C = 1)
Clock1 dadc.b MIN ;increment minutes if set carry
cmp.b #060h,MIN ;sixty minutes elapsed?
jlo EndUpdateClock ;no, jump to end
clr.b MIN ;yes, clear minutes
dadc.b HOUR ;increment hour
cmp.b #024h,HOUR ;24 hours elapsed?
jlo EndUpdateClock ;no, jump to end
mov.b #00h,HOUR ;yes, set hours back to 0 &
dadc.b DAY ;increment DAY
cmp.b #002h,MONTH ;Feb.?
jeq February
cmp.b #008h,MONTH ;Jan thru July?
jlo earlyyear
;lateyear ; Aug-Dec Even months have 31 days
bit.b #01h,MONTH ;test if Month with 30/31 days
jz month31
jmp month30
earlyyear ; Jan-July Odd months have 31 days
bit.b #01h,MONTH ;test if Month with 30/31 days
jnz month31
jmp month30
February
bit.b #03h,YEAR ;Test for leap year (2 lowest bits == 0)
jz month29 ;
;month28
cmp.b #029h,DAY ;28 days elapsed?
jge IncMonth ;yes, inc month
jmp EndUpdateClock ;no, jump to end
month29
cmp.b #030h,DAY ;29 days elapsed?
jge IncMonth ;yes, inc month
jmp EndUpdateClock ;no, jump to end
month30
cmp.b #031h,DAY ;30 days elapsed?
jge IncMonth ;yes, inc month
jmp EndUpdateClock ;no, jump to end
month31
cmp.b #032h,DAY ;31 days elapsed?
jge IncMonth ;yes, inc month
jmp EndUpdateClock ;no, jump to end
IncMonth
mov.b #01, DAY ; Set day to 1
dadc.b MONTH ;increment MONTH
cmp.b #013h,MONTH ;12 Months elapsed?
jlo EndUpdateClock ;no, jump to end
mov.b #01h,MONTH ;yes, set month back to 1
dadc.b YEAR ;increment YEAR
; jmp EndUpdateClock ;jump to end
EndUpdateClock
; call #Dis_Clock
ret
;-------------------------------------------------------------------------------
; Display clock values contained in RAM Bytes MIN & HOUR.
; CPU Registers R12, R13 and R14 used temporarily.
;-------------------------------------------------------------------------------
_Dis_Clock:
Dis_Clock
push R12 ;Save Registers
push R14
mov.b #LCDM2,R14; ;R15 points to first LCD location
mov.b SEC,R12 ;second BCD value to R14
call #Display_BCD ;call routine to display minutes
mov.b MIN,R12 ;minute BCD value to R14
call #Display_BCD ;call routine to display minutes
mov.b HOUR,R12 ;hour BCD value to R14
call #Display_BCD ;call routine to display hours
mov.b SEC,R12 ;second BCD value to R14
and.b #01h,R12 ;get second tick
jz End_CLK
bis.b #colon,-6(R14) ;toggle Colon
bis.b #colon,-10(R14) ;toggle Colon
End_CLK
pop R14 ;Restore Registers
pop R12
NoUpdate_CLk
ret ;return to Basic Timer ISR
_Dis_Date:
Dis_Date
push R12 ;Save Registers
push R14
mov.b #LCDM2,R14; ;R15 points to first LCD location
mov.b YEAR,R12 ;year BCD value to R12
call #Display_BCD ;call routine to display minutes
#if date_format == MMDDYY // US Format
mov.b DAY,R12 ;day BCD value to R12
call #Display_BCD ;call routine to display hours
mov.b MONTH,R12 ;month BCD value to R12
call #Display_BCD ;call routine to display minutes
#else // European Format
mov.b MONTH,R12 ;month BCD value to R12
call #Display_BCD ;call routine to display minutes
mov.b DAY,R12 ;day BCD value to R12
call #Display_BCD ;call routine to display hours
#endif
mov.b SEC,R12 ;second BCD value to R14
and.b #01h,R12 ;get second tick
jz End_Date
bis.b #dp,-6(R14) ;toggle Dobble point
bis.b #dp,-10(R14) ;toggle dobble point
End_Date
pop R14 ;Restore Registers
pop R12
NoUpdate_CLK
ret ;return to Basic Timer ISR
;Write an BCD value into the Display
;The BCD value consists of 2 Digits
;R12 contains the the BCD value
;R14 indicates the possition on the LCD where the values should be displayed
; 0 is the right border / one digit are two steps
_Display_BCD:
Display_BCD
push R13 ;save R13
push R12
and #0Fh,R12 ;get low nibble
rla R12 ;transform for word table
mov LCD_Tab(R12),R13 ;LCD value to R13
mov.b R13,0(R14) ;low byte to LCD
swpb R13
mov.b R13,1(R14) ;high byte to LCD
add #2,R14 ;increase R14 (LCD mem pointer)
pop R12
rra R12 ; get high nibble
rra R12
rra R12
bic #01h,R12
mov LCD_Tab(R12),R13 ;LCD value to R13
mov.b R13,0(R14) ;low byte to LCD
swpb R13
mov.b R13,1(R14) ;high byte to LCD
add #2,R14 ;increase R14 (LCD mem pointer)
pop R13 ;restore R13
ret ;return to Dis_Clock routine
;-------------------------------------------------------------------------------
; Display 1 digit on static LCD. CPU Registers R12, R14 are used
; for the parameters
; R12 is char (R15 in CROSSWORKS)
; R14 is position
; pos = 0 means right aligned digit / 1 digit are 2 steps
;-------------------------------------------------------------------------------
;void Char2LCD (unsigned char, unsigned char pos)
#ifndef __CROSSWORKS__
_Char2LCD:
Char2LCD
sub #'0',R12 ;subtract offset of char '0'
_BCD2LCD:
BCD2LCD
rla R12 ;transform for word table
mov LCD_Tab(R12),R12 ;LCD value to R13
_Direct2LCD:
Direct2LCD
rla R14 ;position for word table (2 bytes per char)
mov.b R12,LCDM2(R14) ;low byte to LCD
swpb R12
mov.b R12,LCDM3(R14) ;high byte to LCD
add #2,R14 ;increase R14 (LCD mem pointer)
ret
;-------------------------------------------------------------------------------
_setPoint:
setPoint
rla R12 ;position for word table (2 bytes per char)
bis.b #dp,LCDM2(R12) ;low byte to LCD
ret
;-------------------------------------------------------------------------------
_setColon:
setColon
rla R12 ;position for word table (2 bytes per char)
bis.b #colon,LCDM2(R12) ;Turn on colon
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -