標(biāo)題:
51單片機(jī)萬用表Proteus仿真+匯編程序
[打印本頁(yè)]
作者:
xiuye_tao
時(shí)間:
2016-5-10 19:49
標(biāo)題:
51單片機(jī)萬用表Proteus仿真+匯編程序
51單片機(jī)萬用表仿真,原理圖如下:
0.png
(51.1 KB, 下載次數(shù): 83)
下載附件
2016-5-10 21:01 上傳
仿真及完整程序的下載地址:
實(shí)用萬用表.rar
(33.37 KB, 下載次數(shù): 64)
2016-5-10 21:12 上傳
點(diǎn)擊文件名下載附件
萬用表
下載積分: 黑幣 -5
c語(yǔ)言版本的單片機(jī)萬用表51黑下載:
http://www.torrancerestoration.com/bbs/dpj-50069-1.html
萬用表的程序源碼如下:
org 0000h ;單片機(jī)復(fù)位地址
ajmp main ;轉(zhuǎn)移到主程序處
org 0100h ;main被定位在0x0100處
main: mov sp,#80h ;初始化堆棧指針
mov DPTR,#0E000h
mov A,#00h
movx @DPTR,A
setb C
mov P3.0,C
call DELAY_5ms
JUDGE: mov A,P1 ;判斷測(cè)量種類
anl A,#0Fh
cjne A,#00h,NON_CAP
call CAP_MEA
NON_CAP: cjne A,#01h,NON_V
call V_MEA
NON_V: cjne A,#02h,NON_A
call A_MEA
NON_A: call R_MEA
CAP_MEA: mov A,#00h ;測(cè)量電容
clr C
mov P3.0,C
DELAY_1S: mov R5,#2Eh ;設(shè)置R5初始計(jì)數(shù)值
DELAY_1S1: mov R6,#58h ;設(shè)置R6初始計(jì)數(shù)值
DELAY_1S2: mov R7,#7Ah ;設(shè)置R7初始計(jì)數(shù)值
DELAY_1S3: djnz R7,DELAY_1S3 ;延時(shí)時(shí)間為 Time=( ( (R7*2)+2+1 )*R6+2+1 )*R5+1
djnz R6,DELAY_1S2 ;
djnz R5,DELAY_1S1 ;
setb C
nop
nop
mov P3.0,C
READC: mov P2,#00h
setb C
mov P3.1,C
nop
clr C
mov P3.1,C
nop
call DELAY_5ms
mov DPTR,#0000h
movx A,@DPTR
mov B,A ;防止數(shù)據(jù)溢出
mov A,#0E6h
subb A,B
jc LARGERC
mov B,A
subb A,#31h
jc MIDDLEC
LESSC: mov A,#30h
ajmp CALCULATEC
LARGERC: mov A,#00h
ajmp CALCULATEC
MIDDLEC: mov A,B
CALCULATEC: mov R1,#40h
mov @R1,#00h
inc r1
mov @R1,#0BFh
inc r1
mov DPTR,#TABLE1 ;查找表格
movc A,@A+DPTR
mov B,A
mov @R1,#0BFh
anl A,#0F0h
swap A
mov DPTR,#SEGMENT7
movc A,@A+DPTR
mov @r1,A
inc r1
mov A,B
anl A,#0Fh
mov DPTR,#SEGMENT7
movc A,@A+DPTR
mov @r1,A
LOOPC: call DISPLAY
ajmp LOOPC
ret
V_MEA: mov A,#00h ;測(cè)量電壓
READV: mov P2,#20h
setb C
mov P3.1,C
nop
clr C
mov P3.1,C
nop
call DELAY_5ms
mov DPTR,#2000h
movx A,@DPTR
mov R2,#00h
mov R3,A
mov R6,#01h
mov R7,#0F4h
call MULD2 ;乘以500
clr C
mov A,r5
add A,#60h ;加96修正
mov r5,A
mov A,r4
addc A,#00h
mov r4,A
mov A,r3
addc A,#00h
mov r3,A
mov A,r2
addc A,#00h
mov r2,A
mov r0,#30h
mov r1,#34h
mov A,R2
mov @r1,A
inc r1
mov A,R3
mov @r1,A
inc r1
mov A,R4
mov @r1,A
inc r1
mov A,R5
mov @r1,A
inc r1
mov @r1,#00h
inc r1
mov @r1,#00h
inc r1
mov @r1,#00h
inc r1
mov @r1,#0FFh
call DIVD4 ;除以255
mov r1,#38h
mov @r1,#00h
inc r1
mov @r1,#00h
inc r1
mov @r1,#00h
inc r1
mov @r1,#0Ah
call DIVD4
mov 43h,33h
call DIVD4
mov 42h,33h
call DIVD4
mov 41h,33h
mov r0,#40h
mov @r0,#00h
inc r0
mov A,41h
mov DPTR,#SEGMENT7
movc A,@A+DPTR
orl A,#80h
mov @r0,A
inc r0
mov A,42h
mov DPTR,#SEGMENT7
movc A,@A+DPTR
mov @r0,A
inc r0
mov A,43h
mov DPTR,#SEGMENT7
movc A,@A+DPTR
mov @r0,A
LOOPV: call DISPLAY
nop
ajmp LOOPV
ret
A_MEA: mov A,#00h ;測(cè)量電流
READA: mov P2,#40h ;采樣
setb C
mov P3.1,C
nop
clr C
mov P3.1,C
nop
call DELAY_5ms
mov DPTR,#4000h
movx A,@DPTR ;讀取采樣值
mov B,A
mov A,#0B6h
clr C ;以下根據(jù)范圍設(shè)置數(shù)值以防溢出
subb A,B
jc LARGERA
mov A,B
subb A,#16h
jc LESSA
ajmp MIDDLEA
LARGERA: mov A,#0B6h
ajmp CALCULATEA
LESSA: mov A,#16h
ajmp CALCULATEA
MIDDLEA: mov A,B
CALCULATEA: mov r2,#0C3h
mov r3,#50h
mov r6,#00h
mov r7,A
call MULD2 ;乘以50000
clr C
mov A,r5
subb A,#70h ;以下減去102000
mov r5,A
mov 37h,A
mov A,r4
subb A,#8Eh
mov r4,A
mov 36h,A
mov A,r3
subb A,#01h
mov r3,A
mov 35h,A
mov A,r2
subb A,#00h
mov r2,A
mov 34h,A
mov r0,#30h
mov r1,#38h
mov @r1,#00h
inc r1
mov @r1,#01h
inc r1
mov @r1,#5Eh
inc r1
mov @r1,#0A0h
call DIVD4 ;除以89760
mov r1,#38h
mov @r1,#00h
inc r1
mov @r1,#00h
inc r1
mov @r1,#00h
inc r1
mov @r1,#0Ah
mov DPTR,#SEGMENT7
call DIVD4
mov A,33h
movc A,@A+DPTR
mov 43h,A
call DIVD4
mov A,33h
movc A,@A+DPTR
mov 42h,A
call DIVD4
mov A,33h
movc A,@A+DPTR
cjne A,#3Fh,NOTEQU
mov A,#00h
NOTEQU: mov 41h,A
mov 40h,#00h
LOOPA: call DISPLAY
nop
ajmp LOOPA
ret
R_MEA: mov A,#00h ;測(cè)量電阻
READR: mov P2,#60h ;采樣
setb C
mov P3.1,C
nop
clr C
mov P3.1,C
nop
call DELAY_5ms
mov DPTR,#6000h
movx A,@DPTR ;讀取采樣值
mov R2,#00h
mov R3,A
mov R6,#03h
mov R7,#0E8h
call MULD2 ;乘以1000
mov r0,#30h
mov r1,#34h
mov A,R2
mov @r1,A
inc r1
mov A,R3
mov @r1,A
inc r1
mov A,R4
mov @r1,A
inc r1
mov A,R5
mov @r1,A
inc r1
mov @r1,#00h
inc r1
mov @r1,#00h
inc r1
mov @r1,#00h
inc r1
mov @r1,#0FFh
call DIVD4 ;除以255
mov r1,#38h
mov @r1,#00h
inc r1
mov @r1,#00h
inc r1
mov @r1,#00h
inc r1
mov @r1,#0Ah
mov DPTR,#SEGMENT7
call DIVD4 ;連續(xù)進(jìn)行4次除以10的操作
mov A,33h ;取得10進(jìn)制值
movc A,@A+DPTR
mov 43h,A
call DIVD4
mov A,33h
movc A,@A+DPTR
mov 42h,A
call DIVD4
mov A,33h
movc A,@A+DPTR
mov 41h,A
call DIVD4
mov A,33h
movc A,@A+DPTR
cjne A,#3Fh,NONZERO
mov A,#00h
NONZERO: mov 40h,A
LOOPR: call DISPLAY
nop
ajmp LOOPR
ret
DELAY_5ms: mov R5,#01h ;設(shè)置R5初始計(jì)數(shù)值
DELAY_5ms1: mov R6,#16h ;設(shè)置R6初始計(jì)數(shù)值
DELAY_5ms2: mov R7,#70h ;設(shè)置R7初始計(jì)數(shù)值
DELAY_5ms3: djnz R7,DELAY_5ms3 ;延時(shí)時(shí)間為 Time=( ( (R7*2)+2+1 )*R6+2+1 )*R5+1
djnz R6,DELAY_5ms2 ;
djnz R5,DELAY_5ms1 ;
ret
TABLE1: DB 10h,11h,12h,14h,15h,16h,17h,18h ;電容量表格0.1uF---1uF
DB 20h,22h,24h,25h,27h,28h,30h,31h
DB 33h,34h,35h,36h,38h,40h,41h,43h
DB 45h,47h,50h,52h,55h,57h,59h,60h
DB 61h,63h,65h,68h,70h,72h,75h,77h
DB 80h,82h,85h,88h,90h,93h,95h,97h
DB 99h
SEGMENT7: DB 3Fh ;7段數(shù)碼管字符0的abcdefg的值,a在最低位,最高位始終保留為0
DB 06h ;7段數(shù)碼管字符1的abcdefg的值
DB 5Bh ;7段數(shù)碼管字符2的abcdefg的值
DB 4Fh ;7段數(shù)碼管字符3的abcdefg的值
DB 66h ;7段數(shù)碼管字符4的abcdefg的值
DB 6Dh ;7段數(shù)碼管字符5的abcdefg的值
DB 7Dh ;7段數(shù)碼管字符6的abcdefg的值
DB 07h ;7段數(shù)碼管字符7的abcdefg的值
DB 7Fh ;7段數(shù)碼管字符8的abcdefg的值
DB 6Fh ;7段數(shù)碼管字符9的abcdefg的值
; 3Fh======0 0 1 1 1 1 1 1
; h g f e d c b a
; a
; ■■■■■
; ■ ■
; f■ ■b
; ■ g ■
; ■■■■■
; ■ ■
; e■ ■c
; ■ ■
; ■■■■■
; d
DISPLAY: mov DPTR,#0E000h ;寫第一位數(shù)碼管
mov r1,#40h
mov A,@r1
movx @DPTR,A
setb C
mov P3.2,C
clr C
mov P3.2,C
call DELAY_5ms
setb C
mov P3.2,C
inc r1
mov A,@r1 ;寫第二位數(shù)碼管
movx @DPTR,A
setb C
mov P3.3,C
clr C
mov P3.3,C
call DELAY_5ms
setb C
mov P3.3,C
inc r1
mov A,@r1 ;寫第三位數(shù)碼管
movx @DPTR,A
setb C
mov P3.4,C
clr C
mov P3.4,C
call DELAY_5ms
setb C
mov P3.4,C
inc r1
mov A,@r1 ;寫第四位數(shù)碼管
movx @DPTR,A
setb C
mov P3.5,C
clr C
mov P3.5,C
call DELAY_5ms
setb C
mov P3.5,C
ret
DEBUG_OUT: mov DPTR,#0E000h ;調(diào)試輸出
movx @DPTR,A
D_LOOP: setb C
mov P3.5,C
clr C
mov P3.5,C
ajmp D_LOOP
ret
;雙字節(jié)二進(jìn)制無符號(hào)數(shù)乘法
;被乘數(shù)在R2(高位)、R3(低位)中,乘數(shù)在R6(高位)、R7(低位)中。
;乘積在R2(高位)、R3、R4、R5(低位)中。
;用到累加器A,B,PSW,R2~R7。
;永遠(yuǎn)不會(huì)產(chǎn)生進(jìn)位。
;在出口時(shí)總是清除C。
;若結(jié)果超出2個(gè)字節(jié)范圍則OV=1。
;無需調(diào)用其它子程序。
MULD2:
MOV A,R3
MOV B,R7
MUL AB
MOV R4,B
MOV R5,A
MOV A,R3
MOV B,R6
MUL AB
ADD A,R4
MOV R4,A
CLR A
ADDC A,B
MOV R3,A
MOV A,R2
MOV B,R7
MUL AB
ADD A,R4
MOV R4,A
MOV A,R3
ADDC A,B
MOV R3,A
CLR A
RLC A
XCH A,R2
MOV B,R6
MUL AB
ADD A,R3
MOV R3,A
MOV A,R2
ADDC A,B
MOV R2,A
ORL A,R3
JZ MULD21
SETB OV
RET
MULD21:
CLR OV
RET
;四字節(jié)無符號(hào)數(shù)除法
;R0存放著被除數(shù),除數(shù),商數(shù)的地址。
;從R0開始的連續(xù)四個(gè)字節(jié)為結(jié)果的余數(shù),入口時(shí)可以為任意,但在出口時(shí)發(fā)生變化。
;其后的連續(xù)4個(gè)字節(jié)在入口時(shí)是被除數(shù),出口時(shí)是商數(shù)。
;再其后的連續(xù)四個(gè)字節(jié)在入口時(shí)是除數(shù),出口時(shí)保持不變。
;用到累加器A,B,PSW,R0~R7。
;如果除數(shù)為零,則置OV=1標(biāo)志,否則清零。
;在出口時(shí)總是清除C,請(qǐng)注意!
;無需調(diào)用其它子程序。
DIVD4:
MOV A,R0
MOV B,A
ADD A,#08h
MOV R1,A
MOV A,#00h
ORL A,@R1
INC R1
ORL A,@R1
INC R1
ORL A,@R1
INC R1
ORL A,@R1
JZ DIVD45
MOV R1,B
MOV R2,#04h
DIVD41:
MOV @R1,#00h
INC R1
DJNZ R2,DIVD41
MOV R3,#20h
DIVD42:
MOV R2,#08h
MOV A,B
MOV R0,A
ADD A,#07h
MOV R1,A
CLR C
DIVD43:
MOV A,@R1
RLC A
MOV @R1,A
DEC R1
DJNZ R2,DIVD43
MOV A,R0
ADD A,#03h
MOV R1,A
MOV A,R0
ADD A,#0Bh
MOV R0,A
MOV A,@R1
SUBB A,@R0
MOV R4,A
DEC R1
DEC R0
MOV A,@R1
SUBB A,@R0
MOV R5,A
DEC R1
DEC R0
MOV A,@R1
SUBB A,@R0
MOV R6,A
DEC R1
DEC R0
MOV A,@R1
SUBB A,@R0
MOV R7,A
JC DIVD44
MOV A,B
MOV R0,A
ADD A,#03h
MOV R1,A
MOV A,R4
MOV @R1,A
DEC R1
MOV A,R5
MOV @R1,A
DEC R1
MOV A,R6
MOV @R1,A
DEC R1
MOV A,R7
MOV @R1,A
MOV A,R0
ADD A,#07h
MOV R1,A
INC @R1
DIVD44:
DJNZ R3,DIVD42
MOV R0,B
CLR OV
CLR C
RET
DIVD45:
SETB OV
CLR C
RET
end
復(fù)制代碼
作者:
Dsimple
時(shí)間:
2016-11-28 15:42
wetyhdutdutyidftityd
作者:
a25575703
時(shí)間:
2017-12-28 05:17
樓主厲害!
作者:
AGC4@
時(shí)間:
2020-5-7 11:28
樓主的程序能滿足我這個(gè)題目以下的要求嗎?電阻、電容和電感測(cè)試儀 簡(jiǎn)易電阻、電容和電感測(cè)試儀 (1)任務(wù) 設(shè)計(jì)并制作一臺(tái)數(shù)字顯示的電阻、電容和電感測(cè)試儀。 (2)要求 ①測(cè)量范圍:電阻100Ω~1MΩ,電容100pF~1uF,電感100uH~10mH; ②測(cè)量精度為:±5%; ③用LCD為顯示器,顯示其值; ④其他功能。
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1