?? fet4xx_rtcwlcd.s43
字號:
#include "device.h"
#define _def_clock
#include "fet4xx_rtclcd.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 #028h,HOUR ;28 days elapsed?
jlo EndUpdateClock ;no, jump to end
cmp.b #002h,MONTH ;Feb.?
jeq IncMonth
bit.b #01h,MONTH ;test if Month with 30/31 days
jnz month31
cmp.b #031h,HOUR ;30 days elapsed?
jlo EndUpdateClock ;no, jump to end
jmp IncMonth
month31
cmp.b #032h,HOUR ;31 days elapsed?
jlo EndUpdateClock ;no, jump to end
IncMonth
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
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
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
; R14 is position
; pos = 0 means right aligned digit / 1 digit are 2 steps
;-------------------------------------------------------------------------------
;void Char2LCD (unsigned char, unsigned char pos)
_Char2LCD:
Char2LCD
sub #'0',R12 ;subtract of set of char '0'
_BCD2LCD:
BCD2LCD
rla R12 ;transform for word table
mov LCD_Tab(R12),R12 ;LCD value to R13
_Direct2LCD:
Direct2LCD
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -