




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 内混色喷射技术发展趋势内混色喷射稳定性研究考核试卷
- 农业机械化项目风险管理法律框架分析考核试卷
- 信托资本补充中的股权激励计划设计研究考核试卷
- 培训项目可持续性评估标准考核试卷
- 2024年新疆泽普县急诊医学(副高)考试题含答案
- 新疆新冠管理办法
- 政府采供管理办法
- 2024年天津市宁河区急诊医学(副高)考试题含答案
- 拉萨苗木管理办法
- 2024年四川省宜宾县普通外科学(副高)考试题含答案
- 2025年中小学教师招聘考试教育理论综合知识模拟试卷及答案
- 2025-2026学年三年级数学上册 第6单元 多位数乘一位数 单元测试卷(提升练)人教版
- 脊柱骨折的治疗与护理
- 陕西婚姻服务管理办法
- 酒吧员工劳动合同协议书
- 《弟子规》全文拼音版(完美注音-A4打印版)
- 心肌梗塞的治疗及护理
- 2023-2028年中国通风隔声窗行业市场调查研究及发展战略规划报告
- 2025至2030中国沉淀硫酸钡行业产业运行态势及投资规划深度研究报告
- 2025年北京市社区工作者招聘笔试考试题库及答案解析
- 火灾事故桌面演练记录
评论
0/150
提交评论