Microchip Technology Power Debugger Manual page 26

Table of Contents

Advertisement

USART/SPI
POWER DEBUGGER
host
USB
The example code makes use of the pin-change interrupt connected to the button on the Xplained Mini to toggle a
LED and update a ticker. On each button-press the LED toggles and the ticker count is sent using the DGI USART
along with a LED status message.
The code below is included in project low_power_105.
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
volatile uint8_t
led_on;
volatile uint8_t
send_message;
volatile uint8_t
ticker = 0;
const
char* message_on =
const
char* message_off =
ISR (PCINT0_vect)
{
// Each botton press generates two pin-change interrupt (press, release)
// Ignore half of these
if
(PINB & (1 << 7))
return;
// Update LED
if
(led_on)
PORTB &= ~(1 << 5);
else
PORTB |= (1 << 5);
// Invert led_on
led_on = ~led_on;
// Flag a message send
send_message = 1;
// Increment ticker
ticker++;
// Reset ticker
if
(ticker >= 10)
ticker = 0;
}
void
usart_send
(const char
{
// Send a character to the USART
UDR0 = data;
// Wait for the character to be sent
while
(!(UCSR0A & (1 << TXC0)))
©
2020 Microchip Technology Inc.
DGI
CLK
A
A
GND
"LED ON
";
"LED OFF
";
data)
5V
Vcc
GND
User Guide
Power Debugger
Detailed Use Cases
host
USB
PWR_EN
PD4
PD1
ISP
DS40002201A-page 26

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Power Debugger and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents