mình đang làm code hiển thị điện áp trên biến trở dùng ADC. và đầu ra của ADC la đầu vào cua DAC. sử dụng VOM để đo giá trị ngõ ra của DAC
anh chị kiểm tra đoạn code này dùm em với
ORG 2000H
RS BIT P3.5
EN BIT P3.4
NCS BIT P1.0
SCK BIT P1.1
SDI BIT P1.2
NLD BIT P1.3
MOV DPTR,#8000H
ACALL LCD_INIT
LAP: MOV DPTR,#4000H
MOV A,#0
MOVX @DPTR,A
ACALL DELAY_100US
MOVX A,@DPTR
MOV DPTR,#8000H
ACALL CHIA
MOV A, #80H
ACALL WRITE_CMD
SJMP LAP
ACALL DAC
LCD_INIT: MOV A, #38H
ACALL WRITE_CMD
MOV A, #0CH
ACALL WRITE_CMD
MOV A, #04H
ACALL WRITE_CMD
MOV A, #01H
ACALL WRITE_CMD
RET
WAIT_LCD: MOV R7,#100
LOOP: MOV R6, #250
DJNZ R6,$
DJNZ R7, LOOP
RET
WRITE_CHAR: SETB RS
MOVX @DPTR,A
SETB EN
CLR EN
ACALL WAIT_LCD
RET
WRITE_CMD: CLR RS
MOVX @DPTR,A
SETB EN
CLR EN
ACALL WAIT_LCD
RET
DELAY_100US: MOV R6,#200
DJNZ R6,$
RET
CHIA: PUSH ACC
PUSH B
MOV B,#51
DIV AB
ORL A,#30H
ACALL WRITE_CHAR
MOV A,#0A5H
ACALL WRITE_CHAR
MOV A,B
MOV B,#5
DIV AB
ORL A,#30H
ACALL WRITE_CHAR
MOV A,B
MOV B,#2
MUL AB
ORL A,#30H
ACALL WRITE_CHAR
POP B
POP ACC
RET
DAC: MOV B,#16
MUL AB
XCH A,B
DAC_WRITE_16B: PUSH ACC
PUSH B
PUSH 01H
CLR NCS
SETB NLD
ACALL WRITE_8B
ACALL WRITE_8B
SETB NCS
NOP
CLR NLD
NOP
SETB NLD
POP 01H
POP B
POP ACC
RET
WRITE_8B: MOV R1,#8
CLR C
DAC_LOOP: RLC A
CLR SCK
MOV SDI,C
SETB SCK
DJNZ R1,DAC_LOOP
XCH A,B
RET
END
anh chị kiểm tra đoạn code này dùm em với
ORG 2000H
RS BIT P3.5
EN BIT P3.4
NCS BIT P1.0
SCK BIT P1.1
SDI BIT P1.2
NLD BIT P1.3
MOV DPTR,#8000H
ACALL LCD_INIT
LAP: MOV DPTR,#4000H
MOV A,#0
MOVX @DPTR,A
ACALL DELAY_100US
MOVX A,@DPTR
MOV DPTR,#8000H
ACALL CHIA
MOV A, #80H
ACALL WRITE_CMD
SJMP LAP
ACALL DAC
LCD_INIT: MOV A, #38H
ACALL WRITE_CMD
MOV A, #0CH
ACALL WRITE_CMD
MOV A, #04H
ACALL WRITE_CMD
MOV A, #01H
ACALL WRITE_CMD
RET
WAIT_LCD: MOV R7,#100
LOOP: MOV R6, #250
DJNZ R6,$
DJNZ R7, LOOP
RET
WRITE_CHAR: SETB RS
MOVX @DPTR,A
SETB EN
CLR EN
ACALL WAIT_LCD
RET
WRITE_CMD: CLR RS
MOVX @DPTR,A
SETB EN
CLR EN
ACALL WAIT_LCD
RET
DELAY_100US: MOV R6,#200
DJNZ R6,$
RET
CHIA: PUSH ACC
PUSH B
MOV B,#51
DIV AB
ORL A,#30H
ACALL WRITE_CHAR
MOV A,#0A5H
ACALL WRITE_CHAR
MOV A,B
MOV B,#5
DIV AB
ORL A,#30H
ACALL WRITE_CHAR
MOV A,B
MOV B,#2
MUL AB
ORL A,#30H
ACALL WRITE_CHAR
POP B
POP ACC
RET
DAC: MOV B,#16
MUL AB
XCH A,B
DAC_WRITE_16B: PUSH ACC
PUSH B
PUSH 01H
CLR NCS
SETB NLD
ACALL WRITE_8B
ACALL WRITE_8B
SETB NCS
NOP
CLR NLD
NOP
SETB NLD
POP 01H
POP B
POP ACC
RET
WRITE_8B: MOV R1,#8
CLR C
DAC_LOOP: RLC A
CLR SCK
MOV SDI,C
SETB SCK
DJNZ R1,DAC_LOOP
XCH A,B
RET
END
Comment