📄 rfid_userio.c
字号:
// $Id: rfid_UserIO.c,v 1.4 2006/10/18 18:15:12 tprescott Exp $
/*****************************************************
Project : rfid_UserIO.c
Date : 9/08/2006
Author : Toby Prescott
Company : Atmel
Comments: AVR Studio GCC
Revisions:
v1.0 - Started written for CodeVision
v2.2 - 3/8/06 Changed the I/O checking to single routine.
v2.6 - 9/8/06 Clean for WinAVR
*****************************************************/
#include "rfid_UserIO.h"
uint8_t volatile cButton; //Global var that stores the button currently pressed
uint8_t ioActive = 1; //Flag that triggers if the user I/O is checked or not
uint8_t cRelease = 1; //Flag that triggers if the buzzer sounds
uint8_t uio_Get(void)
{
unsigned char temp, i;
//Disable Joystick
DDRC &= ~0x01; // Set Joystick Comm input
PORTC |= 0x01; // Set Joystick Comm pullup
//Enable Pushbuttons
DDRC |= 0x02; // Set Function Comm output
PORTC &= ~0x02; // Set Function Comm low
cButton = NO_INPUT; // Clear previous I/O read
for(i=0; i<100; i++){;} // Wait for inputs to stablize 16 * 125ns/cycle = 2us
temp = ~PINC & 0x3C; // Mask the inputs from the Pushbuttons
if(temp) // If Pushbuttons inputs present, isolate the button
{
if(temp == 0x04){cButton = IO_F4;}
else if(temp == 0x08){cButton = IO_F3;}
else if(temp == 0x10){cButton = IO_F2;}
else if(temp == 0x20){cButton = IO_F1;}
}
else // If Pushbuttons inputs not present
{
//Disable Pushbuttons
DDRC &= ~0x02; // Set Function Comm input
PORTC |= 0x02; // Set Function Comm
//Enable Joystick
DDRC |= 0x01; // Set Joystick Comm output
PORTC &= ~0x01; // Set Joystick Comm low
for(i=0; i<100; i++){;} // Wait for inputs to stablize 16 * 125ns/cycle = 2us
if(!(PINE & 0x80)){cButton = IO_ENTER;} // Check for center press
else
{
temp = ~PINC & 0x3C; // Mask the inputs from the Joystick
if(temp) // If Joystick inputs present, isolate the direction
{
if(temp == 0x04){cButton = IO_DOWN;}
else if(temp == 0x08){cButton = IO_LEFT;}
else if(temp == 0x10){cButton = IO_RIGHT;}
else if(temp == 0x20){cButton = IO_UP;}
}
}
}
if(cButton && cRelease){snd_Play(BEEPFREQ1,BEEPFREQ0,BEEPTIME);} // Audio feedback
return cButton;
}
void uio_Release(void)
{
cRelease = 0;
while(uio_Get() != 0){;} // Wait for button release
cRelease = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -