sau đây là đoạn chương trình tôi viết cho pic 16f877a với lm35 nhưng không hiểu sao ở kết qua hiển thị khi nhiệt độ tăng giảm thì mứt tăng giảm của nó là 64 thay vì 1
chẳng hạn khi nhiệt độ tăng 32 --> 96 --> 160 --> 224 --> 288...
làm cách nào để có kết quả 32 --> 33 --->34 --->35 --->36....
nhờ các bạn chỉ giúp
chẳng hạn khi nhiệt độ tăng 32 --> 96 --> 160 --> 224 --> 288...
làm cách nào để có kết quả 32 --> 33 --->34 --->35 --->36....
nhờ các bạn chỉ giúp
Code:
;*********************************************************************** ;CHUONG TRINH DO NHIET DO VOI PIC16F877a+LM35 ;*********************************************************************** ;Nguoi thuc hien : PHAM THANH KHUYEN ;Ngay thuc hien : 26/05/2007 ;FREQUENCY: 20MHz ;OSCILLATOR: XT ;PROCESSOR: PIC16F877A ;WACHTDOD : OFF ;DIVECE:LM35 ;----------------------------------------------------------------------- ;IC pocessor PIC16f877a voi 5 ngo vao ADC & Vref+ : ;AN0,AN1,AN2,Vref+,AN4,AN5 ung voi bo 3BIT <PCFG3:PCFG0><1010> ;RA0,RA1,RA2,RA3 ,RA5,RE0 la cac chan cua PORT tuong ung ;ADCON1: <ADFM>=1 lay ket qua 2bit cua ADRESH 8bit cua ADRESL ;CAM BIEN DUNG LM35 ;Ban phim thao tac gom 7 phim nhan ; PORTC : RC5 RC4 RC3 RC2 RC1 RC0 ; KEYPAD: COL1 COL0 ROW3 ROW2 ROW1 ROW0 ;ten , ma cong dung 7 phim nhan ; PRESET: 010001 vao che do chinh mac dinh chon nhom1(1 cua 5 nhom) ; SELECT_L: 010010 qua nhom ben trai ' 1 nhom co 3 led TRAM CHUC DONVI ' ; SELECT_R: 010100 qua nhom ben phai ; LEFT: 100001 qua con so ben trai trong nhom duoc chon ; RIGHT: 100010 qua con so ben phai trong nhom duoc chon ; INC: 100100 tang gia tri con so dang chon ; DEC 101000 giam gia tri con so dang chon ;khoi hien thi : ;hien thi 5 tri so do nhiet do ung voi 5 ngo vao cua ANx ;hien thi 5 tri so dat truoc ung voi 5 nhiet do tren ;khoi hien thi dung : 2 IC74247 cap 2 bo ma hinh | D0.2 D1.2 D2.2 D3.2 , D0.1 D1.1 D2.1 D3.1 | ;2 IC74LS138 mat noi tiep lam thanh bo dem 15 de SET 15 anot led 7 ; portD : MA HINH 1 MA HINH 2 ; RD7 RD6 RD5 RD4 RD3 RD2 RD1 RD0 ; D3.2 D2.2 D1.2 D0.2 D3.1 D2.1 D1.1 D0.1 ; PORTB: MA CHON CON SO ; RB4 RB3 RB2 RB1 RB0 ; LED9_15 LED1_8 C B A ;---------------------------------------------------------------------------- LIST P=16F877A INCLUDE <P16F877A.INC> __CONFIG _XT_OSC &_WDT_OFF&_LVP_OFF ;............................................................................ CBLOCK 0X20 ;CAC BIEN CHO CAC CON SO CUA LED HIEN THI ;byte cao la con so cua led hien thi tri so dat truoc ;byte thap la con so cua led hien thi gia tri nhiet do hien thoi DIGI_1 ;TRAM_nhiet1 DIGI_2 ;CHUC_nhiet1 DIGI_3 ;DONVI_nhiet1 ; DIGI_4 ;TRAM_nhiet2 DIGI_5 ;CHUC_nhiet2 DIGI_6 ;DONVI_nhiet2 ; DIGI_7 ;TRAM_nhiet3 DIGI_8 ;CHUC_nhiet3 DIGI_9 ;DONVI_nhiet3 ; DIGI_10 ;TRAM_nhiet4 DIGI_11 ;CHUC_nhiet4 DIGI_12 ;DONVI_nhiet4 ; DIGI_13 ;TRAM_nhiet5 DIGI_14 ;CHUC_nhiet5 DIGI_15 ;DONVI_nhiet5 ; CHANEL ;BIEN LUU TRI SO CHANEL : .0 .1 .2 .3 .4 CHANEL_ACTION ;BIEN CHANEL HOAT DONG : .0 .1 .2 .4 .5 CHANEL_TEMP ACQUI_TIME ;BIEN VE THOI GIAN CHO A/D ;CAC BIEN LUU FSR_SAVE W_SAVE S_SAVE ;CAC BIEN CUA PHEP CHUYEN BCD R0 R1 R2 L_BYTE H_BYTE COUNT TEMP ;CAC BIEN CHO HIEN THI LED_SET MAHINH COUNT1 COUNT2 ;CAC BIEN KEYPAD ENDC ;................................................................ ;CAC HANG SO ; START_RAM0 EQU 0X20 ;dia chi ram bat dau tren BANK0 END_RAM0 EQU 0X50 ;dia chi ram ket thuc tren BANK0 LED1_8 EQU 3 ;RB3 LAY SO DEM TU 1 TO 8 LED9_15 EQU 4 ;RB4 LAY SO DEM TU 9 TO 15 ;................................................................. ;CHUONG TRINH BAT DAU TU DAY ORG 0 GOTO START ORG 4 ; GOTO ISR ;CHUONG TRINH CHINH TAI DAY START ;thiet lap ban dau CALL CLEAR_RAM CALL INI_PORT CALL INI_ANALOG ;chuong trinh chinh MAIN CALL READ_ANALOG CALL B2_BCD CALL SAVE_RESULT ; INCF CHANEL,F INCF CHANEL_ACTION,F MOVLW .5 SUBWF CHANEL,W BTFSC STATUS,Z CLRF CHANEL CLRF CHANEL_ACTION ; MOVLW .100 MOVWF COUNT2 HT_LAI CALL HIENTHI DECFSZ COUNT2,F GOTO HT_LAI GOTO MAIN ;CAC CHUONG TRINH CON ;---------------------------------------------------------------- CLEAR_RAM MOVLW START_RAM0 MOVWF FSR NEXT CLRF INDF INCF FSR,F MOVLW END_RAM0 SUBWF FSR,W BTFSS STATUS,Z GOTO NEXT RETURN ;---------------------------------------------------------------- INI_PORT BCF STATUS,RP1 BSF STATUS,RP0 MOVLW B'00101111' MOVWF TRISA MOVLW B'00000001' MOVWF TRISE CLRF TRISB CLRF TRISD MOVLW B'00001111' MOVWF TRISC BCF STATUS,RP0 CLRF PORTA CLRF PORTB CLRF PORTC CLRF PORTD CLRF PORTE RETURN ;------------------------------------------------------------------- INI_ANALOG MOVLW B'10001010' ;result Right justified PCFG<3:0>=<1010> MOVWF ADCON1 ;AN7:D AN6:D AN5:A AN4:A AN3:Vref+ AN2:A AN1:A AN0:A MOVLW B'10000000' ;a/d clock Fosc/32 <7:6> RA0 chanel selected <5:3> MOVWF ADCON0 ;a/d module still off RETURN ;---------------------------------------------------------------- READ_ANALOG MOVF CHANEL_ACTION,W MOVWF CHANEL_TEMP MOVLW .3 SUBWF CHANEL_ACTION,W BTFSS STATUS,Z GOTO KHAC3 MOVLW .4 MOVWF CHANEL_ACTION KHAC3 MOVF CHANEL_ACTION,W MOVWF CHANEL_TEMP BCF STATUS,C RLF CHANEL_TEMP,F RLF CHANEL_TEMP,F RLF CHANEL_TEMP,F MOVLW B'11000000' ANDWF ADCON0,F MOVF CHANEL_TEMP,W IORWF ADCON0,F BSF ADCON0,ADON MOVLW .70 MOVWF ACQUI_TIME ACQUILOOP DECFSZ ACQUI_TIME,F GOTO ACQUILOOP BSF ADCON0,GO CONVERTLOOP BTFSC ADCON0,GO GOTO CONVERTLOOP BSF STATUS,RP0 ;selected bank1 MOVF ADRESL,W BCF STATUS,RP0 MOVWF L_BYTE MOVF ADRESH,W MOVWF H_BYTE ; BCF ADCON0,ADON BCF ADCON0,GO RETURN ;---------------------------------------------------------------- SAVE_RESULT MOVFW FSR MOVWF FSR_SAVE MOVF CHANEL,W ADDWF CHANEL,W ADDWF CHANEL,W ADDWF CHANEL,W ADDLW 0X20 MOVWF FSR MOVFW R1 ANDLW B'00001111' MOVWF INDF INCF FSR,F MOVFW R2 ANDLW B'11110000' MOVWF INDF SWAPF INDF,F INCF FSR,F MOVFW R2 ANDLW B'00001111' MOVWF INDF MOVFW FSR_SAVE MOVWF FSR RETURN ;---------------------------------------------------------------- ;CHUONG TRINH HIEN THI HIENTHI CLRF LED_SET BSF LED_SET,LED1_8 ; DAT LED_SET=8 MOVFW FSR MOVWF FSR_SAVE MOVLW 0X20 MOVWF FSR ;FSR DANG LAY DIA CHI DIGI1 HT0 MOVF INDF,W MOVWF PORTD MOVF LED_SET,W MOVWF PORTB CALL DELAY CLRF PORTB CLRF PORTD INCF FSR,F INCF LED_SET,F MOVLW .23 ;LED_SET TANG TU 8 TOI 22 = 14 LAN SE DUNG LAI SUBWF LED_SET,W BTFSS STATUS,Z GOTO HT0 MOVFW FSR_SAVE MOVWF FSR RETLW 0 ;---------------------------------------------------------------- DELAY MOVLW .255 MOVWF COUNT1 LAPLAI DECFSZ COUNT1,F GOTO LAPLAI RETURN ;-------------------------------------------------------------------------- ; CHUONG TRINH : B2_BCD ;chuyen so nhi phan 2 byte sang nhi phan BCD ;so 2 byte : H_BYTE L_BYTE ;con so BCD : R0 R1 R2 ; LUU Y: sau qua trinh chuyen doi tri so cua L_BYTE va H_BYTE bi thay doi ;-------------------------------------------------------------------------- B2_BCD bcf STATUS,0 ; clear the carry bit movlw .16 movwf COUNT clrf R0 clrf R1 clrf R2 loop16 rlf L_BYTE, f rlf H_BYTE, f rlf R2, f rlf R1, f rlf R0, f ; decfsz COUNT, f ; routine for bcd conversion goto adjDEC retlw 0 ; adjDEC movlw R2 movwf FSR call adjBCD ; no bank switching, always ; ; indirect access for RAM movlw R1 movwf FSR call adjBCD ; movlw R0 movwf FSR call adjBCD ; goto loop16 ; adjBCD movlw 3 addwf INDF,W movwf TEMP btfsc TEMP,3 ; test if result > 7 movwf INDF movlw 30 addwf INDF,W movwf TEMP btfsc TEMP,7 ; test if result > 7 movwf INDF ; save as MSD retlw 0 END
Comment