Description: In the previous article about the Atmel AVR, only LED blinking was demonstrated without any external event influence on the microprocessor. All ports operated solely as outputs, with no input functionality. This article will illustrate how to connect control buttons to the microcontroller and utilize the INT0 and INT1 pins as inputs. The Atmega8 microcontroller is chosen for this demonstration, although the newer Atmega8A can also be used. The buttons will be connected to pins 4 and 5, which correspond to bits 3 and 4 of port D, and also serve as INT0 and INT1. These alternative functions are significant as they serve as external interrupt sources. When these interrupts are enabled, the inputs can trigger the interrupt handler. The INT1 interrupt is activated using the most significant bit in the GICR register, while the INT0 interrupt is enabled using the second highest bit. Both interrupts can be enabled by setting the two upper bits of GICR to 1. Next, it is necessary to select the trigger conditions for the interrupts, which is achieved using the MCUCR register. The sensitivity for INT0 is determined by a combination of the ISC01 and ISC00 bits, while the sensitivity for INT1 is determined by the ISC10 and ISC11 bits. In this example, the sensitivity is set to trigger on the falling edge, which means each pair is set to 1 and 0. Pressing the button will now initiate the corresponding interrupt handler. In this scenario, the handler increments or decrements the working register REG and subsequently sends its state to output, specifically to port C, which controls the first six bits. The status of these bits is indicated by six LEDs. A binary counter is thus created, where one button adds 1 and the other subtracts 1. A schematic diagram of this experimental circuit is provided below, and a video demonstrating its function is available at the bottom of the page. Numerous other applications for the buttons can also be explored. When no interrupts are being executed, the program enters an endless loop (referred to as SMYCKA in the code). Although there is currently nothing in the loop, additional functionality can be incorporated. The program is available for download below.
The Atmega8 microcontroller operates at a voltage range of 2.7V to 6V and can be programmed using the AVR-GCC toolchain. In this schematic, the connections for the buttons to pins 4 and 5 of port D are essential for enabling the external interrupts. Pull-up resistors are typically used to ensure that the pins read a high state when the buttons are not pressed. When a button is pressed, the corresponding pin is pulled low, triggering the interrupt.
The GICR register controls the interrupt enable bits, allowing for precise control over which interrupts are active. By configuring the ISC bits in the MCUCR register, the sensitivity of the interrupts can be tailored to specific applications. In this case, setting ISC01 and ISC00 to 1 and 0, respectively, configures INT0 to trigger on a falling edge, while ISC10 and ISC11 are set similarly for INT1.
The handling of the interrupts is crucial for the functionality of the binary counter. Upon triggering, the ISR (Interrupt Service Routine) can be programmed to increment or decrement the REG variable, which holds the current count. The output to port C allows the status of the counter to be visually represented by the six LEDs, providing immediate feedback on the current count.
In addition to the basic functionality described, further enhancements can be made to the program. For instance, debouncing logic can be implemented to prevent multiple triggers from a single button press due to mechanical bounce. Furthermore, additional features such as long-press detection or multi-button combinations could expand the capabilities of the circuit.
The schematic diagram should include all necessary components, including the Atmega8 microcontroller, buttons, pull-up resistors, and the six LEDs connected to port C. Proper labeling of each component and clear connections will facilitate understanding and reproduction of the circuit.In previous article about the Atmel AVR We have only blinked with LEDs, without influence of events outside the microprocessor. All ports operated only as outputs, there was no input. Now we will show how to connect control buttons to the microcontroller and how to the INTO and INT1 pins as inputs.
To demonstrate this, I chose the Atmega8 (You can also use the newer Atmega8A). The buttons are connected to pins 4 and 5, which are bits 3 and 4 of the port D, but also have an alternative function - INT0 and INT1. These alternative functions are in our interest. They are external interrupt sources. If these interrupts are enabled, you can use these inputs to trigger the interrupt handler. INT1 interrupt is enabled using the most significant bit in register GICR. Interrupt INT0 is enabled using the second highest bit. Enabling both interrupts we do by setting the two upper bits of GICR to 1: Next, we have to select what will trigger the interrupt - the interrupt sensitivity.
This is done by using the MCUCR registr. Sensitivity of INT0 is chosen by combination of two bits - ISC01 and ISC00. Sensitivity INT1 is chosen bits ISC10 and ISC11. In our example, we want sensitivity to the falling edge, and therefore each pair is set to 1 0. We can do it this way: Pressing the button now initiates the appropriate interrupt handler. In our example, this is the increment / decrement the working register REG and subsequently sending its state on output, which is a port C - its first 6 bits. Its status is indicated by 6 LED. Now you have built the binary counter, you can press a one button to add 1 and second button to substract 1.
Schematic diagram of this experimental circuit you can see below. This video on the bottom of this page demonstrates the function. You can certainly find a lot of other things to which buttons can be used :). When no interrupt is being executed, the program loops it the endless loop (called SMYCKA in the cource code). There`s nothing in the loop, but you can add something. The program is available for download below.
Cymbet Corporation provides rechargeable solid-state batteries designed for advanced microcontroller power backup applications. The company is recognized as a leader in thin-film energy storage technology.
Cymbet Corporation's rechargeable solid-state batteries are engineered to deliver reliable power solutions for microcontrollers, which are...
Security is a primary concern in daily life, and an access control system is a crucial component of a security framework. The microcontroller-based digital lock described here is an access control system that permits only authorized individuals to enter a...
A DC motor from an old personal stereo cassette player has been utilized in this circuit, which provides control over both the speed and direction of the motor. The circuit employs PWM waveforms to drive a MOSFET H-bridge, as illustrated...
This project focuses on interfacing a microSD card, which is an affordable option for adding substantial memory to embedded systems. The microSD card is compatible with the SPI bus, simplifying the interfacing process. SD card adapters are readily available, and...
Nowadays, USB is the most popular connection between PCs and peripherals such as AVR programmers, printers, scanners, etc. For that reason, it was necessary to modify an old serial AVR In-System-Programmer (ISP) to work with a USB connection. One solution...
The schematic for controlling the motors is divided into three main sections, each serving a distinct function. The primary components featured in the schematic include the PIC 18F252 microcontroller, the SN754410 motor driver, and 2N2222 transistors. At the top of...
The ATmega8 microcontroller-based Low-Cost Telemetry Device (LTD) is an efficient telemetry keyer. The LTD measures the voltage levels of up to four analog channels via its on-chip 10-bit ADC, converts the measurements to numbers, and then sends the data in...
The page is about equipping an Atmel AVR microcontroller based system with a Prism WLAN interface. This document is intended for people that already have experiences with the AVR microcontrollers and teaches them how to add a cheap but flexible...
Atmel described a simple programmer based on the AT90S1200 (NOT the AT90S1200A) controller in their application note, AVR910 (a modification to use the AT90S2313 is also given below). The circuit is so small and simple, I was able to put...
We use cookies to enhance your experience, analyze traffic, and (if you allow) serve personalized ads.
By clicking Accept All, you agree to our use of cookies.
Learn more