C:\Users\MINH HAI\Desktop\VDK\DO NHIET DO.asm #INCLUDE "p16f887.inc" ; config 0xE0F7 CONFIG _CONFIG1, _FOSC_EXTRC_CLKOUT & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _IESO_OFF & _FCMEN_OFF & _LVP_OFF ; CONFIG2 ; config 0xFFFF CONFIG _CONFIG2, _BOR4V_BOR40V & _WRT_OFF ; khai bao bien cblock 0x20 nhietdo tam0 dem adc_value adc bat den so dv hc tram tam d0 d1 d2 d3 endc ; ORG goto 0x00 start ; ; ;************************************************************************************ ; -bat dau chuong trinh o day -start ;cai dat ngo vao ngo banksel TRISB ; chon bank chua ghi TRISB clrf TRISB ; PortB la output movlw B'00000001' movwf TRISA ; chan RA0 input clrf TRISD ; -banksel PORTA clrf PORTA clrf PORTB clrf PORTD ; chon loai banksel movlw movwf clrf ngo vao AI hay DI ANSEL ; chon bank chua ghi ANSEL B'00000001' ; AN0 la analog ANSEL ; tat cac cac kenh lai ANSELH ; la digital banksel PORTB ; khai bao chuyen doi ADC banksel ADCON1 ; chon bank chua ghi ADCON1 movlw 0x80 movwf ADCON1 banksel movlw movwf ADCON0 B'10000001' ADCON0 ; chon bank chua ADCON0 ; tan so xung doi Fosc/32, ; RA0 duoc su cho chuyen doi ; chuyen doi AD duoc bat/cho phep ; -chuong trinh chinh -main call docADC; cap nhat gia tri moi, tach so cho hien thi call check_alarm ; kiem tra nhiet cho phep va bat/tat canh bao (den, coi bao) call tachso call hienthi ;chuong trinh co nhien thi nhiet led doan call Delay2s C:\Users\MINH HAI\Desktop\VDK\DO NHIET DO.asm exit_main goto main ; ;===================================================================================== ; cac chuong trinh hienthi; chuong trinh hien thi nhiet LED7 doan: XY0C clrf PORTD movfw hc ; hien thi hang chuc call bangma movwf PORTD bcf PORTB,4 ; bat led hang chuc call delay bsf PORTB,4 ; tat led hang chuc movfw call movwf bcf call bsf dv ; hien thi hang don vi bangma PORTD PORTB,5 ;bat led hang don vi delay PORTB,5 ;bat led hang don vi movlw movwf bcf call bsf 0x9C ; hien thi ki hieu "0" PORTD PORTB,6 ;bat led delay PORTB,6 ; tat led movlw movwf bcf call bsf call 0xC6 ; hien thi chu "C" PORTD PORTB,7 ;bat led hang delay PORTB,7 ;bat led hang delay return ; -chuong trinh2: doc adc : tra ve gia tri : "adc_tam" -docADC ; doc gia tri adc va luu vao bien adc_value nop bsf btfsc goto ADCON0,1 ADCON0,1 $-1 ; batdau chuyen doi adc ; chuyen doi xong ? ; chua xong ==1,kiem tra lai banksel movf TRISB ADRESL,0 banksel movwf bcf rrf bcf movwf movlw subwf PORTB adc_value STATUS,C adc_value,0 STATUS,C so d'1' so,1 ; ; ; ; ; chon bank1 byte thap la ket qua copied to W chon bank2 luu ket qua vao bien : adc_value ; w = adc_value/2 = nhiet ; so = w ; cai phan la ta tru di cho hien ; thi dung thoi return tachso ; tach nhiet so BCD de hien thi LED doan clrf dv clrf hc tru sai0 movlw subwf btfsc goto goto d'10' so,f STATUS,C sai0 dung0 incf goto hc,f tru C:\Users\MINH HAI\Desktop\VDK\DO NHIET DO.asm dung0 movlw addwf movwf d'10' so,w dv return ; chuong trinh 1: ham kiem tra va bao chay -check_alarm ; kiem tra nhiet cho phep va bat/tat canh bao (den, coi bao) ; tatbd banksel movf sublw btfsc goto goto bcf bsf goto bsf bcf exit_check return batbd PORTB adc_value,0 ; gan w = adc_value d'82' ; w = w-70 STATUS,C ; c == ? tatbd ; c = : w < 82 hay nhiet < 35oC batbd ; c = : w > 82 hay nhiet lon hon 35oC PORTB,0 PORTB,1 exit_check PORTB,0 PORTB,1 ; -chuong trinh 4: delay Delay movlw 0x09 movwf d0 Delay_0 decfsz d0, f goto Delay_0 return ; Delay2s movlw movwf movlw movwf movlw movwf Delay_2 decfsz goto decfsz goto decfsz goto 0x5A d1 0xCD d2 0x16 d3 d1, f $+2 d2, f $+2 d3, f Delay_0 nop return bangma addwf retlw retlw retlw retlw retlw retlw retlw retlw retlw retlw PCL,f 0xc0 0xf9 0xa4 0xb0 0x99 0x92 0x82 0xf8 0x80 0x90 end ;