英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流

 找回密码
 立即注册
搜索
电子烟方案单片机单片机开发深圳单片机开发
单片机方案国产单片机8位单片机电子烟方案开发
查看: 2681|回复: 0
打印 上一主题 下一主题

PIC16C54单片机四位LED时钟显示程序

[复制链接]
跳转到指定楼层
1#
发表于 2009-5-6 09:22:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
title"clock"
list p=16c54,n=66
PIC54 equ 1ffh
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;written by:PIC单片机www.pic16.com ;;
;;四位LED时钟显示程序 ;;
;;RB1-SW1秒设置 RB2-SW2分设置 RB3-SW3时设置 ;;
;;RB1--RB7接LED段码,RA0--RA3做选通 ;;
;;使用4M晶振TMR0滪分频为1:16 TMRO的循环时间为4.096MS 244次为一秒 ;;
;;用sec_nth计数 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pointer equ 00h
rtcc equ 01h
pc equ 02h
status equ 03h
fsr equ 04h
port_a equ 05h
port_b equ 06h
;---------------------------------
carry equ 0
c equ 0
dcarry equ 1
dc equ 1
z_bit equ 2
z equ 2
p_down equ 3
pd equ 3
t_out equ 4
to equ 4
pa0 equ 5
pa1 equ 6
pa2 equ 7
;---------------------------------
zero equ 0x7e
one equ 0x0c
two equ 0xb6
three equ 0x9e
four equ 0xcc
five equ 0xda
six equ 0xfa
seven equ 0x0e
eight equ 0xfe
nine equ 0xce
colon equ 0x01
t equ 0xf0
blank equ 0x00
;-----------------------------------------
maxnths equ 0x0c ; d12
maxsecs equ 0xc4 ; d196
maxmins equ 0xc4 ; d196
maxhrs equ 0xf4 ; d244
minhrs equ 0xf3 ; d243
adjmin equ 0x09 ; d9
adjhr equ 0x22 ; d34
adjday equ 0x03 ; d3
;-----------------------------------------------
disp1 equ b'11111110' ;pa0--pa3
disp2 equ b'11111101'
disp3 equ b'11111011'
disp4 equ b'11110111'
dispoff equ b'11111111'
switch equ b'00001110' ;key in portb
;---------------------------------------------
sec equ 00h ;秒 flags d0--d7
min equ 01h ;分
hrs equ 02h ;时
chg equ 03h ;有显示或按键按下
sw1 equ 04h ;
sw2 equ 05h ;
sw3 equ 06h ;
sw_on equ 07h ;有键按下
;------------------------------------
keys equ 08h ;哪个键按下?
flags equ 09h ;the bits for :sec d0. min d1 .hrs d2.chg ;d3.sw1.sw2.sw3 d6 .swon d7
display equ 0bh ;new display
digit1 equ 0ch ;a0
digit2 equ 0dh ;a1
digit3 equ 0eh ;a2
digit4 equ 0fh ;a3 led
;---------------------------------------
sec_nth equ 10h ;秒计数单元
seconds equ 11h ;秒
minutes equ 12h ;分
hours equ 13h ;时
var equ 14h ;运算变量
count equ 15h
count1 equ 16h

start
movlw 0x03
option
movlw 0
tris port_a
tris port_b
movlw blank
movwf port_b
bcf status,pa1
bcf status,pa0
;----------------------------------------
movlw 0x01
movwf rtcc
movlw 0xfe
movwf display
movlw blank
movwf digit1
movwf digit2
movwf digit3
movwf digit4
movlw maxnths ;d12
movwf sec_nth
movlw maxsecs ;d196
movwf seconds
movlw maxmins
movwf minutes
movlw 0xff
movwf hours
movlw 00h
movwf flags
main rtcc_fill
movf rtcc,0
btfss status,z
goto rtcc_fill
incfsz sec_nth,1
goto time_done
movlw maxnths
movwf sec_nth
check_sw
btfss flags,sw_on
goto set_time
btfsc flags,sw1
goto set_time
movlw maxsecs ;d196
movwf seconds
movlw 0x7f
movwf sec_nth
btfss flags,sw2
goto hourset
movlw 0xaf
movwf sec_nth
incfsz minutes,1
goto hourset
movlw maxmins ;d196
movwf minutes
hourset
btfsc flags,sw2
goto check_time
incfsz hours,1
goto check_time
movlw maxhrs
movwf hours
goto check_time
set_time
bsf flags,sec
bsf flags,chg
incfsz seconds,1
goto time_done
movlw maxsecs
movwf seconds
bsf flags,min
bsf flags,chg
movlw adjmin
subwf sec_nth,1
incfsz minutes,1
goto time_done
movlw maxmins ;0xc4
movwf minutes
bsf flags,hrs
bsf flags,chg
movlw adjhr ;0x22
addwf sec_nth
incfsz hours,1
goto time_done
movlw maxhrs ;0xf4
movwf hours
movlw adjday ;0x03
subwf sec_nth,1
time_done
btfss flags,chg
goto cycle
check_seconds
btfss flags,sw1
goto check_time
movlw 0x00
movwf digit2
movwf digit3
movwf digit4
movlw maxsecs ;0xc4
subwf seconds,0
movwf digit1
goto split_hex
check_time
movlw 0x00
movwf digit2
movwf digit4
movlw minhrs ;0xf3
subwf hours,0
movwf digit3
movlw maxmins ;0xc4
subwf minutes,0
movwf digit1
split_hex
movlw 0x02
movwf count
movlw digit1
movwf fsr
goto loop
loop2
movlw digit3
movwf fsr
loop movlw 0x0a
subwf pointer,1
btfsc status,c
goto increment_10s
addwf pointer,1
goto next_digit
increment_10s
incf fsr,1
incf pointer,1
decf fsr,1
goto loop
next_digit
decfsz count,1
goto loop2
convert_hex_to_display
movlw digit1
movwf fsr
movlw 0x04
movwf count
next_hex
movf pointer,0
call return_code
movwf pointer
incf fsr,1
decfsz count,1
goto next_hex
fix_display
movlw zero
subwf digit4,0
btfss status,z
goto fix_sec
movlw blank
movwf digit4
fix_sec
btfss flags,sw1
goto clear_flags
movwf digit3
clear_flags
movlw 0xf0
andwf flags,1
cycle
movlw dispoff
movwf port_a
movlw switch
tris port_b
movlw 0x0f
andwf flags,1
nop
nop
nop
movf port_b,0
movwf var
btfss var,1
goto switch2
bsf flags,chg
bsf flags,sw1
bsf flags,sw_on
switch2
btfss var,2
goto switch3
bsf flags,chg
bsf flags,sw2
bsf flags,sw_on
switch3
btfss var,3
goto switch3
bsf flags,chg
bsf flags,sw3
bsf flags,sw_on
setport
movlw 0x00
tris port_b
movlw blank
movwf port_b
btfss display,0
movf digit4,0
btfss display,1
movf digit3,0
btfss display,2
movf digit2,0
btfss display,3
movf digit1,0
movwf port_b
btfsc sec_nth,7
bsf port_b,0
movf display,0
movwf port_a
movwf display
rlf display,1
bsf display,0
btfss display,4
bcf display,0
goto main
return_code
addwf pc,1
retlw zero ;0
retlw one
retlw two
retlw three
retlw four ;4
retlw five
retlw six
retlw seven
retlw eight
retlw nine ;9
org PIC54
goto start

end
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|公司首页|Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 ( 粤ICP备09008620号 )

GMT+8, 2024-12-25 23:15 , Processed in 0.051917 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表