//ui.c
//user interface
//initialize the user interface
void UI_Init(void)
begin
PushState = NoPush;
Button_DDR = 0x00;//set as inputs
Button_PORT = 0xff;//pull up on
Clr_Butnum;
//Use Timer3 for debounce timing
//prescalar 64
//ovrfl at 0xffff = 0.262 ms
TCCR3B = 0x03;//ck/64
end
//debounces the push buttons
void debounce(void)
begin
unsigned char Butnum;
Butnum = ~Button_PIN;
switch(PushState)
begin
case NoPush:
if (Butnum > 0) PushState=MaybePush;
else PushState=NoPush;
break;
case MaybePush:
if (Butnum > 0)
begin
PushState=Pushed;
Current_Butnum=Butnum;
end
else PushState=NoPush;
break;
case Pushed:
if (Butnum > 0)
begin
PushState=Pushed;
//current_Butnum = Butnum;
end
else PushState=MaybeNoPush;
break;
case MaybeNoPush:
if (Butnum > 0)
begin
PushState=Pushed;
end
else
begin
Set_Butnum;
PushState=NoPush;
//current_Butnum=Butnum;
end
end//switch
end//debounce keypad
|