Micro Controller Data Type Help

Micro Controller Data Type Help

#include "sfr62p.h"

typedef struct{ unsigned int data:8;

Programming Assignment Help Order Now

unsigned int unread:1;

unsigned int live:1;

} key;

key button;

void keyscan(void)

{

static unsigned char pattern;

static unsigned char keys;

static unsigned char masked;

static unsigned char autorepeat;

static _Bool first=1;

static _Bool debouncing=1;

button.live=0;

keys=P8;

masked=keys&0x1C;

if(masked!=0x1C) // has button been pushed

{

if(debouncing) // is this the first push

{

debouncing=0;

first=1;

autorepeat=1;

if( ( pattern=P8&0x1C)==0x18 ) //wich button has pushed

button.data='A'; // pressed ??

else if( pattern==0x14)

button.data='B';

else if( pattern==0x0C)

button.data='C';

else

button.live=0;

}

else

{

if ( autorepeat--==0)

{

keys=P8&0x1C;

if(keys==pattern)

{

button.live=1;

if(first)

{

first=0;

autorepeat=40; // 1 second wait

}

else

{

autorepeat=10; // 250ms between characters

}

}

else

{

debouncing=1;

button.live=0;

first=1;

}

}

}

}

else

{

debouncing=1;

button.live=0;

first=1;

}

if(button.live)

button.unread=1;

}

char getcommand(void)

{

char command;

if(button.unread)

command=button.data;

else

command='X';

button.unread=0;

return(command);

}

Assignment help | Micro Controller Data Type Help | Micro Controller Data Type Assignment Help | Micro Controller Data Type Online Help | Online Tutoring | Sample Homework