Have you read the geekhack TOS lately?
0 Members and 1 Guest are viewing this topic.
#include <avr/io.h>#include <avr/power.h>#include <avr/wdt.h> static void setup_mcu(void){ /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Disable clock division */ clock_prescale_set(clock_div_1);} int main(void){ setup_mcu(); //DDRB = 0x00; PORTB = 0x00; // input(HiZ) DDRB = 0x00; PORTB = 0xFF; // input with pull-up //DDRB = 0xFF; PORTB = 0x00; // output Lo //DDRB = 0xFF; PORTB = 0xFF; // output Hi while(1) ;}
/* Column pin configuration* col: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16* pin: F4 B6 D1 D0 B7 E6 B3 B2 F0 B1 B0 D2 D3 C6 C7 D5 D4*//* Row pin configuration* row: 0 1 2 3 4* pin: F7 F6 B5 F5 F1*/static void init_cols(void){ DDRF &= (0<<4 | 0<<0); PORTF |= (1<<4 | 1<<0); DDRE &= (0<<6); PORTE |= (1<<6); DDRD &= (0<<5 | 0<<4 | 0<<3 | 0<<2 | 0<<1 | 0<<0); PORTD |= (1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0); DDRC &= (0<<7 | 0<<6); PORTC |= (1<<7 | 1<<6); DDRB &= (0<<7 | 0<<6 | 0<<3 | 0<<2 | 0<<1 | 0<<0); PORTB |= (1<<7 | 1<<6 | 1<<3 | 1<<2 | 1<<1 | 1<<0);}static matrix_row_t read_cols(void){ return (PINF&(1<<4) ? 0 : (1UL<<0)) | (PINB&(1<<6) ? 0 : (1UL<<1)) | (PIND&(1<<1) ? 0 : (1UL<<2)) | (PIND&(1<<0) ? 0 : (1UL<<3)) | (PINB&(1<<7) ? 0 : (1UL<<4)) | (PINE&(1<<6) ? 0 : (1UL<<5)) | (PINB&(1<<3) ? 0 : (1UL<<6)) | (PINB&(1<<2) ? 0 : (1UL<<7)) | (PINF&(1<<0) ? 0 : (1UL<<) | (PINB&(1<<1) ? 0 : (1UL<<9)) | (PINB&(1<<0) ? 0 : (1UL<<10)) | (PIND&(1<<2) ? 0 : (1UL<<11)) | (PIND&(1<<3) ? 0 : (1UL<<12)) | (PINC&(1<<6) ? 0 : (1UL<<13)) | (PINC&(1<<7) ? 0 : (1UL<<14)) | (PIND&(1<<5) ? 0 : (1UL<<15)) | (PIND&(1<<4) ? 0 : (1UL<<16)) ;}static void unselect_rows(void){ DDRF &= 0b00011101; PORTF &= 0b00011101; DDRB &= 0b11011111; PORTB &= 0b11011111;}static void select_row(uint8_t row){ switch (row) { case 0: DDRF |= (1<<7); // "1<<.." = output (strobing) PORTF &= (0<<7); // "0<<.." = LOW break; case 1: DDRF |= (1<<6); // "1<<.." = output (strobing) PORTF &= (0<<6); // "0<<.." = LOW break; case 2: DDRB |= (1<<5); // "1<<.." = output (strobing) PORTB &= (0<<5); // "0<<.." = LOW break; case 3: DDRF |= (1<<5); // "1<<.." = output (strobing) PORTF &= (0<<5); // "0<<.." = LOW break; case 4: DDRF |= (1<<1); // "1<<.." = output (strobing) PORTF &= (0<<1); // "0<<.." = LOW break; }}
static void init_cols(void){ DDRF &= (0<<4 | 0<<0); PORTF |= (1<<4 | 1<<0);
DDRF &= ~(1<<4 | 1<<0); PORTF |= (1<<4 | 1<<0);