您的当前位置:首页正文

51写的0809AD转换程序

2022-05-17 来源:易榕旅网
;模数转换8位,最小精度0.02, ;ADC 0809

;外部频率500KHZ

; ------------

; 0.0~0.3位控制----|p0 p2 |-|--/8----显示段控制 ; 0.4~0.7按键---| | ; | | ; | |

; | |---ALE--CLOCK ; | |

; | |---p3.5-- OE ; A/D 8BIT---|p1 P3 |---P3.4--EOC

; | |---p3.3--START/ALE

; | |---P3.0~P3.2--显示位控制 ; -----------

;转换顺序,先选通地址,再SAA脉冲信号,延时10MS,等待EOC为高,从P1口读入,(也可以P2口读入)

;作为动态自动扫描时,用33H存显示的通道,并赋给P3口,而P3口高位全为一,保证数据的有效读入 ;晶振12MHZ

;30,31,32-=显示字,33H--8BIT,34H--MODE,35H--BIT CONTROL,36--显示通道字 37H--10 38H--FFH

STA BIT P3.6;START 11010 000 ALE BIT P3.3 ; ALE EOC BIT P3.4 OE BIT P3.5

DYBJ BIT 20H.0 ;大于比较 XYBJ BIT 20H.1 ;小于比较

CCBJ BIT 20H.2 ;存储电压标记

;*************程序开始初始化********************** ORG 0000H START:

MOV P0,#0FFH MOV P1,#0FFH MOV P3,#0D0H MOV P2,#0FFH

MOV 20H,#00H ;延时初始化 MOV R5,#25 MOV R6,#50 MOV R7,#50

MOV 30H,#0BFH; - 显示初始化 显示位 2 MOV 31H,#0BFH ; - 显示初始化 显示位 3 MOV 32H,#0BFH ; - 显示初始化 显示位4

MOV 33H,#00H ;BIT CONTROL --8

MOV 34H,#00H ;MODE SELECT COUNTER MOV 36H,#0BFH ; - 显示初始化 显示位1

; ------------存储区初始化-------- MOV 50H,#00H MOV 51H,#00H MOV 52H,#00H MOV 53H,#00H MOV 54H,#00H MOV 55H,#00H MOV 56H,#00H MOV 57H,#00H CALL XIANSHI AJMP ITMODETS

;---------------------------------------------------------------------------

DELAY: ;10 MS DJNZ R5,$ MOV R5,#25

;提高扫描次数 DJNZ R6, DELAY MOV R6,#50 RET

;*********************显示部分800MS****************** XIANSHI: MOV P2,36H CLR P0.0 CALL DELAY SETB P0.0 MOV P2,30H CLR P0.1 CALL DELAY SETB P0.1 MOV P2,31H CLR P0.2 CALL DELAY SETB P0.2 MOV P2,32H CLR P0.3 CALL DELAY

SETB P0.3

DJNZ R7,XIANSHI MOV R7,#50 RET

;----------------------模式部分--------------------------- ITMODETS:;智能模式提示 MOV 33H,#00H

MOV 36H,#0A4H ;Z MOV 30H,#0C8H ;N MOV 31H,#0A3H ;o MOV 32H,#0A3H ;o CALL XIANSHI

ITMODE: ;智能模式 JNB P0.4,AUTOMODETS CALL WBQZ MOV A,21H

CJNE A,#00H,ITMODE0 JMP ITMODE1 ITMODE0:

CALL TDXIANSHI

CALL XIANSHI ;延长时间 ITMODE1: CALL TDADD1 AJMP ITMODE

;-----------------CUN CHU MODE-------- STOREMODETS: ;智能选择,循环显示 MOV R1,#50H MOV 33H,#00H

MOV 36H,#0C6H ;C MOV 30H,#0C6H ;C MOV 31H,#0A3H ;o MOV 32H,#0A3H ;o CALL XIANSHI

JNB P0.4,STOREMODETS;防止按键时间过长,跳过该模式 STOREMODE: ;存储模式 ;初始化R1

JNB P0.4,ITMODETS MOV 21H,@R1 MOV A,21H

CJNE A,#00H, STMODE JMP STMODE0 STMODE: CALL CCTD

STMODE0: CALL TDADD1 INC R1

CJNE R1,#58H,STOREMODE MOV R1,#50H AJMP STOREMODE

;--------------AUTO MODE------------- AUTOMODETS: MOV 33H,#00H

MOV 36H,#0A4H ;Z MOV 30H,#0A1H ;d MOV 31H,#0A3H ;o MOV 32H,#0A3H ;o CALL XIANSHI

AUTOMODE: ;自动模式 JNB P0.4,MANMODETS CALL TZX CALL TDADD1 AJMP AUTOMODE

;---------------MAN MODE------------- MANMODETS: MOV 33H,#00H

MOV 36H,#092H ;S MOV 30H,#0A1H ;d MOV 31H,#0A3H ;o MOV 32H,#0A3H ;o CALL XIANSHI

MANMODE: ; 手动模式 ,具有电压存储功能 JNB P0.4,STOREMODETS CALL TZX

JB P0.6, MMD CALL DELAY JB P0.6, MMD

CALL TDADD1 ;通道加一 按键检测 AJMP MANMODE MMD:

JB P0.7,MMD0 CALL DELAY JB P0.7,MMD0

CALL TDPLUS1 ;通道减一 按键检测 AJMP MANMODE

MMD0: ;存储通道电压按键检测 JB P0.5,MANMODE

CALL DELAY

JB P0.5,MANMODE

MOV R1,#50H ;按通道存储 MOV A, 33H ADD A, R1 MOV R1,A

MOV @R1,21H ; 加入存储动作提示 MOV 36H,#0C6H MOV 30H,#0C6H MOV 31H,#0BFH MOV 32H,#0BFH CALL XIANSHI JMP MANMODE

;---------------一体化部分------------------------------- TZX:;通道,转换,显示一体化 CALL TDXIANSHI CALL WBQZ CALL XIANSHI RET

CCTD: ;存储通道,编码,显示一体化 CALL TDXIANSHI CALL CONVERT CALL XIANSHI RET

;----------------通道显示转化部分--------------------- TDXIANSHI: ;通道字的转换 MOV A,33H

MOV DPTR,#XSS MOVC A,@A+DPTR MOV 36H,A RET

TDADD1: ;通道加一 MOV A,33H INC A

CJNE A,#08H,TDTZ MOV 33H,#00H RET

TDTZ: ;通道调整 MOV 33H,A RET

TDPLUS1: ;通道减一

MOV A,33H DEC A

CJNE A,#0FFH,TDTZ;通道调整 MOV 33H,#00H RET

;+++++++++++++++++++++计数部分 JISHI BU FEN++++++++++++++++++ ;以下为电压查询部分,------------------------------------------- WBQZ: ;外部取值 MOV 20H,#00H MOV P2,#0FFH MOV 35H,33H ORL 33H,#0D0H MOV P3,33H MOV 33H,35H SETB ALE CLR STA JNB EOC,$

MOV P1,#0FFH ; 高阻态 SETB OE MOV A,P1 MOV 21H,A

CONVERT: ;电压查询转换 MOV 30H,#2 MOV 31H,#5 MOV 32H,#00H CLR OE AJMP SWCX SWCX:

MOV A,30H

MOV DPTR,#ZSB;整数表,存的是二进制电压 MOVC A,@A+DPTR

CJNE A,21H,JXC;继续查 AJMP SWCC;首位查出 JXC:

SUBB A,21H JC ADD0

AJMP PLUS0 PLUS0:

DEC 30H

JB XYBJ,ZWCX;中为查询 CLR C

SETB DYBJ AJMP SWCX ADD0:

JB DYBJ,ZWCX INC 30H CLR C

SETB XYBJ AJMP SWCX

ZWCX: ;中为查询,根据30H的值,找出表单 MOV A,30H

CX0V: CJNE A,#00H,CX1V MOV DPTR,#TAB0V AJMP ZWXC

CX1V: CJNE A,#01H,CX2V MOV DPTR,#TAB1V

AJMP ZWXC;中位详查 CX2V: CJNE A,#02H,CX3V MOV DPTR,#TAB2V AJMP ZWXC CX3V: CJNE A,#03H,CX4V MOV DPTR,#TAB3V AJMP ZWXC

CX4V: CJNE A,#04H,WRONG MOV DPTR,#TAB4V AJMP ZWXC WRONG:

MOV P2,#079H;E CPL P0.3

CALL DELAY;20MS DJNZ R7,WRONG MOV R7,#20

AJMP XIANSHI;显示上次测量电压600MS后,就重新测量 ZWXC:

MOV 20H,#00H ZWXC1:

MOV A,31H

MOVC A,@A+DPTR MOV 22H,A

CJNE A,21H,BJ AJMP ZWCC BJ:

SUBB A,21H

JC ADD1 AJMP PLUS1

PLUS1:

DEC 31H

JB XYBJ,MWCX;中为查询 CLR C

SETB DYBJ AJMP ZWXC1 ADD1:

JB DYBJ,MWCX INC 31H CLR C

SETB XYBJ AJMP ZWXC1

MWCX: ;调整22H的值为前一值,查询溢出时,调整为9 CLR C

MOV A,31H

MOVC A,@A+DPTR MOV 22H,A MWCX0:

; MOV A,22H INC 22H; INC 32H MOV A,22H

CJNE A,21H,MWCX0 MOV A,#5 SUBB A,32H JC MWYC JZ MWYC MOV A,32H RL A

MOV 32H,A AJMP CBQZ

MWYC: MOV 32H,#9 JMP CBQZ SWCC: MOV 31H,#0 ZWCC: MOV 32H,#0

CBQZ:

MOV DPTR,#DDS;带点数 MOV A,30H

MOVC A,@A+DPTR MOV 30H,A

MOV DPTR,#XSS;显示数查询 MOV A,31H

MOVC A,@A+DPTR MOV 31H,A MOV A,32H

MOVC A,@A+DPTR MOV 32H,A RET

ZSB: DB 00H, 33H ,66H, 99H,0CCH,0FFH DDS: DB 040H;0. 带点数 DB 079H;1. DB 024H;2. DB 030H;3. DB 019H;4. DB 012H;5.

XSS: DB 0C0H;0 显示数字 DB 0F9H;1 DB 0A4H;2 DB 0B0H;3 DB 099H;4 DB 092H;5 DB 082H;6 DB 0F8H;7 DB 080H;8

DB 090H;9 电压表单

TAB0V: DB 00H, 05H, 0AH, 0FH, 14H, 19H, 1EH, 23H, 28H, 2DH, 33H ; 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

TAB1V: DB 33H, 38H, 3DH, 42H, 47H, 4CH, 51H, 56H, 5BH, 60H, 66H ; 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2

TAB2V: DB 66H, 6BH, 70H, 75H, 7AH, 7FH, 84H, 89H, 8EH, 93H, 99H ; 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3

TAB3V: DB 99H, 9EH, 0A3H,0A8H,0ADH,0B2H,0B7H,0BCH,0C1H,0C6H,0CCH ; 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4

TAB4V: DB 0CCH,0D1H,0D6H,0DBH,0E0H,0E5H,0EAH,0EFH,0F4H,0F9H,0FFH ; 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5

因篇幅问题不能全部显示,请点此查看更多更全内容