/FollowMe/button.c |
---|
0,0 → 1,50 |
#include "timer0.h" |
#include "button.h" |
#ifdef USE_FOLLOWME |
#define BUTTON !(PINC & (1<<PINC6)) |
#endif |
#ifdef USE_SDLOGGER |
#define BUTTON !(PINC & (1<<PINC3)) |
#endif |
#define CNT_KEY 10 // at least 3 |
#define KEY_DELAY_MS 50 |
uint16_t ButtonTimer = 0; |
void Button_Init(void) |
{ |
// set port pin as input pullup |
#ifdef USE_FOLLOWME |
PORTC |= (1 << PORTC6); |
DDRC &= ~(1 << DDC6); |
#endif |
#ifdef USE_SDLOGGER |
PORTC |= (1 << PORTC3); |
DDRC &= ~(1 << DDC3); |
#endif |
ButtonTimer = SetDelay(KEY_DELAY_MS); |
} |
uint8_t GetButton(void) |
{ |
static uint8_t button = 0; |
uint8_t ret = 0; |
if(CheckDelay(ButtonTimer)) |
{ |
if(BUTTON) |
{ |
if(button++ == 0 || button == CNT_KEY) ret = 1; |
if(button == CNT_KEY) button = CNT_KEY - CNT_KEY / 3; |
} |
else button = 0; |
ButtonTimer = SetDelay(KEY_DELAY_MS); |
} |
return(ret); |
} |
/FollowMe/button.h |
---|
0,0 → 1,11 |
#ifndef _BUTTON_H |
#define _BUTTON_H |
#include <avr/io.h> |
#include <inttypes.h> |
extern void Button_Init(void); |
extern uint8_t GetButton(void); |
#endif //_BUTTON_H |
/FollowMe/main.c |
---|
64,6 → 64,7 |
#include "printf_P.h" |
#include "analog.h" |
#include "ubx.h" |
#include "button.h" |
#ifdef USE_FOLLOWME |
int16_t UBat = 120; |
93,6 → 94,7 |
UBX_Init(); |
USART1_Init(); |
ADC_Init(); |
Button_Init(); |
// enable interrupts global |
sei(); |
LEDRED_OFF; |
133,6 → 135,9 |
GPS_Timer = SetDelay(1000); |
while (1) |
{ |
// check for button action |
if(GetButton()) BeepTime = 200; |
// restart ADConversion if ready |
if(ADReady) |
{ |
/FollowMe/makefile |
---|
76,7 → 76,7 |
########################################################################################################## |
# List C source files here. (C dependencies are automatically generated.) |
SRC = main.c uart0.c uart1.c printf_P.c timer0.c menu.c led.c ubx.c analog.c |
SRC = main.c uart0.c uart1.c printf_P.c timer0.c menu.c led.c ubx.c analog.c button.c |
#ssc.c sdc.c fat16.c |
########################################################################################################## |