ComAidSystem (Communication Aid System)
an embedded system written in C
May 2010
By Joseph Paul Cohen, Timmy Mbaya, Brendan Davis
AVR Memory Usage
----------------
Device: atmega168p
Program: 3608 bytes (22.0% Full)
(.text + .data + .bootloader)
Data: 793 bytes (77.4% Full)
(.data + .bss + .noinit)
int main()
{
//initializes bitcount to 11 (1 start, 1 parity, 8 data, 1 stop
bitcount = NUM_BITS;
//initializes system global variables
init_sysvarStates();
//Enable pin change interrupts from the keyboard clock
enable_pcint(KB_PCINT);
//Initialize scancode tables
initTables();
//Sets up the keyboard after BAT test
keyboard_setup();
//sets AVR global interrupt flag
sei();
// enable: nlcd_init does not by default
nlcd_init();
nlcd_enable_scrolling();
//clears the LCD screen
deletefn(NO_USE_CHAR);
//forever loop . Everything will happen within the
//interrupt handler whenever interrupts are set off by the keyboard
while(1)
;
return 0;
}
ISR(PCINT1_vect){
static unsigned char char_data = 0;
//If negative edge, ignore start, parity and stop bits and read bit
if ((PINC & (1 << PINC3)) == 0 ) {
//we only take the 8 data bits
if (bitcount < NUM_BITS && bitcount > 2) {
char_data = (char_data >> 1);
if (PINC & 0x04)
char_data = (char_data | 0x80);
}
//If we received a byte...
if (--bitcount == 0) {
bitcount = NUM_BITS;
//Decode and process received scancode
process_scancode(char_data);
}
}
}
void enable_pcint(int pcintnum){
//We use PCINT11 but we could have used other PCINT's
if ((pcintnum >= 8) && (pcintnum <= 14)) {
//Enables pin change interrupts from PCINT8-14
PCICR |= 0x2;
//Unmasks pin change interrupt from PCINT11 only
PCMSK1 |= 0x8;
//Sets PINC3 as input for data
DDRC &= ~(1 << DDC3);
//Sets pull-up on PINC3
PORTC |= (1 << PORTC3);
//Completes Tri-state (Hi-Z) DDxn:0 PORTxn:1 PUD:1 (MCUCR)
MCUCR |= (1 << PUD);
//Sets PINC2 as input for data
DDRC &= ~(1 << DDC2);
//Sets pull-up on PINC2
PORTC |= (1 << PORTC2);
//Completes Tri-state (Hi-Z) DDxn:0 PORTxn:1 PUD:1 (MCUCR)
MCUCR |= (1 << PUD);
}
}
to be finished later...
More documents can be found here Manuals