EM78系列單片機(jī)的數(shù)值轉(zhuǎn)換子程序簡(jiǎn)介
jbc 0x03,0
inc 0x35
mov a,0x34
mov 0x30,a
mov a,0x35
mov 0x31,a
ret
eop
七 二進(jìn)制數(shù)轉(zhuǎn)換為BCD碼
本例為單字節(jié)二進(jìn)制數(shù)(0X20)轉(zhuǎn)換為非壓縮BCD碼,存在0X25,0X24,0X23中,0X25為百位,0X23為個(gè)位。
main: mov a,@0xa4 ;賦值
mov 0x20,a
mov 0x21,a
mov 0x22,a
mov a,@0x0 ;0x23,0x24,0x25單元清0
mov 0x23,a
mov 0x24,a
mov 0x25,a
mov a,@0x64 ;對(duì)100的個(gè)數(shù)計(jì)數(shù)
mov 0x26,a
mov a,@0x25 ;百位存在0x25中
mov 0x04,a
call a0 ;調(diào)計(jì)數(shù)子程
mov a,@0x0a ;對(duì)10的個(gè)數(shù)計(jì)數(shù)
mov 0x26,a
dec 0x04 ;個(gè)位存在0x24中
call a0
mov a,0x22 ;除去百位,十位,余下的即個(gè)位,存入0x23
mov 0x23,a
self: jmp self
a0: ;計(jì)數(shù)子程
mov a,0x26
sub 0x22,a
jbs 0x03,2
jmp a1
inc 0x00 ;無(wú)余數(shù)則對(duì)應(yīng)位加1
mov a,@0x0 ;0x21與0x22在返回時(shí)應(yīng)保持相同
mov 0x21,a
ret
a1: jbs 0x03,0 ;小于則跳a2
jmp a2
inc 0x00 ;大于則計(jì)數(shù)值加1
mov a,0x22
mov 0x21,a ;將0x22保存到0x21中
jmp a0 ;跳回a0繼續(xù)計(jì)數(shù)
a2: mov a,0x21 ;0x21中保存的減之前的數(shù)據(jù),此時(shí)恢復(fù)到0x22
mov 0x22,a
ret
eop本文引用地址:http://m.butianyuan.cn/article/171052.htm
評(píng)論