Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // by Ido Gendel, 2021
- // Share and enjoy!
- // Target: AVR128DB48 Curiosity Nano evaluation kit
- // Using: MPLAB X 5.45, XC8 2.30
- #include <xc.h>
- #include <avr/io.h>
- #include <avr/interrupt.h>
- FUSES = {
- .WDTCFG = 0x00, // WDTCFG {PERIOD=OFF, WINDOW=OFF}
- .BODCFG = 0x00, // BODCFG {SLEEP=DISABLE, ACTIVE=DISABLE, SAMPFREQ=128Hz, LVL=BODLEVEL0}
- .OSCCFG = 0xF8, // OSCCFG {CLKSEL=OSCHF}
- .SYSCFG0 = 0xD2, // SYSCFG0 {EESAVE=CLEAR, RSTPINCFG=GPIO, CRCSEL=CRC16, CRCSRC=NOCRC}
- .SYSCFG1 = 0xE8, // SYSCFG1 {SUT=0MS, MVSYSCFG=DUAL}
- //.SYSCFG1 = 0xF0, // SYSCFG1 {SUT=0MS, MVSYSCFG=SINGLE}
- .CODESIZE = 0x00, // CODESIZE {CODESIZE=User range: 0x0 - 0xFF}
- .BOOTSIZE = 0x00, // BOOTSIZE {BOOTSIZE=User range: 0x0 - 0xFF}
- };
- LOCKBITS = 0x5CC5C55C; // {KEY=NOLOCK}
- inline void LEDasVDDIO2(void) {
- // The on-board LED is negative logic
- if (MVIO_STATUS & 1) PORTB_OUTCLR = 8;
- else PORTB_OUTSET = 8;
- }
- void main(void) {
- PORTB_DIRSET = 8; // PB3 is the on-board LED
- LEDasVDDIO2(); // Reflect the initial status, until an interrupt occurs
- // PC0 as output HIGH for testing under current draw
- PORTC_DIRSET = 1;
- PORTC_OUTSET = 1;
- MVIO_INTCTRL |= 1; // Enable the MVIO interrupt
- CPU_SREG |= 0x80; // Enable global interrupts
- for ( ; ; ) {
- }
- return;
- }
- ISR(MVIO_MVIO_vect) {
- LEDasVDDIO2();
- MVIO_INTFLAGS = 1; // Clear flag - this one's not automatic!
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement