(vì thế muốn thay đổi thì chỉ thay đổi số ở đó là ok)
PROCESSOR 16F877A
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
#INCLUDE <P16F877A.INC>
CHUC EQU 20H
DVI EQU 21H
TAM EQU 22H
DEM1 EQU 23H
DEM2 EQU 24H
GIAM EQU 25H
ORG 0000H
BCF STATUS,6
BCF STATUS,5
CLRF PORTA
CLRF PORTB
CLRF PORTE
CLRF PORTD
BSF STATUS,5
CLRF TRISB
BCF TRISE,1
BCF TRISE,2
BCF TRISD,3
MAIN
CALL DOC_ADC
MOVF ADRESH,W
MOVWF TAM
MOVLW D'65'
SUBWF TAM,0
BTFSC STATUS,0
GOTO ON
GOTO OFF
KIEMTRACALL DOC_SO
MAIN_1
MOVLW B'11110000'
ANDWF TAM,0
MOVWF CHUC
SWAPF CHUC,1
MOVLW B'00001111'
ANDWF TAM,0
MOVWF DVI
MOVLW D'21'
MOVWF GIAM
HIEN_THI
BCF PORTE,1
BSF PORTE,2
MOVF CHUC,W
CALL BANG
MOVWF PORTB
CALL DELAY
BSF PORTE,1
BCF PORTE,2
MOVF DVI,W
CALL BANG
MOVWF PORTB
CALL DELAY
DECFSZ GIAM,1
GOTO HIEN_THI
GOTO MAIN
DOC_SO
DOC0_9
KT_1
MOVLW D'0'
SUBWF TAM,0
BTFSS STATUS,0
RETURN
MOVLW D'10'
SUBWF TAM,0
BTFSS STATUS,0
RETURN
MOVLW D'20'
SUBWF TAM,0
BTFSS STATUS,0
GOTO CONG_1
GOTO KT_2
KT_2
MOVLW D'30'
SUBWF TAM,0
BTFSS STATUS,0
GOTO CONG_2
GOTO KT_3
KT_3
MOVLW D'40'
SUBWF TAM,0
BTFSS STATUS,0
GOTO CONG_3
GOTO KT_4
KT_4
MOVLW D'50'
SUBWF TAM,0
BTFSS STATUS,0
GOTO CONG_4
GOTO KT_5
KT_5
MOVLW D'60'
SUBWF TAM,0
BTFSS STATUS,0
GOTO CONG_5
GOTO KT_6
KT_6
MOVLW D'70'
SUBWF TAM,0
BTFSS STATUS,0
GOTO CONG_6
GOTO KT_7
KT_7
MOVLW D'80'
SUBWF TAM,0
BTFSS STATUS,0
GOTO CONG_7
GOTO KT_8
KT_8
MOVLW D'90'
SUBWF TAM,0
BTFSS STATUS,0
GOTO CONG_8
KT_9
MOVLW D'100'
SUBWF TAM,0
BTFSS STATUS,0
GOTO CONG_9
GOTO MAIN
CONG_1
MOVLW D'6'
ADDWF TAM,1
GOTO MAIN_1
CONG_2
MOVLW D'12'
ADDWF TAM,1
GOTO MAIN_1
CONG_3
MOVLW D'18'
ADDWF TAM,1
GOTO MAIN_1
CONG_4
MOVLW D'24'
ADDWF TAM,1
GOTO MAIN_1
CONG_5
MOVLW D'30'
ADDWF TAM,1
GOTO MAIN_1
CONG_6
MOVLW D'36'
ADDWF TAM,1
GOTO MAIN_1
CONG_7
MOVLW D'42'
ADDWF TAM,1
GOTO MAIN_1
CONG_8
MOVLW D'48'
ADDWF TAM,1
GOTO MAIN_1
CONG_9
MOVLW D'54'
ADDWF TAM,1
GOTO MAIN_1
CONG_10
MOVLW D'60'
ADDWF TAM,1
GOTO MAIN_1
DOC_ADC
BCF STATUS,6
BSF STATUS,5
BCF ADCON1,3
BSF ADCON1,2
BCF ADCON1,1
BSF ADCON1,0
BCF STATUS,5
BCF ADCON0,5
BCF ADCON0,4
BCF ADCON0,3
BCF ADCON0,7
BCF ADCON0,6
BSF STATUS,5
BSF ADCON1,6
BCF ADCON1,7
BCF STATUS,5
BSF ADCON0,0
BSF ADCON0,2
LOOP_ADC
BTFSC ADCON0,2
GOTO LOOP_ADC
RETURN
BANG
ADDWF PCL,1
RETLW B'11000000';0
RETLW B'11111001';1
RETLW B'10100100';2
RETLW B'10110000';3
RETLW B'10011001';4
RETLW B'10010010';5
RETLW B'10000010';6
RETLW B'11111000';7
RETLW B'10000000';8
RETLW B'10010000';9
DELAY
BSF STATUS,5
BCF OPTION_REG,3
MOVLW D'101'
MOVWF OPTION_REG
BCF STATUS,5
BATDAU
MOVLW D'98'
MOVWF TMR0
BSF STATUS,5
BCF OPTION_REG,5
BCF STATUS,5
LOOP
BTFSS INTCON,2
GOTO LOOP
BCF INTCON,2
RETURN
ON
BCF PORTD,3
GOTO KIEMTRA
OFF
BSF PORTD,3
GOTO KIEMTRA
END
mạch nguyên lý đâu bạn
Trả lờiXóa