top
<返回首页 <退出
欢迎您来到51-ARM学习论坛,您还没有[注册]或[登陆]
用户名:  
密  码:  
验证码:  
共有1299位会员 新进来宾:xle
今日发帖:27篇 在线人数:965人
最高发帖:140篇 主题总数:589篇
消息:热烈祝贺侯工单片机工作室官方网站正式开通!论坛版块诚征精英斑竹...凡51-ARM论坛斑竹,均有机参加侯工单片机工作室组织的各种技术交流,培训!!!
 论坛帮助  
  51-ARM学习论坛>>源码下载区>>体育100米计时器汇编程序
 
回帖
当前心情:

内  容:
   
 

;               体育百米计时器源程序
;               总架构:欧福强
;               74HC595传输子程序:韦国权
;               LED段码:谢名全
;------------------------------------------------------------------------
                SCK     EQU     P1.1            ;移位时钟
                RCK     EQU     P1.2            ;更新显示脉冲
                SI      EQU     P1.3            ;串行数据
;------------------------------------------------------------------------
;               30H,31H,32H,33H                 ;板载LED段码缓冲区
;               34H,35H                         ;延时子程序使用
;               R1                              ;串行LED发送循环计数
;               R2,R3,R4,R5,                    ;|计时十进制数字缓冲区|
;              .01 .1 1  10                     ;|对应位              |
;               40H,41H,41H,43H                 ;串行LED段码缓冲区
;-------------------------------------------------------------------------------
                ORG     0000H
                SJMP    INIT                    ;系统初始化
                ORG     000BH
                LJMP    TIMER_0_IRQ             ;定时器0中断
                ORG     001BH
                LJMP    TIMER_1_IRQ             ;定时器1中断
;-------------------------------------------------------------------------------
                ORG     0040H                   ;系统初始化区
INIT:           MOV     TMOD,#11H               ;都工作在方式1--16位定时器
                MOV     SP,#71H                 ;堆栈区设置
                SETB    PT0                     ;10ms定时器中断优先
;--------------------------------
                MOV     TH0,#0D8H               ;置初值(10MS/12MHz)
                MOV     TL0,#0F4H               ;TO
;--------------------------------
                MOV     TH1,#03CH               ;置初值(50MS/12MHz)
                MOV     TL1,#0B0H               ;T1
;--------------------------------
                SETB    TR1                     ;启动(50ms)定时器
                MOV     IE,#8AH                 ;打开总中断使能以及定时器中断
;--------------------------------
                MOV     R2,#0                   ;用户初始化区
                MOV     R3,#0
                MOV     R4,#0
                MOV     R5,#0
;-------------------------------------------------------------------------------
MAIN:           LCALL   OnbordDisp              ;用户程序区,扫描板载LED
                LCALL   KEYSCAN_DEAL            ;扫描键盘并处理
                SJMP    MAIN                    
;-------------------------------------------------------------------------------
TIMER_0_IRQ:    MOV     TH0,#0D8H               ;定时器0中断服务程序(10ms)
                MOV     TL0,#0F4H               ;恢复(10ms)定时初值
;--------------------------------
                LCALL   TimeCount               ;10ms节拍程序区,时间计数
T0_DRE_EXIT:    RETI
;-------------------------------------------------------------------------------
TIMER_1_IRQ:    MOV     TH1,#03CH               ;定时器1中断服务程序(50ms)
                MOV     TL1,#0B0H               ;恢复(50ms)定时初值
;--------------------------------
                LCALL   ValToCode               ;50ms节拍程序区,转换板载段码
                LCALL   S_LedValToCode          ;转换串行LED数值成段码
                LCALL   SenDataToLed            ;发送到串行LED并显示
T1_DRE_EX:      RETI
;-------------------------------------------------------------------------------
DELAY:          DJNZ    34H,$                   ;精确0.1S延时子程序
                DJNZ    35H,DELAY
                MOV     35H,#194
                MOV     34H,#78
                DJNZ    34H,$
                RET
;-------------------------------------------------------------------------------
OnbordCodeTab:  DB      88H,0BEH,0C4H,94H,0B2H,91H,81H,0BCH        ;板载LED段码
                DB      80H,90H,0A0H,83H,0C9H,86H,0C1H,0E1H
SeriaLedTab:    DB      0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H      ;串行LED段码
                DB      0FEH,0F6H
;-------------------------------------------------------------------------------
ValToCode:      MOV     A,R2                    ;数值转段码子程序(板载)
                MOV     DPTR,#OnbordCodeTab     ;指针指向板载段码表
                MOVC    A,@A+DPTR
                MOV     30H,A
                MOV     A,R3
                MOVC    A,@A+DPTR
                MOV     31H,A
                MOV     A,R4
                MOVC    A,@A+DPTR
                ANL     A,#7FH                  ;秒个位加上小数点
                MOV     32H,A
                MOV     A,R5
                MOVC    A,@A+DPTR
                MOV     33H,A
                RET
