Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pub
hello-world
xmega
Commits
b8debd84
Commit
b8debd84
authored
Aug 10, 2017
by
Grace Copplestone (admin)
Browse files
Upload New File
parent
bea7ef33
Pipeline
#658
failed with stage
in 0 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
functionality/interrupt/interrupt.8e5.c
0 → 100644
View file @
b8debd84
//
// xmega 8e5 interrupt example
//
// with a button on pin 4 port C and an LED on pin 0 port C
#include
<avr/io.h>
#include
<util/delay.h>
#include
<avr/pgmspace.h>
#include
<avr/interrupt.h>
#define SLAVE_ADDRESS 0x56
#define CPU_SPEED 32000000
// ISR = interrupt service routine, program that runs when an interrupt is triggered on PORTC
ISR
(
PORTC_INT_vect
)
{
// Toggle LED on interrupt
PORTC
.
OUTSET
=
PIN0_bm
;
_delay_ms
(
100
);
PORTC
.
OUTCLR
=
PIN0_bm
;
// the interrupt has to be cleared within the ISR
PORTC
.
INTFLAGS
=
PIN4_bm
;
}
int
main
(
void
)
{
// set up clock
OSC
.
CTRL
=
OSC_RC32MEN_bm
;
// enable 32MHz clock
while
(
!
(
OSC
.
STATUS
&
OSC_RC32MRDY_bm
));
// wait for clock to be ready
CCP
=
CCP_IOREG_gc
;
// enable protected register change
CLK
.
CTRL
=
CLK_SCLKSEL_RC32M_gc
;
// switch to 32MHz clock
//enable interrupts
PMIC
.
CTRL
|=
PMIC_LOLVLEX_bm
;
//set up LED as output
PORTC
.
DIRSET
=
PIN0_bm
;
// External interrupt on PC4, enable internal pullup resistor, sense falling edge
PORTC
.
PIN4CTRL
=
PORT_OPC_PULLUP_gc
|
PORT_ISC_FALLING_gc
;
PORTC
.
INTMASK
=
PIN4_bm
;
PORTC
.
INTCTRL
=
PORT_INTLVL_LO_gc
;
// Enable low level interrupts
PMIC
.
CTRL
|=
PMIC_LOLVLEN_bm
;
sei
();
//set global interrupt enable
while
(
1
){
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment