Go to the documentation of this file.00001
00012 #define _BUTTON_C_ 1
00013
00014 #include <avr/io.h>
00015 #include <avr/interrupt.h>
00016 #include <util/delay.h>
00017 #include "button.h"
00018 #include "uart.h"
00019
00020
00021 void button_init(void) {
00022
00023
00024 DDRC |= (1<<PC4) | (1<<PC5);
00025 DDRD |= (1<<PD5) | (1<< PD6) | (1<<PD7);
00026 DDRB |= (1<<PB0);
00027
00028
00029 PORTC |= (1<<PC4) | (1<<PC5);
00030 PORTD |= (1<<PD5) | (1<< PD6) | (1<<PD7);
00031 PORTB |= (1<<PB0);
00032 _delay_ms(1);
00033
00034
00035
00036 DDRC &= ~((1<<PC4) | (1<<PC5));
00037 DDRD &= ~((1<<PD5) | (1<< PD6) | (1<<PD7));
00038 DDRB &= ~((1<<PB0));
00039
00040 }
00041
00042 uint8_t button_read(void) {
00043 uint8_t tmp;
00044
00045 tmp=0;
00046 tmp |= ( PINC & (1<<PC5) ) >> 5;
00047 tmp |= ( PINC & (1<<PC4) ) >> 3;
00048 tmp |= ( PINB & (1<<PB0) ) << 2;
00049 tmp |= ( PIND & (1<<PD7) ) >> 4;
00050 tmp |= ( PIND & (1<<PD6) ) >> 2;
00051 tmp |= ( PIND & (1<<PD5) );
00052
00053
00054 return ~tmp;
00055
00056 }
00057
00058 void button_process(void) {
00059 static uint8_t read=0;
00060 uint8_t old;
00061 uint8_t mask;
00062 uint8_t diff;
00063 uint8_t sample0;
00064 static uint8_t sample1=0;
00065 uint8_t tmp;
00066 uint8_t i;
00067
00068
00069
00070
00071
00072
00073 sample0 = sample1;
00074 sample1 = button_read();
00075 mask = (sample0 ^ sample1);
00076 old = read;
00077 read = ( (old & mask) | (sample1 & (~mask)) );
00078
00079
00080 diff = (old ^ read);
00081
00082
00083 tmp = (read & diff);
00084 for(i=0; i<6; i++) {
00085 if(tmp & (1<<i)) {
00086 uart_sendbyte('a'+i);
00087 }
00088 }
00089
00090
00091 tmp = ( (~read) & diff);
00092 for(i=0; i<6; i++) {
00093 if(tmp & (1<<i)) {
00094 uart_sendbyte('A'+i);
00095 }
00096 }
00097
00098 }