Need "debouncing Code" in C++ For Interrupt routine - Urgent !!
The way I have my code is such that when there is an interrupt in the p0.5 , pin
The ISR works - which is to BLINK an LED. on p1.3.
Now what I want to do is that i need to make sure the edge has been triggered or not , so I want to add a 1 second delay after which the cpu checks if the interrupt is still true or not and proceeds with the ISR.
so basically . here's my working code -- I need to add debounce code in here.
//------------------------------------------------------------------
#include <C8051F330.h>
#define SYSCLK 245000000
sbit SW1 = P0^5;
sbit LED = P1^3;
void Oscillator_Init (void); // Initiating Oscillator,Ports & Interrupts.
void Port_Init (void);
void Ext_Interrupt_Init (void);
void main (void)
{
PCA0MD &= ~0x40;
Oscillator_Init();
Port_Init ();
Ext_Interrupt_Init();
EA = 1;
while(1);
}
void Oscillator_Init (void)
{
OSCICN = 0x83;
}
void Port_Init (void)
{
XBR1 = 0x40;
P0SKIP = 0x20; // input is p0.5 , digital , open drain
P1MDOUT = 0x08; // led digital , push pull p1.3
}
void Ext_Interrupt_Init (void)
{
TCON = 0x01; //INT0 , active low
IT01CF = 0x05;
EX0 = 1; // Enable int0
}
void INT0_ISR (void) interrupt 0
{ // I need a debounce code here
LED = !LED;
}
//---------------------------------------------------------------------
How do I write this ?? I would really appreciate any help .
The ISR works - which is to BLINK an LED. on p1.3.
Now what I want to do is that i need to make sure the edge has been triggered or not , so I want to add a 1 second delay after which the cpu checks if the interrupt is still true or not and proceeds with the ISR.
so basically . here's my working code -- I need to add debounce code in here.
//------------------------------------------------------------------
#include <C8051F330.h>
#define SYSCLK 245000000
sbit SW1 = P0^5;
sbit LED = P1^3;
void Oscillator_Init (void); // Initiating Oscillator,Ports & Interrupts.
void Port_Init (void);
void Ext_Interrupt_Init (void);
void main (void)
{
PCA0MD &= ~0x40;
Oscillator_Init();
Port_Init ();
Ext_Interrupt_Init();
EA = 1;
while(1);
}
void Oscillator_Init (void)
{
OSCICN = 0x83;
}
void Port_Init (void)
{
XBR1 = 0x40;
P0SKIP = 0x20; // input is p0.5 , digital , open drain
P1MDOUT = 0x08; // led digital , push pull p1.3
}
void Ext_Interrupt_Init (void)
{
TCON = 0x01; //INT0 , active low
IT01CF = 0x05;
EX0 = 1; // Enable int0
}
void INT0_ISR (void) interrupt 0
{ // I need a debounce code here
LED = !LED;
}
//---------------------------------------------------------------------
How do I write this ?? I would really appreciate any help .
0