View Single Post
Old 05-03-2006, 06:00 PM   #2
nhh
Đệ tử 9 túi
 
nhh's Avatar
 
Tham gia ngày: Feb 2006
Bài gửi: 174
:
Send a message via Yahoo to nhh
Ngắt ngoài với RB0

Đây là chương trình đếm số lần switch on từ 1 đến 9 hiển thị lên LED 7 đoạn,dùng ngắt ngoài RB0 và kỹ thuật bảng.

Code:
;========================================
;Auhor:		NHH
;Date:		02/03/06
;Hardware:	PIC16F877A ,Crystal 10MHz
;========================================
	TITLE 		"Count button on by Interrupt RB0"
	PROCESSOR	PIC16f877A 
	INCLUDE<P16f877A.inc> 
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _CPD_OFF &_LVP_OFF
;========================================
	COUNT	EQU	0x20	
w_temp		EQU	0x71		; variable used for context saving 
status_temp	EQU	0x72		; variable used for context saving
pclath_temp	EQU	0x73		; variable used for context saving			

;=============================================================================
;CHUONG TRINH CHINH
;=============================================================================
	ORG 0000h
	GOTO 	MAIN
	ORG 0004h
	GOTO	INTERRUPT

;==============================INTERRUPT PROGRAM===========================		
INTERRUPT
	movwf w_temp	 ; save off current W register contents
	movf STATUS,w 	; move status register into W register
	movwf status_temp	 ; save off contents of STATUS register
	movf PCLATH,w	 ; move pclath register into w register
	movwf pclath_temp 	; save off contents of PCLATH register
;******************************************************************************
	BCF	INTCON,INTF	;xoa co int
	INCF	COUNT,F
	MOVLW	d'10'
	SUBWF	COUNT,W
	BTFSS	STATUS,0
	GOTO	$+2
	GOTO	NODISPLAY
	MOVF	COUNT,W
	CALL	TABLE
	MOVWF	PORTD
	retfie 			; return from interrupt
NODISPLAY			;khong hien thi neu vuot qua 9
	MOVLW	d'10'
	CALL	TABLE
	MOVWF	PORTD
	RETFIE

;******************************************************************************
	movf pclath_temp,w 		; retrieve copy of PCLATH register
	movwf PCLATH 		; restore pre-isr PCLATH register contents
	movf status_temp,w 		; retrieve copy of STATUS register
	movwf STATUS 		; restore pre-isr STATUS register contents
	swapf w_temp,f
	swapf w_temp,w 		; restore pre-isr W register contents
	retfie 			; return from interrupt
;==============	CHUONG TRINH CHINH===============
MAIN
	BCF 	STATUS,RP1
	BSF 	STATUS,RP0 		; chon BANK 1
	MOVLW	b'11111111'		;RB0=Input
	MOVWF	TRISB
	CLRF	TRISD
	BCF	OPTION_REG,INTEDG	;interrupt canh xuong
	BCF 	STATUS,RP0 		; chon BANK 0
	BSF	INTCON,GIE		;cho phep interrupt toan cuc
	BSF	INTCON,INTE		;cho phep interrupt RB0
	
	CLRF	COUNT	
	MOVLW	d'0'
	CALL	TABLE	
	MOVWF	PORTD
	
	GOTO	$
;----------------------------------------------------------
; Bang tra ve Digital tu 0 den 9 va OFF
; Chi so dau truy cap la 0
; Bang o PAGE 0

	ORG 0x80
TABLE
;----------------------------------------------------------
	ADDWF 	PCL, F 		; bat dau tai 0x80
	RETLW 	b'00111111' 		; 0
	RETLW 	b'00000110' 		; 1
	RETLW 	b'01011011' 		; 2
	RETLW 	b'01001111' 		; 3
	RETLW 	b'01100110' 		; 4
	RETLW 	b'01101101' 		; 5
	RETLW 	b'01111101' 		; 6
	RETLW 	b'00000111' 		; 7
	RETLW 	b'01111111' 		; 8
	RETLW 	b'01101111' 		; 9
	RETLW 	b'00000000' 		; OFF
		
	END
Hình Kèm Theo
File Type: gif Count button on_RB0.gif (4.3 KB, 1760 lần tải)
__________________
Ngày mai bắt đầu từ ngày hôm nay

Bạn có thắc mắc, bạn cần sự hỗ trợ của các thành viên. Hãy đọc luồng này:
http://www.picvietnam.com/forum//showthread.php?t=1263

thay đổi nội dung bởi: nhh, 09-03-2006 lúc 12:11 PM.
nhh vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn