benscott171
Newbie level 1
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.
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.