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. 🔗 External reference
Uses surface-barrier transistors in an arrangement where a pattern of four on stages is stepped along a ring, allowing the maximum number of stages in the ring to be significantly higher than in conventional rings. -W. Carlson, Ring Counter...
LED displays consist of arrays of Light Emitting Diodes (LEDs) arranged in various shapes to convey specific information. The operation of LED displays is similar to that of standard LEDs, requiring straightforward connections when sufficient microcontroller pins are available....
The NanoVM is a java virtual machine for the Atmel AVR ATmega8 CPU, the member of the AVR CPU family used e.g. in the DLR Asuro robot, manufactured by AREXX engineering. With the NanoVM, the Asuro can be programmed...
This simple counter can be utilized to count pulses, serving as the foundation for a customer counter, similar to those found at store entrances, or for any other counting applications. The circuit is compatible with any TTL logic signal...
This simple circuit utilizes an LM311 as a level detector, incorporating CMOS analog switches to control capacitance. A significant feature of this counter is its ability to change numbers. The comparator operates more efficiently when there is a need...
This circuit utilizes fewer components than traditional transistor flip-flops. The output at point "B" produces a transient-free waveform.
The circuit in question is designed to provide a simplified approach to signal processing by minimizing the number of components involved compared...
We use cookies to enhance your experience, analyze traffic, and serve personalized ads.
By clicking "Accept", you agree to our use of cookies.
Learn more