Advertisement
igendel

AVR128DB48 MVIO status bit test

Jan 19th, 2021 (edited)
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.45 KB | None | 0 0
  1. // by Ido Gendel, 2021
  2. // Share and enjoy!
  3.  
  4. // Target: AVR128DB48 Curiosity Nano evaluation kit
  5. // Using: MPLAB X 5.45, XC8 2.30
  6.  
  7. #include <xc.h>
  8. #include <avr/io.h>
  9. #include <avr/interrupt.h>
  10.  
  11. FUSES = {
  12.     .WDTCFG = 0x00, // WDTCFG {PERIOD=OFF, WINDOW=OFF}
  13.     .BODCFG = 0x00, // BODCFG {SLEEP=DISABLE, ACTIVE=DISABLE, SAMPFREQ=128Hz, LVL=BODLEVEL0}
  14.     .OSCCFG = 0xF8, // OSCCFG {CLKSEL=OSCHF}
  15.     .SYSCFG0 = 0xD2, // SYSCFG0 {EESAVE=CLEAR, RSTPINCFG=GPIO, CRCSEL=CRC16, CRCSRC=NOCRC}
  16.     .SYSCFG1 = 0xE8, // SYSCFG1 {SUT=0MS, MVSYSCFG=DUAL}
  17.     //.SYSCFG1 = 0xF0, // SYSCFG1 {SUT=0MS, MVSYSCFG=SINGLE}    
  18.     .CODESIZE = 0x00, // CODESIZE {CODESIZE=User range:  0x0 - 0xFF}
  19.     .BOOTSIZE = 0x00, // BOOTSIZE {BOOTSIZE=User range:  0x0 - 0xFF}
  20. };
  21. LOCKBITS = 0x5CC5C55C; // {KEY=NOLOCK}
  22.  
  23. inline void LEDasVDDIO2(void) {
  24.  
  25.   // The on-board LED is negative logic
  26.   if (MVIO_STATUS & 1) PORTB_OUTCLR = 8;
  27.     else PORTB_OUTSET = 8;    
  28.  
  29. }
  30.  
  31. void main(void) {
  32.    
  33.     PORTB_DIRSET = 8; // PB3 is the on-board LED
  34.     LEDasVDDIO2(); // Reflect the initial status, until an interrupt occurs
  35.    
  36.     // PC0 as output HIGH for testing under current draw
  37.     PORTC_DIRSET = 1;
  38.     PORTC_OUTSET = 1;
  39.    
  40.     MVIO_INTCTRL |= 1; // Enable the MVIO interrupt
  41.     CPU_SREG |= 0x80; // Enable global interrupts
  42.  
  43.     for ( ; ; ) {
  44.     }
  45.     return;
  46.    
  47. }
  48.  
  49. ISR(MVIO_MVIO_vect) {
  50.   LEDasVDDIO2();  
  51.   MVIO_INTFLAGS = 1; // Clear flag - this one's not automatic!
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement