//头文件
#ifndef __always_inline__
#define __always_inline__ _Pragma("inline=forced")inline
#endif
#define AVR_GPIO_ASSIGN(name, port, bit) \
__always_inline__ static void GPIO_##name##_Set(void) {PORT##port |= (1 << bit);}\
__always_inline__ static void GPIO_##name##_Clr(void) {PORT##port &= ~(1 << bit);}\
__always_inline__ static void GPIO_##name##_Toggle(void) {PORT##port ^= (1 << bit);}\
__always_inline__ static uint8 GPIO_##name##_Read(void) {return (PIN##port & (1 << bit)) !=0;}\
__always_inline__ static uint8 GPIO_##name##_DdrRead(void) {return (DDR##port & (1 << bit)) !=0;}\
__always_inline__ static void GPIO_##name##_MakeOut(uint8 x) {(x)?(PORT##port |= (1 << bit)):(PORT##port &= ~(1 << bit)); DDR##port |= (1 << bit);}\
__always_inline__ static void GPIO_##name##_MakeIn(uint8 x) {DDR##port &= ~(1 << bit); (x)?(PORT##port |= (1 << bit)):(PORT##port &= ~(1 << bit));}\
__always_inline__ static void GPIO_##name##_MakePullup(void) {GPIO_##name##_MakeIn(1);}
AVR_GPIO_ASSIGN(LED_1,B,0); //LED_1-------PORTB0
AVR_GPIO_ASSIGN(LED_2,B,1); //LED_2-------PORTB1
AVR_GPIO_ASSIGN(KEY,B,2); //KEY---------PORTB2
//C文件
volatile uint8 key;
int main()
{
GPIO_LED_1_MakeOut(0); //LED_1设为输出,初始输出低
GPIO_LED_2_MakeOut(0); //LED_2设为输出,初始输出低
GPIO_KEY_MakeIn(1); //KEY设为输入,初始上拉
GPIO_LED_1_Set(); //LED_1输出高
GPIO_LED_1_Clr(); //LED_1输出低
GPIO_LED_2_Set(); //LED_2输出高
GPIO_LED_2_Clr(); //LED_2输出低
key=GPIO_KEY_Read(); //读取KEY
while(1);
}
Previous article:Using the IIC in the AVR chip to implement the continuous writing (page writing) and continuous reading procedures of AT24C256
Next article:AVR MCU IO usage precautions and structure guide
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Teach you how to apply for a free trial of the new generation of oscilloscope 40 functional software
- Evaluation Weekly Report 20211108: Playing with domestic FPGA is full of pitfalls, but you can also have fun + Topmicro smart display module, etc.
- The msp430 microcontroller sends floating point numbers to the host computer through the serial port
- Talking about software architecture from a historical perspective - DOS era (Part 2)
- WiFi remote control coffee shop equipment
- Tencent employees were fired for working less than 8 hours a day. What kind of work system is reasonable?
- Oscilloscope test inductor saturation current and inductance value
- MTK7686 serial port transparent transmission
- 【Silicon Labs Development Kit Review】+Breathing Light Example
- Shouldn't the positive and negative power supplies of the op amp be connected in series to have a reference point?