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 read more than one button by debouncing?

Status
Not open for further replies.

auto_mitch

Full Member level 3
Joined
Oct 14, 2004
Messages
172
Helped
16
Reputation
32
Reaction score
3
Trophy points
1,298
Activity points
1,240
I am trying to read a button by debouncing. I am using cvavr and i have configured the interrupt service routine of timer0. the problem is that i cannot set and reset the output LED1. And how can i read more than one buttons?
thanx
Code:
// Alphanumeric LCD Module functions
#asm                                      
   .equ __lcd_port=0x18 ;PORTA
#endasm
#include <mega8515.h>
#include <lcd.h>
#include<delay.h>

#define LEFT PINC.2
#define UP PINC.3
#define DOWN PINC.4
#define RIGHT PINC.5 
#define ENTER PINC.6 
#define LED1 PORTB.0
#define LED2 PORTB.1


int timecounter=0,flag1;
bit newstate, oldstate, btnstate;
// Timer 0 overflow ISR.
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{

 // Reload for 320 ticks.
 TCNT0=6;
if(PINC.2) timecounter++;
else timecounter=0;
btnstate=0;
if(timecounter>10)
btnstate=1;
}
void main(void)
{ 

// Set pinc.2 to pin.6 as input
PORTC=0xFF;
DDRC=0x83;

// Port B Initialization.
DDRB=0xFF;   
PORTB=0x00;
//Timer0 Initialization.
//Set clock/1024 as counter input
TCCR0= 0x05;                    
//Start timer with 0 in timer.
TCNT0=0;
//Timer interrupt initialization
// Unmask Timer 0 overflow interrupt
TIMSK=0x02;
// LCD Initialization.
lcd_init(16);
// Global enable interrupts
#asm ("sei")
while (1)
      {   
        if(btnstate) flag1=1;
        else flag1=0;
        if(flag1) LED1=1;
       else LED1=0;
        
      };
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top