访问电脑版页面

导航:老古开发网手机版Pic单片机PIC单片机C语言编程

PIC单片机的BCD码加法程序

导读: PIC单片机的BCD码加法程序 ;*******************  Unsigned BCD Addition   ***************;;       This routine performs a 2
关键字:
BCD

PIC单片机的BCD码加法程序

;*******************  Unsigned BCD Addition   ***************
;
;       This routine performs a 2 Digit Unsigned BCD Addition
; It is assumed that the two BCD numbers to be added are in
; locations Num_1 & Num_2. The result is the sum of Num_1+Num_2
; and is stored in location Num_2 and the overflow carry is returned
; in location Num_1
;
;   Performance :
;               Program Memory  :       25
;               Clock Cycles    :       17   ( worst case )
;
;*******************************************************************;
;
Num_1   equ     8       ; Overflow flow carry overwrites Num_1
result  equ     8
;
Num_2   equ     9       ; Num_2 + Num_1 overwrites Num_2
O_flow  equ     9
;
;
 include         "picreg.h"
;
BCDAdd  movf    Num_1,W
 clrf    Num_1           ;clear num_1
 addwf   Num_2,1         ; do binary addition
 btfsc   STATUS,C        ;< 256 then skip
 goto    inc_n1n2        ;else inc all
 movlw   66              ;add 66
 addwf   Num_2,1         ;/
 btfss   STATUS,DC       ;half carry?
 goto    sub_06          ;no then subtract
 btfss   STATUS,C        ;full carry?
 goto    sub_60          ;yes then subtract
inc_n1  incf    Num_1,1         ;inc it
 retlw   0               ;clr w
sub_06  btfss   STATUS,C        ;full carry
 goto    sub_66          ;yes subtract 66
 movlw   6               ;else subtract 6
 goto    sub_com         ;do common
sub_66  movlw   66             
sub_com subwf   Num_2,1                  
 retlw   0
sub_60  movlw   60
 goto    sub_com
inc_n1n2
 movlw   66
 addwf   Num_2,1
 goto    inc_n1
;
;********************************************************************
;               Test Program
;*********************************************************************
main    movlw   99
 movwf   Num_1      ; Set Num_1 = 99 ( max BCD digit )
 movlw   99
 movwf   Num_2      ; Set Num_2 = 99
;
 call    BCDAdd     ; After addition, Num_2 = 98
;                          ;  and Num_1 = 01 ( 99+99 = 198 -> max number )
;
self    goto    self
;
;
 org     1FF
 goto    main
;
 END

来源:匠人的百宝箱   作者:  2009/1/16 11:44:00
栏目: [ PIC单片机C语言编程]

相关阅读

LCD驱动HT1621的PIC单片机源代码

PIC单片机引脚中断程序的设计技巧

PIC单片机与PC机实现串行通信的设计

基于PIC单片机的数据采集系统设计

PIC单片机如何进行编程

PIC单片机低功耗电路的设计方法介绍

PIC单片机位域结构的应用解析

PIC单片机的各种清零指令解析

pic单片机编程串烧,pic单片机汇编语言讲解上篇

浅谈PIC8位单片机中的RAM和汇编程序的关系

PIC单片机实现延时x毫秒的功能设计

PIC单片机对LED数码管矩阵键盘显示的设计

PIC单片机开发的若干问题

PIC单片机AD转化器编程方法

PIC单片机对豆浆机的控制设计

基于PIC单片机直流电压表的汇编程序分享

PIC单片机控制时钟芯片DS1302汇编程序

PIC16C711 直流电压表汇编程序

PIC单片机的读写93XCXX程序

基于PICC 编译环境编写PIC单片机程序