View Single Post
Old 19-03-2006, 09:30 AM   #10
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
Code:
;========================================
;Author:		NHH
;Date:		18/03/06
;Hardware:	PIC16F877A 
;		QUARTZ  10MHz
;========================================
	PROCESSOR	PIC16f877A 
	INCLUDE<P16f877A.inc> 
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _CPD_OFF &_LVP_OFF
;========================================
	COUNT1 EQU 0x20
	COUNT2 EQU 0x21
	COUNT3 EQU 0x22
	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
;===============MAIN PROGRAM===========
	ORG 	0x000
	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,TMR0IF

	DECFSZ	COUNT1,F
	RETFIE
	MOVLW	d'154'
	MOVWF	COUNT1

	INCF	COUNT2,F
	MOVF	COUNT2,W
	CALL	TABLE
	MOVWF	PORTB

	CALL	CHECK_YELLOW
	CALL	CHECK_GREEN
	CALL	CHECK_RED

	MOVLW	d'10'
	SUBWF	COUNT2,W
	BTFSS	STATUS,0
	RETFIE
	CLRF	COUNT2
	INCF	COUNT3,F
	MOVF	COUNT3,W
	CALL	TABLE
	MOVWF	PORTC

	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
;.............................................................................................
MAIN
	BCF 	STATUS,RP1
	BSF 	STATUS,RP0 		; select BANK 1
	CLRF 	TRISB 			; PORTB,C,D  output
	CLRF 	TRISC
	CLRF 	TRISD
	BSF	OPTION_REG,PS0		;TMR0 rate 1: 64
	BCF	OPTION_REG,PS1
	BSF	OPTION_REG,PS2
	BCF	OPTION_REG,PSA		;Prescaler is assigned to the Timer0 module
	BCF	OPTION_REG,T0CS		;enable TMR0
	BCF 	STATUS,RP0 		;select BANK 0

	BSF	INTCON,GIE
	BSF	INTCON,TMR0IE
	BCF	INTCON,TMR0IF

	MOVLW	d'154'
	MOVWF	COUNT1
	MOVLW	d'1'
	MOVWF	COUNT2
	CLRF	COUNT3
	MOVLW	b'00000110'
	MOVWF	PORTB
	MOVLW	b'00111111'
	MOVWF	PORTC

	MOVLW	b'00000100'
	MOVWF	PORTD
	GOTO	$
;========================================
CHECK_YELLOW
	BTFSS	PORTD,0
	GOTO	$+2
	RETURN
	MOVLW	d'2'
	SUBWF	COUNT3,W
	BTFSS	STATUS,0
	RETURN
	MOVLW	b'00000110'
	MOVWF	PORTD
	RETURN
CHECK_GREEN
	BTFSC	PORTD,0
	GOTO	$+2
	RETURN
	MOVLW	d'2'
	SUBWF	COUNT3,W
	BTFSS	STATUS,0
	RETURN
	GOTO	MAIN
	RETURN
CHECK_RED
	MOVLW	d'3'
	SUBWF	COUNT3,W
	BTFSS	STATUS,0
	RETFIE

	MOVLW	d'1'
	MOVWF	COUNT2
	CLRF	COUNT3
	MOVLW	b'00000110'
	MOVWF	PORTB
	MOVLW	b'00111111'
	MOVWF	PORTC
	MOVLW	b'00000001'
	MOVWF	PORTD
	RETURN	
;-----------------------------------------------------------------------
; Bang tra ve Digital tu 0 den 9 
; Chi so dau truy cap la 0
; Bang o PAGE 0

	ORG 0x90
TABLE
;-----------------------------------------------------------------------
	ADDWF 	PCL, F 			; bat dau tai 0x80
	RETLW 	b'11111111' 		; NO DISPLAY
	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'00111111' 		; 0

	END
File Kèm Theo
File Type: rar Traffic light.rar (22.9 KB, 671 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
nhh vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn