⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adanddisplay_070201_fin.asm

📁 把AD转换的数据在LED上显示
💻 ASM
字号:
;display the number in BCD code
;参考电压5V,对应100,0V对应0
;同时,实际显示的时候是5V对应99.xx
;0V对应0.39
;这个问题好像是应为AD转换,然后再乘了一个系数,0.39/每位

;define foot start

CLK	EQU	P1.1
DIO	EQU	P1.2

;MAX7219
MAX_CS	EQU	P1.3

;AD ADC0834
AD_SARS	EQU	P3.4
AD_CS	EQU	P1.4

;define foot end

;PROGRAM START
	ORG	0000H
	SJMP	START
	
	ORG	0050H
START:	
	SETB	0AFH	;IE.7,(interrupt enable register).7 = ALL INT	;中断总允许
	SETB	0A8H	;IE.0 = E INT0	

	NOP

	LCALL	DELAY
	LCALL	DELAY_1S
	LCALL	MAX_INITIAL
	LCALL	DELAY	
;	LCALL	MAX_TEST	;test mode seem not to act
REPEAT:	
	LCALL	AD_CONVERTER
	LCALL	DATA_CHANGE
	
	MOV	A,35H
	ADD	A,#80H
	MOV	35H,A		;添加小数点
	
	MOV	R4,#5		;显示的小数位数
	MOV	R0,#37H		;地址单元尾地址
	MOV	R5,#08H		;the most left 7-seg led 
DISPLAY_LOOP:	
	CLR	MAX_CS
	MOV	A,@R0
	MOV	R6,A		;
	LCALL	SEND_16BIT

	NOP
	DEC	R0		;转到下一个位数
	DEC	R5		;7-SEG数码管左移一位
	DJNZ	R4,DISPLAY_LOOP
	LCALL	DELAY
	LJMP	REPEAT

;数据调整
	ORG	0200H
DATA_CHANGE:
	MOV	A,30H
	MOV	B,#27H
	MUL	AB
	MOV	31H,A	;low byte A-31H
	MOV	32H,B	;high byte B-32H

	MOV	R7,32H	;high byte
	MOV	R6,31H	;low byte
	LCALL	B2BCD
	MOV	33H,R3	;万位
	MOV	A,R4	
	ANL	A,#0F0H	;取高4位
	SWAP	A	
	MOV	34H,A	;千位
	MOV	A,R4	
	ANL	A,#0FH	;取高4位
	MOV	35H,A	;百位
	MOV	A,R5	
	ANL	A,#0F0H	;取高4位
	SWAP	A	
	MOV	36H,A	;十位
	MOV	A,R5	
	ANL	A,#0FH	;取低4位
	MOV	37H,A	;个位
;转换过程中,小数点在百位上,同时不显示个位!所以37H可以不要
;33H,34H,35H,36H,37H 对应的是 万、千、百、十、个
;实际对应的是温度的百、十、个、小数点后1、小数点后2
	RET

;the start of time delay subprogram
;时间延迟 50ms
	ORG	0500H
DELAY:
	MOV	R7,#200
DEL1:	MOV	R6,#125
DEL2:	DJNZ	R6,DEL2
	DJNZ	R7,DEL1
	RET
;the end of time delay subprogram

;时间延迟 50ms x 20 = 1s
	ORG	0550H
DELAY_1S:
	MOV	R5,#21
D_1S_1:
	LCALL	DELAY
	DJNZ	R5,D_1S_1
	RET

;max7219 initialize
	ORG	0800H
MAX_INITIAL:
	CLR	CLK	;
;
;scan limit
	CLR	MAX_CS	
	MOV	R5,#0BH	;scan limit register
	MOV	R6,#07H	;
	LCALL	SEND_16BIT
	SETB	MAX_CS
	NOP

;intensity register
	CLR	MAX_CS
	MOV	R5,#0AH	;intensity register
	MOV	R6,#0FH	;most brightness
	LCALL	SEND_16BIT
	NOP
;shutdown or normal operation	
	CLR	MAX_CS
	MOV	R5,#0CH	;shutdown mode register
	MOV	R6,#01H	;
	LCALL	SEND_16BIT
	NOP
;	LCALL	DELAY
;BCD decode
	CLR	MAX_CS	
	MOV	R5,#09H	;decode mode register
	MOV	R6,#0FFH	;
	LCALL	SEND_16BIT
	NOP
	RET

;max7219 test mode
;这个子程序没有用好
	ORG	0600H
MAX_TEST:

	CLR	CLK	;AD clock low	;时钟

	CLR	MAX_CS	;MAX select LOW_SINGAL	;片选 低电平有效
	MOV	R5,#0FH	;test mode address "X X X X 1 1 1 1" = "XF"
	MOV	R6,#0F1H	;Display-Test Register in test mode "X X X X X X X 1"
	LCALL	SEND_16BIT

	LCALL	DELAY_1S

	CLR	MAX_CS
	MOV	R5,#0FH		;test mode address "X X X X 1 1 1 1" = "XF"
	MOV	R6,#0F0H	;Display-Test Register in Normal Operation mode "X X X X X X X 0"
	LCALL	SEND_16BIT
	RET

;send 8 bit to the DIO sub program
;实现把A中的数据传送到 DIO 引脚中
	ORG	0300H
SEND_EIGHTBIT:
	CLR	C
	MOV	R7,#08H
INSIDE_SEND_EIGHTBIT:
	CLR	CLK
	RLC	A	;rotate left with the flag C	;把A的首位移到C中
	MOV	DIO,C
	NOP
	NOP
	SETB	CLK
	NOP
	NOP
	DJNZ	R7,INSIDE_SEND_EIGHTBIT
	RET
;the end of send 16 bit to the MAX7219 sub program

;the subprogram of send 16 bits
;the entrance is that r5 the 1st byte and r6 the 2nd byte
	ORG	0330H
SEND_16BIT:
	MOV	R7,#8
	MOV	A,R5
;send the first byte
INSIDE_SEND_16BIT_1:
	CLR	CLK
	RLC	A	;rotate left with the flag C	;把A的首位移到C中
	MOV	DIO,C
	NOP
	NOP
	SETB	CLK
	NOP
	NOP
	DJNZ	R7,INSIDE_SEND_16BIT_1
;send the 7 of 8 of the 2nd byte
	MOV	R7,#08H
	MOV	A,R6
INSIDE_SEND_16BIT_2:
	CLR	CLK
	RLC	A	;rotate left with the flag C	;把A的首位移到C中
	MOV	DIO,C
	NOP
	NOP
	SETB	CLK
	NOP
	NOP
	DJNZ	R7,INSIDE_SEND_16BIT_2
	SETB	MAX_CS	;max_cs must be ahead of the 16th clk signal
	NOP
	RET
;the end of send 16 bit to the max7219 sub program

;the start of BtoBCD subprogram	
;二进制转换成BCD码

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -