ATmega16 Development Board Tutorial (2) - KEY Lighting

Publisher:缘到泉Latest update time:2022-01-06 Source: eefocusKeywords:ATmega16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

3. KEY lighting

The register definition of the KEY pin is the same as that of the LED, which is still 3 registers: DDRx, PORTx, and PINx (for details, please refer to the LED lighting section).


DDRx: 1-output, 0-input. When configured as input, PORTx=1, pull-up enabled, PORTx=0, high configuration, but pay attention to the third pin of SDIOR, which is used to disable pull-up, so pay attention when configuring pull-up, otherwise it will be high configuration.

Figure 2-2 SFIOR register diagram


Code Explanation:


ØDefine the corresponding bits of the 3 button pin registers. Again, use the underscore to get the bit position of the register.

ØButton initialization, while allowing pull-up

ØUse the key scanning program to detect whether the three keys are triggered. If yes, return the corresponding key value, otherwise return 0. Here, the key variable is used to determine whether the key is triggered, and the detection effect is better.

For other instructions, please refer to the original project. It also uses object-oriented structure function thinking for programming, improves the C language level, and keeps pace with the times.


Simulation video


/**

******************************************************************************

* @file main.c

* @author Alex——Xiaobai

* @version V1.0

* @date 2021.1.20

* @brief LED lighting

* @store Proteus simulation store

* @Link https://shop484534014.taobao.com/

* @Email 844545015@qq.com

******************************************************************************

* @attention All Rights Reserved  

**/

#include

void main(void)

{  

    LED.LED_Init(0xFF); //LED ALL OUTPUT

    KEY.KEY_Init(); //KEY 0/1/2 INPUT   

    

    while(1)

    {

        switch(KEY.KEY_Scan())

        {

            case 1:

                LED.LED_Reverse(0); //LED0 flip

                break;

            case 2:

                LED.LED_Reverse(1); //LED1 flip

                break;

            case 3:

                LED.LED_Reverse(2); //LED2 flip

                break;

            default:   

                break;            

        }

    }

}

/********************************************************

  End Of File

************************************************************/

Keywords:ATmega16 Reference address:ATmega16 Development Board Tutorial (2) - KEY Lighting

Previous article:ATmega16 Development Board Tutorial (3) - 74HC595 driving digital tube display
Next article:ATmega16 Development Board Tutorial (1) - LED Lighting

Recommended ReadingLatest update time:2024-11-16 16:43

Design of pure hardware circuit of intelligent car control system based on ATmega16
Introduction: The article uses ATmega16 microcontroller as the control core, RF2401 wireless transceiver module for remote control communication, DS18B20 for temperature detection, and ultrasonic and other sensor materials to detect signals and obstacles. Finally, it makes full use of the serial port resources and com
[Microcontroller]
Design of pure hardware circuit of intelligent car control system based on ATmega16
Design of Intelligent Temperature Controller for Dry-Type Transformer Based on ATmega16 Single Chip Microcomputer
Introduction: This paper discusses the design of an intelligent temperature controller for dry-type transformers based on the ATmega16 microcontroller. The temperature controller has low power consumption, advanced technology, complete functions, simple operation, reliable performance, and can work stably for a long t
[Microcontroller]
Design of Intelligent Temperature Controller for Dry-Type Transformer Based on ATmega16 Single Chip Microcomputer
AVR microcontroller - (three), ATMEGA16 drive 16 * 2 dot matrix character LCD module - 01
3. ATMEGA16 drives 16*2 dot matrix character LCD 3. (01) ATMEGA16 drives 16*2 dot matrix character LCD This article is just a simple driver to make 1602 display, and does not use the part of reading data and reading status, nor does it use read and write detection (if you are interested, you can still write it here)
[Microcontroller]
AVR microcontroller - (three), ATMEGA16 drive 16 * 2 dot matrix character LCD module - 01
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号