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.

Timer0 Interrupts. Help!!!

Status
Not open for further replies.

benscott171

Newbie level 1
Joined
Nov 26, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
Hi

I am trying to modify the following code so that the LED on PORTD is desplayed every 2second. I cant figure it out for the life in me!! I think about looping the timer
But as far as I can see the timer is opperatring in the background and so how do I loop it? I have a hit that the LED does not have to flash every time the interrupt occures.
But i canot see how to achieve this.

//=========================================================================================
// Preprocessor Directives
//=========================================================================================
#include<io16f877.h>
#pragma vector=0x04



//=========================================================================================
// Global Variables
//=========================================================================================


//=========================================================================================
// ANSI Prototypes
//=========================================================================================
__interrupt void my_ISR(void);
void del(void);

//=========================================================================================
// The Main Program
//=========================================================================================

void main(void)//Main Program Starts Here
{
//Timer0, interrupt, PORTA and PORTB are initialised here


TRISB=0x00;
TRISD=0x00;
OPTION=0x07;
INTCON=0xa0;
TMR0=0x00;
PORTD=0x00;
PORTB=0x00;


while(1)
{
del();
PORTB=PORTB+1;
}


}
//========================================================================================
// User Defined Functions
//========================================================================================

void del(void)
{
unsigned int i;
for (i=0;i<32000;i++);
return;
}

//========================================================================================

__interrupt void my_ISR(void)

{

T0IF=0;
PORTD=PORTD^0x08;
TMR0=0x00;

}



Thanks for any help.
 

benscott171 said:
I am trying to modify the following code so that the LED on PORTD is desplayed every 2second.

Is this only one LED? If so there is no need to use the PORTB=PORTB+1; command. Instead you can use:

Code:
while(1)
{
  del();
  if (!PORTB)
    PORTB = 0xFF;
  else
    PORTB = 0;
}

Question: you said that the LED is in PORTD, but you are driving PORTB. If it is on PORTD, then in the above code replace PORTB with PORTD.
Assuming that you have done proper initializations and your delay function is OK, then it should work.

Hope this helps.

EDIT: With the above code you don't need timer interrupt, remove the code inside interrupt.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top