Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdbool.h>
void Interrupt_INIT(void);
void scanKeypad(void);
int findKey(int, int);
void debounce_timer_name(void);
void timer_name(int);
int main(void)
{
Interrupt_INIT();
debounce_timer_name();
while(1)
{
if(flagVariable == 1)
{
_delay_ms(50); // Debounce delay
scanKeypad();
void scanKeypad(void)
{
// (Similar to Lab 3 Keypad Scanning, sets up for scanning the keypad's keys)
//
DDRB &= (1 << DDB0) | (1 << DDB1) | (1 << DDB2) | (1 << DDB3); // Columns are
inputs
DDRD |= (1 << DDD4) | (1 << DDD5) | (1 << DDD6) | (1 << DDD7); // Rows are
outputs
DDRB |= (1 << DDB5);
PORTB = 0x0F;
PORTB = 0x0F;
int i = 0; // Columns
int j = 0; // Rows
if(key == 0)
timer_name(0);
else if(key == 1)
timer_name(200);
else if(key == 2)
timer_name(300);
else if(key == 3)
timer_name(400);
else if(key == 4)
timer_name(500);
else if(key == 5)
timer_name(600);
else if(key == 6)
timer_name(700);
else if(key == 7)
timer_name(800);
else if(key == 8)
timer_name(900);
else if(key == 9)
timer_name(1000);
}
}
void debounce_timer_name()
{
OCR0A = 78; // Debounce (every 5ms)
TIMSK0 |= (1 << OCIE0A);
}