;-------------------------------------------------------------------------------
TimeCount:      INC   R2                        ;计时累加程序
                CJNE  R2,#0AH,TC_DRE_Exit       ;百分秒增值判断
                MOV   R2,#00H
                INC   R3
                CJNE  R3,#0AH,TC_DRE_Exit       ;十分秒增值判断
                MOV   R3,#00H
                INC   R4
;--------------------------------
                CPL   P1.0                      ;秒节拍程序区
;--------------------------------
                CJNE  R4,#0AH,TC_DRE_Exit       ;秒增值判断
                MOV   R4,#00H
                INC   R5
;--------------------------------
                NOP                             ;十秒节拍程序区
;--------------------------------
                CJNE  R5,#0AH,TC_DRE_Exit       ;十位秒增值判断
                MOV   R5,#00H
TC_DRE_Exit:    RET
;-------------------------------------------------------------------------------
OnbordDisp:     MOV   P2,#0FFH                  ;板载LED扫描子程序
                MOV   P0,30H
                MOV   P2,#0EFH
                DJNZ  70H,$
                MOV   P2,#0FFH
                MOV   P0,31H
                MOV   P2,#0DFH
                DJNZ  70H,$
                MOV   P2,#0FFH
                MOV   P0,32H
                MOV   P2,#0BFH
                DJNZ  70H,$
                MOV   P2,#0FFH
                MOV   P0,33H
                MOV   P2,#7FH
                DJNZ  70H,$
                MOV   P2,#0FFH
                RET
;-------------------------------------------------------------------------------
SenDataToLed:   CLR   SCK                       ;更新串行LED显示数据
                CLR   RCK
                CLR   SI
                MOV   R1,#8                     ;循环值清零
;--------------------------------
                MOV   A,40H                     ;读入段码
LO1:            RRC   A
                MOV   SI,C
                CLR   SCK
                SETB  SCK
                DJNZ  R1,LO1
                MOV   R1,#8
;--------------------------------
                MOV   A,41H
LO2:            RRC   A
                MOV   SI,C
                CLR   SCK
                SETB  SCK
                DJNZ  R1,LO2
                MOV   R1,#8
;--------------------------------
                MOV   A,42H
LO3:            RRC   A
                MOV   SI,C
                CLR   SCK
                SETB  SCK
                DJNZ  R1,LO3
                MOV   R1,#8
;--------------------------------
                MOV   A,43H
LO4:            RRC   A
                MOV   SI,C
                CLR   SCK
                SETB  SCK
                DJNZ  R1,LO4
;--------------------------------
                SETB  RCK                       ;更新串行LED显示
                CLR   RCK                       ;停止更新
                RET
;-------------------------------------------------------------------------------
S_LedValToCode: MOV   DPTR,#SeriaLedTab         ;串行LED段码转换子程序
                MOV   A,R2
                MOVC  A,@A+DPTR
                MOV   40H,A
;--------------------------------
                MOV   A,R3
                MOVC  A,@A+DPTR
                MOV   41H,A
;--------------------------------
                MOV   A,R4
                MOVC  A,@A+DPTR
                ORL   a,#1                      ;秒个位加上小数点
                MOV   42H,A
;--------------------------------
                MOV   A,R5
                JZ    S_ZERO_EXIT
                MOVC  A,@A+DPTR
                MOV   43H,A
                RET
S_ZERO_EXIT:    MOV   43H,#0                    ;无效零消隐
                RET
;-------------------------------------------------------------------------------
KEYSCAN_DEAL:   JB    P2.0,NEXT1KEY             ;键盘扫描处理子程序,P2.0:复位
                CLR   TR0                       ;停止计时
                MOV   R2,#0
                MOV   R3,#0
                MOV   R4,#0
                MOV   R5,#0                     ;时间计数区清零
                RET                             ;复位键返回
;--------------------------------
NEXT1KEY:       JB    P2.2,NEXT2KEY             ;P2.1:停止键
                CLR   TR0                       ;停止计时
                RET                             ;停止键返回
;--------------------------------
NEXT2KEY:       JB    P2.1,KEY_DEAL_END         ;P2.2,计时启动键
                SETB  TR0                       ;启动计时
                JNB   P2.1,$                    ;等待按键释放
KEY_DEAL_END:   RET                             ;启动键返回
;-------------------------------------------------------------------------------
                END

bottom
 
联系电话:0755-26766021 邮箱:51-ARM@163.com QQ群:43996737
项目定制承接手机:13798532857(侯工)
部分内容转载于网络,如有涉及版权问题,请通知本站删除。
粤ICP备09217420号 版权所有  @  2008-2012  侯工单片机工作室