访问电脑版页面

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

PIC单片机的BIN码转BCD码

导读: PIC单片机的BIN码转BCD码 ;;********************************************************************;            
关键字:
BCD

PIC单片机的BIN码转BCD码

;
;********************************************************************
;                  Binary To BCD Conversion Routine
;      This routine converts a 16 Bit binary Number to a 5 Digit
; BCD Number. This routine is useful since PIC16C55 & PIC16C57
; have  two 8 bit ports and one 4 bit port ( total of 5 BCD digits)
;
;       The 16 bit binary number is input in locations H_byte and
; L_byte with the high byte in H_byte.
;       The 5 digit BCD number is returned in R0, R1 and R2 with R0
; containing the MSD in its right most nibble.
;
;   Performance :
;               Program Memory  :       35
;               Clock Cycles    :       885
;
;*******************************************************************;
;
count  equ      16
temp   equ      17
;
H_byte  equ     10
L_byte  equ     11
R0      equ     12              ; RAM Assignments
R1      equ     13
R2      equ     14
;
 include         "picreg.h"
;
B2_BCD  bcf     STATUS,0                ; clear the carry bit
 movlw   .16
 movwf   count
 clrf    R0
 clrf    R1
 clrf    R2
loop16  rlf     L_byte
 rlf     H_byte
 rlf     R2
 rlf     R1
 rlf     R0
;
 decfsz  count
 goto    adjDEC
 RETLW   0
;
adjDEC  movlw   R2
 movwf   FSR
 call    adjBCD
;
 movlw   R1
 movwf   FSR
 call    adjBCD
;
 movlw   R0
 movwf   FSR
 call    adjBCD
;
 goto    loop16
;
adjBCD  movlw   3
 addwf   0,W
 movwf   temp
 btfsc   temp,3          ; test if result > 7
 movwf   0
 movlw   30
 addwf   0,W
 movwf   temp
 btfsc   temp,7          ; test if result > 7
 movwf   0               ; save as MSD
 RETLW   0
;
;********************************************************************
;               Test Program
;*********************************************************************
main    movlw   0FF
 movwf   H_byte
 movwf   L_byte          ; The 16 bit binary number = FFFF
 call    B2_BCD          ; After conversion the Decimal Number
;                               ; in R0,R1,R2 = 06,55,35
;
self    goto    self
;
 org     1FF
 goto    main
;
 END

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

相关阅读

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

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

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

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

PIC单片机如何进行编程

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

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

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

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

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

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

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

PIC单片机开发的若干问题

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

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

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

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

PIC16C711 直流电压表汇编程序

PIC单片机的读写93XCXX程序

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