joystick_hw.h

来自「实现液晶多层菜单的程序」· C头文件 代码 · 共 38 行

H
38
字号
#ifndef __JOYSTICK_HW_H__
#define __JOYSTICK_HW_H__

#ifdef AVR

#include <avr/io.h>

# ifndef JOYSTICK_PORT

// Default to PORTC, lines PC0 - PC4

#  define JOYSTICK_PORT     PORTC
#  define JOYSTICK_PORT_IN  PINC
#  define JOYSTICK_DDR      DDRC
#  define JOYSTICK_PORT_MASK 0x1f

#  define JOYSTICK_UP     _BV(PC0)
#  define JOYSTICK_DOWN   _BV(PC1)
#  define JOYSTICK_LEFT   _BV(PC2)
#  define JOYSTICK_RIGHT  _BV(PC3)
#  define JOYSTICK_BUTTON _BV(PC4)
# endif // #ifndef JOYSTICK_PORT

// Set up joystick lines as input with pullup resistors

# define joystick_hw_init() (JOYSTICK_DDR &= ~JOYSTICK_PORT_MASK,    \
		             JOYSTICK_PORT |= JOYSTICK_PORT_MASK)

// Change result so lines active low are returned as "1"

# define joystick_hw_read() ((JOYSTICK_PORT_IN & JOYSTICK_PORT_MASK) \
		                    ^ JOYSTICK_PORT_MASK)

#endif // #ifdef AVR

#endif //#ifndef __JOYSTICK_HW_H__

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?