tình hình là em viết chương trình đếm xung từ RA4 hiển thị led 7 đoạn dùng timer0. cứ 1200ms thì đọc tmr0 một lần rồi cho hiển thị. nhưng mà thử trên textboard + proteus thì nó đếm lung tung lắm. lúc thì ra số này, lúc thì số khác. mong các pro giải thích giùm e cái...
CODE NHƯ SAU
PROCESSOR 16F877A
#INCLUDE <P16F877A.INC>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
DEM EQU 20H
DEMX EQU 21H
DEMA EQU 22H
DEMB EQU 26H
CHUC EQU 23H
DONVI EQU 24H
TRAM EQU 25H
ORG 0000H
BCF STATUS,6
BSF STATUS,5
BSF TRISA,4
CLRF TRISB
CLRF TRISE
BCF STATUS,5
CLRF PORTA
CLRF PORTB
CLRF PORTE
DEMXUNG
BSF STATUS,5
BCF OPTION_REG,3
BCF OPTION_REG,2
BCF OPTION_REG,1
BCF OPTION_REG,0
BCF OPTION_REG,4
BCF STATUS,5
CLRF TMR0
BSF STATUS,5
BSF OPTION_REG,5
BCF STATUS,5
MAIN
CLRF TRAM
CLRF CHUC
CLRF DONVI
MOVF TMR0,W
MOVWF DEMX
CLRF TMR0
CALL TACHSO
MOVLW D'50'
MOVWF DEM
LAPLED
BCF PORTE,0
BSF PORTE,1
BSF PORTE,2
MOVF TRAM,W
CALL BANG
MOVWF PORTB
CALL DELAY_10MS
BSF PORTE,0
BCF PORTE,1
BSF PORTE,2
MOVF CHUC,W
CALL BANG
MOVWF PORTB
CALL DELAY_10MS
BSF PORTE,0
BSF PORTE,1
BCF PORTE,2
MOVF DONVI,W
CALL BANG
MOVWF PORTB
CALL DELAY_10MS
DECFSZ DEM,1
GOTO LAPLED
GOTO MAIN
TACHSO
TROLAI
MOVLW D'10'
SUBWF DEMX,1
BTFSS STATUS,0
GOTO THOAT
INCF CHUC,1
MOVLW D'10'
XORWF CHUC,0
BTFSS STATUS,2
GOTO TROLAI
INCF TRAM,1
CLRF CHUC
GOTO TROLAI
THOAT
MOVLW D'10'
ADDWF DEMX,0
MOVWF DONVI
RETURN
BANG
ADDWF PCL,1
RETLW B'11000000'
RETLW B'11111001'
RETLW B'10100100'
RETLW B'10110000'
RETLW B'10011001'
RETLW B'10010010'
RETLW B'10000010'
RETLW B'11111000'
RETLW B'10000000'
RETLW B'10010000'
DELAY_10MS
MOVLW D'101'
MOVWF DEMA
LOOPDELAY
DECFSZ DEMA,1
GOTO LOOPDELAY1
GOTO THOATDELAY
LOOPDELAY1
MOVLW D'33'
MOVWF DEMB
LOOPDELAY2
DECFSZ DEMB,1
GOTO LOOPDELAY2
GOTO LOOPDELAY
THOATDELAY
RETURN
END
MONG CÁC PRO CHỈ GIÁO SỚM. E ĐANG CẦN
CODE NHƯ SAU
PROCESSOR 16F877A
#INCLUDE <P16F877A.INC>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
DEM EQU 20H
DEMX EQU 21H
DEMA EQU 22H
DEMB EQU 26H
CHUC EQU 23H
DONVI EQU 24H
TRAM EQU 25H
ORG 0000H
BCF STATUS,6
BSF STATUS,5
BSF TRISA,4
CLRF TRISB
CLRF TRISE
BCF STATUS,5
CLRF PORTA
CLRF PORTB
CLRF PORTE
DEMXUNG
BSF STATUS,5
BCF OPTION_REG,3
BCF OPTION_REG,2
BCF OPTION_REG,1
BCF OPTION_REG,0
BCF OPTION_REG,4
BCF STATUS,5
CLRF TMR0
BSF STATUS,5
BSF OPTION_REG,5
BCF STATUS,5
MAIN
CLRF TRAM
CLRF CHUC
CLRF DONVI
MOVF TMR0,W
MOVWF DEMX
CLRF TMR0
CALL TACHSO
MOVLW D'50'
MOVWF DEM
LAPLED
BCF PORTE,0
BSF PORTE,1
BSF PORTE,2
MOVF TRAM,W
CALL BANG
MOVWF PORTB
CALL DELAY_10MS
BSF PORTE,0
BCF PORTE,1
BSF PORTE,2
MOVF CHUC,W
CALL BANG
MOVWF PORTB
CALL DELAY_10MS
BSF PORTE,0
BSF PORTE,1
BCF PORTE,2
MOVF DONVI,W
CALL BANG
MOVWF PORTB
CALL DELAY_10MS
DECFSZ DEM,1
GOTO LAPLED
GOTO MAIN
TACHSO
TROLAI
MOVLW D'10'
SUBWF DEMX,1
BTFSS STATUS,0
GOTO THOAT
INCF CHUC,1
MOVLW D'10'
XORWF CHUC,0
BTFSS STATUS,2
GOTO TROLAI
INCF TRAM,1
CLRF CHUC
GOTO TROLAI
THOAT
MOVLW D'10'
ADDWF DEMX,0
MOVWF DONVI
RETURN
BANG
ADDWF PCL,1
RETLW B'11000000'
RETLW B'11111001'
RETLW B'10100100'
RETLW B'10110000'
RETLW B'10011001'
RETLW B'10010010'
RETLW B'10000010'
RETLW B'11111000'
RETLW B'10000000'
RETLW B'10010000'
DELAY_10MS
MOVLW D'101'
MOVWF DEMA
LOOPDELAY
DECFSZ DEMA,1
GOTO LOOPDELAY1
GOTO THOATDELAY
LOOPDELAY1
MOVLW D'33'
MOVWF DEMB
LOOPDELAY2
DECFSZ DEMB,1
GOTO LOOPDELAY2
GOTO LOOPDELAY
THOATDELAY
RETURN
END
MONG CÁC PRO CHỈ GIÁO SỚM. E ĐANG CẦN