Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to glow a led using interrupt

Status
Not open for further replies.

i_chaitanya

Member level 2
Joined
Jun 4, 2012
Messages
47
Helped
4
Reputation
10
Reaction score
5
Trophy points
1,288
Location
pune
Activity points
1,569
hey guys !!
what i want to do is i want to glow LEDs (lets say connected to RB4-RB7)
i have a switch connected to RB0 pin
when i press the switch an interrupt is to be generated and the LED should glow
all the LED should glow simultaneously
it will be very helpful if anybody could help me with the coding
thanks in advance:!::!:
 

Code:
#include	<htc.h>
#define RELAY RB4					
static unsigned int	relay_timer;	

void main(void)
{
	/* setup stuff */

	RELAY = 1;		
	//TRISB = 0x03;	

	OPTION_REG	= 0b11000111;
	TRISB	= 0b00000011;

	//RBPU = 0;		
	T0IE = 1;		
	//INTEDG = 1;		
	INTE = 1;		
	GIE = 1;		
	for(;;){
		CLRWDT();	
	}
}

static void interrupt
isr(void)			
{
	if(T0IF) {				
		PORTB ^= 4;
		if(relay_timer){
			relay_timer--;	
			PORTB |= 8;
		}else{
			RELAY = 1;		
		PORTB &= ~8;	
		}
		T0IF = 0;			
	}
	if(INTF) {				
		RELAY = 0;			
		relay_timer = 16;	
		INTF = 0;			
	}
}





here is a code can any body explain me what is happening in this code
equivalent proteus snapshot or any other schematic will be highly appreciated
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top