机电之家资源网
单片机首页|单片机基础|单片机应用|单片机开发|单片机文案|软件资料下载|音响制作|电路图下载 |嵌入式开发
培训信息
赞助商
PIC16C54单片机四位LED时钟显示程序
PIC16C54单片机四位LED时钟显示程序
 更新时间:2009-12-10 13:44:04  点击数:0
【字体: 字体颜色
;;四位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 b11111110 ;pa0--pa3
disp2 equ b11111101
disp3 equ b11111011
disp4 equ b11110111
dispoff equ b11111111
switch equ b00001110 ;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

  • 上一篇: PIC16F877单片机的图形液显示模块接口技术
  • 下一篇: 没有了
  • 发表评论   告诉好友   打印此文  收藏此页  关闭窗口  返回顶部
    热点文章
     
    推荐文章
     
    相关文章
    网友评论:(只显示最新5条。)
    关于我们 | 联系我们 | 广告合作 | 付款方式 | 使用帮助 | 机电之家 | 会员助手 | 免费链接

    点击这里给我发消息66821730(技术支持)点击这里给我发消息66821730(广告投放) 点击这里给我发消息41031197(编辑) 点击这里给我发消息58733127(审核)
    本站提供的机电设备,机电供求等信息由机电企业自行提供,该企业负责信息内容的真实性、准确性和合法性。
    机电之家对此不承担任何保证责任,有侵犯您利益的地方请联系机电之家,机电之家将及时作出处理。
    Copyright 2007 机电之家 Inc All Rights Reserved.机电之家-由机电一体化网更名-声明
    电话:0571-87774297 传真:0571-87774298
    杭州滨兴科技有限公司提供技术支持

    主办:杭州市高新区(滨江)机电一体化学会
    中国行业电子商务100强网站

    网站经营许可证:浙B2-20080178-1