Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F84A LED interrupt

Status
Not open for further replies.

monchichi

New Member
hi please help
i'm new just learn PIC for 1 week.
i'm currently using pic16f84a to do the LED display.
i want to the LED display and interrupt for 2sec after that LED display agian.
but doesn't work with the PIC i write.

list p=pic16f84a
include p16f84a.inc
__config _hs_osc & _wdt_off & _pwrte_on & _cp_off
errorlevel -302 ;

cblock h'0c'
count1
count2
endc

;**************** Program Start ***********************
org 0
goto start

;**************** Initial Process *********************
start
bsf status,rp0
movlw h'ff'
movwf trisa
clrf trisb
bcf status,rp0
movlw h'ff'
movwf portb
bsf intcon,f
loop
call timer
decfsz count1,f
goto loop
timer
movlw d'2'
movwf count2
end

please help.
 
hi,
Have a look at this program.:)

You were using the timer loops incorrectly.
This will flash an LED on/off on PORTB.

To change the flash rate, change this decimal.
movlw d'25'
movwf count1


Code:
	list	p=pic16f84a
	include	p16f84a.inc
	__config _HS_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF

	errorlevel -302		;

	cblock	h'0c'
count1
count2
	endc

;**************** Program Start ***********************  
	org	0
	goto	start

;**************** Initial Process *********************  
start
	bsf	STATUS,RP0
	movlw	h'ff'
	movwf	TRISA
	clrf	TRISB
	bcf	STATUS,RP0
	movlw	h'ff'
	movwf	PORTB
	bsf	INTCON,F

loop
	movlw	0xff
	movwf	PORTB
	call	timer
	movlw	0x00
	movwf	PORTB
	call	timer
	goto	loop
		 

timer
	movlw	d'25'
	movwf	count1
lp0
	movlw	d'250'
	movwf	count2
lp1
	decfsz	count2,F
	goto	lp1

	decfsz	count1,F
	goto	lp0
		 
	return

	end

BTW: you are not using Interrupts.

EDIT: Use this delay calculator for your programs.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top