?? main.asm
字號:
;*****************************************************
;
; This programme is for study Ver1.0.0 beta
; The main control programe
;This programme must be run in 12MHz standard settings
; Designer: cqmcu.com
; Copyright 2007 koiistudio
;
;*****************************************************
;*****************************************************
;參數定義
;*****************************************************
beep bit p1.5 ;蜂鳴器引腳
digital_bit equ 08h ;顯示位
keys_byte equ 09h ;按鍵字節
digital_flash_time equ 0ah ;閃爍計時
digital_flash_bit equ 0bh ;閃爍位
aleart_data equ 0ch ;時間報警字節(連續兩字節)
aleart_byte equ 0eh ;報警設置字節
digital_byte equ 10h ;顯存首址,連續8字節為顯存
date_data equ 20h ;時鐘數據首地址
;*****************************************************
;主程序
;*****************************************************
org 0000h
jmp start
org 000bh
jmp time_int
org 0013h
jmp keys_int
org 0030h
start: mov p0,#0
mov p1,#0fh
mov p2,#0
mov p3,#0ffh
mov sp,#60h ;堆棧地址
mov r0,#7fh ;Clear the ram
clr a
main_clear0: mov @r0,a
djnz r0,main_clear0
mov digital_bit,#1
mov r0,#aleart_data ;默認的報警時間
mov @r0,#00h ;分
inc r0
mov @r0,#07h ;時
call timer_set
call iicread
setb ex0
setb ex1
setb ea
call beep1
main_wait: call digital
mov a,keys_byte
cjne a,#0,keysmanagement
jmp main_wait
keysmanagement: call keys_management
mov keys_byte,#0
jmp main_wait
;*****************************************************
;子程序文件載入
;*****************************************************
;*****************************************************
;時間報警校驗程序
;*****************************************************
aleart_check: mov a,#date_data
add a,#3
mov r0,a
mov r1,#aleart_data
mov a,@r0
mov r3,a
mov a,@r1
cjne a,03h,aleart_check_ret
inc r0
inc r1
mov a,@r0
mov r3,a
mov a,@r1
cjne a,03h,aleart_check_ret
call beep3
aleart_check_ret: ret
;*****************************************************
;短鳴一聲
;*****************************************************
beep1: mov 1fh,#04h
setb beep
beep1_1: lcall digital
lcall digital
lcall digital
lcall digital
lcall digital
lcall digital
djnz 1fh,beep1_1
clr beep
ret
;*****************************************************
;長鳴一聲
;*****************************************************
beep2: mov 1fh,#1eh
setb beep
beep2_1: lcall digital
lcall digital
lcall digital
lcall digital
lcall digital
lcall digital
djnz 1fh,beep2_1
clr beep
ret
;*****************************************************
;短鳴兩聲
;*****************************************************
beep3: mov 1fh,#04h
setb beep
beep3_1: lcall digital
lcall digital
lcall digital
lcall digital
lcall digital
lcall digital
djnz 1fh,beep3_1
clr beep
mov 1fh,#04h
beep3_2: lcall digital
lcall digital
lcall digital
lcall digital
lcall digital
lcall digital
djnz 1fh,beep3_2
setb beep
mov 1fh,#04h
beep3_3: lcall digital
lcall digital
lcall digital
lcall digital
lcall digital
lcall digital
djnz 1fh,beep3_3
clr beep
ret
;*****************************************************
;數碼管顯示
;*****************************************************
digital: mov a,digital_bit ;根據顯示位置讀取不同的顯示內容
jb acc.0,digital_check0
jb acc.1,digital_check1
jb acc.2,digital_check2
jb acc.3,digital_check3
jb acc.4,digital_check4
jb acc.5,digital_check5
jb acc.6,digital_check6
jb acc.7,digital_check7
call beep2
ret
digital_check0: mov r0,#digital_byte
mov a,@r0 ;秒
jmp digital_display
digital_check1: mov r0,#digital_byte
inc r0
mov a,@r0
jmp digital_display
digital_check2: mov r0,#digital_byte ;分
inc r0
inc r0
mov a,@r0
setb acc.4 ;加小數點
jmp digital_display
digital_check3: mov a,#digital_byte
add a,#3
mov r0,a
mov a,@r0
jmp digital_display
digital_check4: mov a,#digital_byte ;時
add a,#4
mov r0,a
mov a,@r0
setb acc.4 ;加小數點
jmp digital_display
digital_check5: mov a,#digital_byte
add a,#5
mov r0,a
mov a,@r0
anl a,#83h ;屏蔽無效位
jmp digital_display
digital_check6: mov a,#digital_byte
add a,#6
mov r0,a
mov a,#20h
jmp digital_display
digital_check7: mov a,#digital_byte
add a,#7
mov r0,a
mov a,#20h
digital_display: push acc
mov a,digital_flash_time
anl a,#7fh ;最高位表示顯示狀態:1為顯示;0為不顯示;其余位為記數值
cjne a,#80,digital_display_00
mov a,digital_flash_time
cpl acc.7
anl a,#80h
mov digital_flash_time,a
jmp digital_display_01
digital_display_00: inc digital_flash_time
digital_display_01: pop acc
jb acc.7,digital_display_1 ;最高位表示現在是否選擇了該位,若是則閃爍
digital_display_0: mov dptr,#data_tab_digital
movc a,@a+dptr
cpl a ;數據是共陰數碼管的,用在共陽數碼管上就需要取反
mov p2,#0
mov p0,a
mov a,digital_bit
mov p2,a
rl a
mov digital_bit,a
call time2_5ms
ret
digital_display_1: push acc
mov a,digital_flash_time
jb acc.7,digital_display_2
pop acc ;若最高位為零則消隱
mov a,#20h
jmp digital_display_0
digital_display_2: pop acc ;否則正常顯示
clr acc.7
jmp digital_display_0
;*****************************************************
;共陰數碼管顯示數據
;排列為:0-F, 0.-F.
;端口排列:p07 p06 p05 p04 p03 p02 p01 p00
;段排列為: d dp e c g b f a
;*****************************************************
data_tab_digital: db 0b7h,014h,0adh,09dh,01eh,09bh,0bbh,015h
db 0bfh,09fh,03fh,0bah,0a8h,0bch,0abh,02bh
db 0f7h,054h,0edh,0ddh,05eh,0dbh,0fbh,055h
db 0ffh,0dfh,07fh,0fah,0e8h,0fch,0ebh,06bh
db 000h
;*****************************************************
;參數定義
;*****************************************************
scl bit p1.6 ;時鐘引腳
sda bit p1.7 ;數據引腳
;*****************************************************
;時鐘數據設置
;*****************************************************
timer_set: mov r0,#date_data ;時鐘相關設置
mov @r0,#0 ;Control status 1
inc r0
mov @r0,#11h ;Control status 2
inc r0
mov @r0,#00h ;Seconds
inc r0
mov @r0,#15h ;Minutes
inc r0
mov @r0,#15h ;Hours
inc r0
mov @r0,#30h ;Days
inc r0
mov @r0,#07h ;Weekdays
inc r0
mov @r0,#03h ;Months
inc r0
mov @r0,#03h ;Years
inc r0
mov @r0,#80h ;Minute alarm
inc r0
mov @r0,#80h ;Hour alarm
inc r0
mov @r0,#80h ;Day alarm
inc r0
mov @r0,#80h ;Weekday alarm
inc r0
mov @r0,#83h ;CLKout control
inc r0
mov @r0,#82h ;Timer control
inc r0
mov @r0,#01h ;Timer
call timer_write ;設置時鐘
ret
;*****************************************************
;PCF8563應用程序
;寫PCF8563
;入口參數:發送緩沖@r1
;*****************************************************
timer_write: call iicstart
mov a,#0a2h ;器件地址和寫指令
call iicwbyte
call iiccack
jc return_0
mov a,#0 ;字節子地址
call iicwbyte
call iiccack
jc return_0
mov r1,#date_data ;數據
mov r0,#16 ;字節數
iicwrite0: mov a,@r1 ;數據
call iicwbyte
call iiccack
jc return_0
inc r1
djnz r0,iicwrite0
call iicstop
ret
return_0: call beep3
call iicstop
mov a,#0e5h
ret
;*****************************************************
;讀PCF8563
;出口參數:接收緩沖@r1
;*****************************************************
iicread: call iicstart
mov a,#0a3h ;器件地址和讀命令
call iicwbyte
call iiccack
jc retrdn
mov r1,#date_data
mov r0,#15 ;共讀取16個字節數據
iicread0: call iicrbyte
call iicack
inc r1
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -