版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 PIC单片机的BCD码处理程序PIC单片机的BCD码处理程序#definePAGEEJECTTITLE"BCDArithmeticRoutines:Ver1.0"*;BCDArithmeticRoutines;*LISTcolumns=120,WRAP,L=0include"17c42.h"CBLOCK0x20Lbyte,HbyteR2,R1,R0;mustmaintainR2,R1,R0sequencecountNum1,Num2ENDC;BCDequNum1HtempequNum1LtempequNum
2、2;PAGEORG0x0000;*PIC单片机的BCD码处理程序#define PAGE EJECT TITLE "BCD Arithmetic Routines : Ver 1.0"*; BCD Arithmetic Routin
3、es;* LIST columns=120, WRAP, L=0 include "17c42.h" CBLOCK 0x20 Lbyte, Hbyte R2, R1, R0 ;must maintain R2, R1, R0 sequence count Num1, Num2
4、ENDC;BCD equ Num1Htemp equ Num1Ltemp equ Num2; PAGE ORG 0x0000;*;
5、60; BCD Arithmetic Test Program;*;main setf Hbyte setf Lbyte; &
6、#160; ;16bit binary num = 0xffff call B2_BCD_Looped ; after conversion the Decimal Num;
7、0; ; in R0, R1, R2 = 06,55,35 setf Hbyte setf Lbyte call B2_BCD_Straight ; sameasabove, but straight line code; movlw 0x06 movwf
8、60; R0 movlw 0x55 movwf R1 movlw 0x35 movwf R2 ; setf R0R1R2 = 65535; call BCDtoB
9、160; ; after conversion Hbyte = 0xff; ; and Lbyte = 0xff movlw
10、; 0x99 movwf Num1 movlw 0x99 movwf Num2 ; setf Num1 = Num2 = 0x99 (maxBCD); call BCDAdd &
11、#160; ; after addition, Num2 = 98; ; and Num1 = 01 ( 99+99 = 198); movlw 0x63
12、160; ; setf Wreg= 63 hex call BinBCD ; after conversion, BCD = 99; &
13、#160; ; 63 hex = 99 decimal.;self goto self; PAGE;*; Binary To BCD Conversion R
14、outine (8 bit); This routine converts the 8 bit binary number in the W Reg; to a 2 digit BCD number in location BCD( compacted BCD Code); The least significant digit is returned in location LSD and; the most significant digit is
15、 returned in location MSD.; Performance :; Program Memory : 10; Clock Cycles : 62
16、0; (worst case when W = 63 Hex ); ( i.e max Decimal number 99 );*;BinBCD
17、clrf BCDagain addlw -10 btfss _carry goto swapBCD incf BCD goto againswapBCD addlw 10 swapf BCD
18、160;iorwf BCD return; PAGE;*; Binary To BCD Conversion Routine (16 Bit);
19、160; (LOOPED Version); This routine converts a 16 Bit binary Number to a 5 Digit; BCD Number.; The 16 bit binary number is input in locations Hbyte and; Lbyte with the high byte in Hbyte.;
20、0; 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 : 32;
21、; Clock Cycles : 750;*;B2_BCD_Looped bsf _fs0 bsf _fs1 ; set fsr0 for no auto increment;
22、0;bcf _carry clrf count bsf count,4 ; set count = 16 clrf R0 clrf R1 clrf
23、0; R2loop16a rlcf Lbyte rlcf Hbyte rlcf R2 rlcf R1 rlcf R0; dcfsnz count returnadjDEC movlw R2
24、0; ; load R2 as indirect address ptr movwf fsr0 call adjBCD; incf fsr0 call adjBCD; incf fsr0 call
25、0; adjBCD; goto loop16a;adjBCD movfp indf0,wreg addlw 0x03 btfsc wreg,3 ; test if result > 7 movwf
26、 indf0 movfp indf0,wreg addlw 0x30 btfsc wreg,7 ; test if result > 7 movwf indf0
27、; ; save as MSD return;*; Binary To BCD Conversion Routine (16 Bit);
28、; (Partial Straight Line Version); This routine converts a 16 Bit binary Number to a 5 Digit; BCD Number.; The 16 bit binary number is input in locations Hbyte and; Lbyte with the high byte in Hbyte.;
29、0; 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 : 44;
30、; Clock Cycles : 572;*;B2_BCD_Straight bsf _fs0 bsf _fs1 ; set fsr0 for no auto increment; bcf
31、; _carry clrf count bsf count,4 ; set count = 16 clrf R0 clrf R1 clrf R2loop1
32、6b rlcf Lbyte rlcf Hbyte rlcf R2 rlcf R1 rlcf R0; dcfsnz count return
33、0; ; DONE movlw R2 ; load R2 as indirect address ptr movwf fsr0; adjustBCD movfp indf0,wreg addlw
34、60; 0x03 btfsc wreg,3 ; test if result > 7 movwf indf0 movfp indf0,wreg addlw 0x30 btfsc wreg,7
35、60; ; test if result > 7 movwf indf0 ; save as MSD; incf fsr0; adjustBCD movfp indf0,wreg addlw 0x03 btfsc
36、0; wreg,3 ; test if result > 7 movwf indf0 movfp indf0,wreg addlw 0x30 btfsc wreg,7 ;
37、 test if result > 7 movwf indf0 ; save as MSD; incf fsr0; adjustBCD movfp indf0,wreg addlw 0x03 btfsc wreg,3
38、160; ; test if result > 7 movwf indf0 movfp indf0,wreg addlw 0x30 btfsc wreg,7 ; test if result > 7 m
39、ovwf indf0 ; save as MSD; goto loop16b; PAGE;*; BCD To Binary Conversion;
40、This routine converts a 5 digit BCD number to a 16 bit binary; number.; The input 5 digit BCD numbers are asumed to be in locations; R0, R1 & R2 with R0 containing the MSD in its right most nibble.; The 16 bit binary num
41、ber is output in registers Hbyte & Lbyte; ( high byte & low byte repectively ).; The method used for conversion is :; input number X = abcde ( the 5 digit BCD number );
42、0; X = (R0,R1,R2) = abcde = 10101010a+b+c+d+e; Performance :; Program Memory : 30;
43、160; Clock Cycles : 112;*;mpy10b andlw 0x0f addwf Lbyte btfsc _carry incf Hbytempy10a bcf _carry
44、; ; multiply by 2 rlcf Lbyte,w movwf Ltemp rlcf Hbyte,w ; (Htemp,Ltemp) = 2*N movwf Htemp; bcf &
45、#160; _carry ; multiply by 2 rlcf Lbyte rlcf Hbyte bcf _carry ; multiply by 2 rlcf
46、 Lbyte rlcf Hbyte bcf _carry ; multiply by 2 rlcf Lbyte rlcf Hbyte ; (Hbyte,
47、Lbyte) = 8*N; movfp Ltemp,wreg addwf Lbyte movfp Htemp,wreg addwfc Hbyte return
48、0; ; (Hbyte,Lbyte) = 10*N;BCDtoB clrf Hbyte movfp R0,wreg andlw 0x0f movwf Lbyte call mpy10a ; result = 10a+b; swa
49、pf R1,w call mpy10b ; result = 1010a+b; movfp R1,wreg call mpy10b ; result = 101010a+b+c; swapf R2,w call mpy10b
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 三明市人民医院手工清洗操作资格认证
- 扬州市中医院银屑病关节炎分类诊断标准考核
- 南昌市中医院医师定期考核管理
- 金华市中医院专科护理标准制定考核
- 2025年新疆甜菜种植项目投资与收购合同
- 2025年合伙旅游产品开发合同模板
- 淮安市中医院学科安全管理考核
- 2025年互联网公司员工股权激励合同协议
- 新余市中医院透析患者健康教育考核
- 并网调度电力市场交易合同协议(GF-2003-0512)
- 环境 监理 培训课件
- 船员服务车辆管理制度
- 2025至2030麻醉药行业市场发展分析及投资融资策略报告
- 检测单位抽样管理制度
- 安全技术与管理专业教学标准(中等职业教育)2025修订
- GB/T 29188-2022品牌价值评价多周期超额收益法
- T/CAPA 3-2021毛发移植规范
- 汽车维修服务中心车辆维修证明书(8篇)
- 风电总包合同协议书
- 物业移交消防协议书
- 《厦门大学海洋科学导论课件》(生物部分)
评论
0/150
提交评论