| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 810 人关注过本帖
标题:单片机用BCD码显示0000——9999,百位不会进到千位去,那里错了?
只看楼主 加入收藏
nbmeixiang21
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-6-29
收藏
 问题点数:0 回复次数:0 
单片机用BCD码显示0000——9999,百位不会进到千位去,那里错了?

CURR_NUM EQU 30H ;BCD
curr_num_1 equ 31h

org 0000H
jmp MAIN

;*******************************************
org 0030H ;Start program from 0030H
MAIN:
mov P0,#0FFH ;Initialize the port
mov P1,#0FFH
mov P2,#0FFH
mov P3,#0FFH

mov CURR_NUM,#00H
mov curr_num_1,#00h;Initilize the var
clr P3.3 ;Clear the common line

MAIN_LOOP:
jb P2.7,next_loop ;Wait for key down,ADD
call DELAY
call NUM_ADD
jmp NEXT_LOOP


;KEY_2:
; jb P2.6,NEXT_LOOP ;Wait for key down,SUB
;call DELAY
; call NUM_SUB
;jmp NEXT_LOOP

NEXT_LOOP:
call DISPLAY_NUM
jmp MAIN_LOOP

ret
;****************************************************
DISPLAY_NUM:
;Display the low value
mov a,CURR_NUM
anl a,#0FH
mov dptr,#TAB_LED
movc a,@a+dptr

mov P0,a ;Display the number
mov P2,#11111011B
call DELAY_DISP

;Display the high value
mov a,CURR_NUM
swap a
anl a,#0FH
mov dptr,#TAB_LED
movc a,@a+dptr

mov P0,a ;Display the number
mov P2,#11110111B
call DELAY_DISP
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mov a,curr_num_1
anl a,#0fh
mov dptr,#tab_led
movc a,@a+dptr

mov p0,a
mov p2,#11101111b
call delay_disp

mov a,CURR_NUM_1
swap a
anl a,#0FH
mov dptr,#TAB_LED
movc a,@a+dptr

mov p0,a
mov p2,#11011111b
call delay_disp

ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nUM_ADD:
mov a,CURR_NUM
cjne a,#99H,INC_NUM
;If CURR_NUM=099H,then reset CURR_NUM
mov a,#00H
mov curr_num,a
jmp NUM_ADD_3

INC_NUM:
mov a,curr_num
anl a,#0FH
cjne a,#09H,NUM_ADD_1
mov a,CURR_NUM
add a,#07H
mov curr_num,a
jmp NUM_ADD_EXIT

NUM_ADD_1:
inc curr_num

jmp num_add_exit
num_add_3:
mov a,CURR_NUM_1
cjne a,#99H,INC_NUM_1
;If CURR_NUM=099H,then reset CURR_NUM
mov a,#00H
jmp num_add_exit
inc_num_1:
mov a,curr_num_1
anl a,#0FH
cjne a,#09H,NUM_ADD_2
;If (low 4-bits)=9 ;then (high 4-bits)+1 and (low 4-bits)=0
;add a,#10H
;anl a,#0F0H
add a,#07H
mov curr_num_1,a
jmp NUM_ADD_EXIT
num_add_2:
inc curr_num_1
jmp num_add_exit



NUM_ADD_EXIT:


ret

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DELAY:
mov r7,#10
DELAY_LOOP:
mov r6,#20
djnz r6,$
mov r6,#20
djnz r6,$

djnz r7,DELAY_LOOP
ret
;****************************************************
DELAY_DISP:
mov r7,#20
DELAY_DISP_LOOP:
mov r6,#20
djnz r6,$
mov r6,#20
djnz r6,$

djnz r7,DELAY_DISP_LOOP
ret

;****************************************************
;LED code
TAB_LED:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
;****************************************************
END

搜索更多相关主题的帖子: 单片机 BCD 
2007-07-12 22:25
快速回复:单片机用BCD码显示0000——9999,百位不会进到千位去,那里错了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.069808 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved