- /*---------------------------------------------------------------------------------------------------------*/
- /* */
- /* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved. */
- /* */
- /*---------------------------------------------------------------------------------------------------------*/
- //***********************************************************************************************************
- // Nuvoton Technoledge Corp.
- // Website: http://www.nuvoton.com
- // E-Mail : MicroC-8bit@nuvoton.com
- // Date : Apr/21/2015
- //***********************************************************************************************************
- //***********************************************************************************************************
- // File Function: N76E885 I/O Interrupt demo code
- //***********************************************************************************************************
- #include <stdio.h>
- #include "N76E885.h"
- #include "Version.h"
- #include "Typedef.h"
- #include "Define.h"
- #include "SFR_Macro.h"
- #include "Common.h"
- #include "Delay.h"
- /*
- //-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
- //
- //<e0> System Clock Source Configuration
- // <o1> System Clock Source Selection
- // <0=> 2~25MHz XTAL
- // <1=> 32.768KHz XTAL
- // <2=> 22.1184MHz Internal
- // <3=> 10KHz Internal
- // <4=> OSC-In External
- //</e>
- //
- //<e2> Clock Divider Configuration
- // <o3.0..7> System Clock Source Devider <1-255:1>
- // <i> Fsys = (System Clock Source) / (2 * Devider)
- //</e>
- //
- //<h> Port Interrupt Option
- // <o4.0..1> Port Pin Selection <0=> Port0 <1=> Port1 <2=> Port2 <3=> Port3
- // <h> Edge/Level
- // <o4.2> Channel 0, trigger type selection <0=> Level <1=> Edge
- // <o4.3> Channel 1, trigger type selection <0=> Level <1=> Edge
- // <o4.4> Channel 2, trigger type selection <0=> Level <1=> Edge
- // <o4.5> Channel 3, trigger type selection <0=> Level <1=> Edge
- // <o4.6> Channel 5,4, trigger type selection <0=> Level <1=> Edge
- // <o4.7> Channel 7,6, trigger type selection <0=> Level <1=> Edge
- // </h>
- // <h> Falling/Level
- // <q5.0> Channel 0, Enabled level/falling edge detect.
- // <q5.1> Channel 1, Enabled level/falling edge detect.
- // <q5.2> Channel 2, Enabled level/falling edge detect.
- // <q5.3> Channel 3, Enabled level/falling edge detect.
- // <q5.4> Channel 4, Enabled level/falling edge detect.
- // <q5.5> Channel 5, Enabled level/falling edge detect.
- // <q5.6> Channel 6, Enabled level/falling edge detect.
- // <q5.7> Channel 7, Enabled level/falling edge detect.
- // </h>
- // <h> Rising/Level
- // <q6.0> Channel 0, Enabled level/rising edge detect.
- // <q6.1> Channel 1, Enabled level/rising edge detect.
- // <q6.2> Channel 2, Enabled level/rising edge detect.
- // <q6.3> Channel 3, Enabled level/rising edge detect.
- // <q6.4> Channel 4, Enabled level/rising edge detect.
- // <q6.5> Channel 5, Enabled level/rising edge detect.
- // <q6.6> Channel 6, Enabled level/rising edge detect.
- // <q6.7> Channel 7, Enabled level/rising edge detect.
- // </h>
- //</h>
- //
- //-------- <<< end of configuration section >>> ------------------------------
- */
- #define SYS_CLK_EN 0
- #define SYS_SEL 2
- #define SYS_DIV_EN 0 //0: Fsys=Fosc, 1: Fsys = Fosc/(2*CKDIV)
- #define SYS_DIV 1
- #define PICON_VAL 0xFC //Pin Interrupt Control
- #define PINEN_VAL 0xFF //Pin Interrupt Negative Polarity Enable.
- #define PIPEN_VAL 0xFF //Pin Interrupt Positive Polarity Enable.
- bit BIT_TMP;
- /*----------------------------------------------------------------------------
- Check the register settings
- *----------------------------------------------------------------------------*/
- #define CHECK_RANGE(val, min, max) ((val < min) || (val > max))
- #define CHECK_RSVD(val, mask) (val & mask)
- #if (PICON_VAL&0x03) == 0x01 //Port1, only P1[2:0] available
- #if CHECK_RSVD(PINEN_VAL, ~0x07)
- #error "Port1[2:0] Interrup Pin Select Error"
- #elif CHECK_RSVD(PIPEN_VAL, ~0x07)
- #error "Port1[2:0] Interrup Pin Select Error"
- #endif
- #endif
- #if (PICON_VAL&0x03) == 0x02 //Port2, only P2[6:0] available
- #if CHECK_RSVD(PINEN_VAL, ~0x7F)
- #error "Port2[6:0] Interrup Pin Select Error"
- #elif CHECK_RSVD(PIPEN_VAL, ~0x7F)
- #error "Port2[6:0] Interrup Pin Select Error"
- #endif
- #endif
- /******************************************************************************
- * FUNCTION_PURPOSE: I/O Pin interrupt Service Routine
- ******************************************************************************/
- void PinInterrupt_ISR (void) interrupt 7
- {
- PIF = 0x00; //clear interrupt flag
-
- #if (PICON_VAL&0x03) == 0x00 //Port0 are interrupt pin
- P30 = ~P30;
- #endif
-
- #if (PICON_VAL&0x03) == 0x01 //Port1 are interrupt pin
- P30 = ~P30;
- #endif
-
- #if (PICON_VAL&0x03) == 0x02 //Port2 are interrupt pin
- P30 = ~P30;
- #endif
-
- #if (PICON_VAL&0x03) == 0x03 //Port3 are interrupt pin
- P00 = ~P00;
- #endif
- }
- /******************************************************************************
- The main C function. Program execution starts
- here after stack initialization.
- ******************************************************************************/
- void main (void)
- {
- /* Note
- MCU power on system clock is HIRC (22.1184MHz), so Fsys = 22.1184MHz
- */
-
- Set_All_GPIO_Quasi_Mode();
- InitialUART0_Timer1_Type1(9600); /* 9600 Baud Rate*/
- Show_FW_Version_Number_To_PC();
- printf ("\n*===================================================================");
- printf ("\n* Name: N76E885 Pins Interrupt Demo Code.");
- printf ("\n*===================================================================\n");
-
- /* Change system closk source */
- #if SYS_CLK_EN == 1
- #if SYS_SEL == 0
- System_Clock_Select(E_HXTEN); //Fosc = 2~25MHz XTAL
- #elif SYS_SEL == 1
- System_Clock_Select(E_LXTEN); //Fosc = 32.768KHz XTAL
- #elif SYS_SEL == 2
- System_Clock_Select(E_HIRCEN); //Fosc = 22.1184MHz Internal RC
- #elif SYS_SEL == 3
- System_Clock_Select(E_LIRCEN); //Fosc = 10KHz Internal RC
- #elif SYS_SEL == 4
- System_Clock_Select(E_OSCEN); //Fosc = OSC-In External OSC
- #endif
- #endif
-
- #if SYS_DIV_EN == 1
- CKDIV = SYS_DIV; //Fsys = Fosc / (2* CLKDIV) = Fcpu
- #endif
-
- P0 = 0xFF;
- P1 = 0x07;
- P2 = 0x7F;
- P3 = 0xFF;
-
- PICON = PICON_VAL;
- PINEN = PINEN_VAL;
- PIPEN = PIPEN_VAL;
-
- set_EPI;
- EA = 1;
-
- while(1)
- {
- set_PD; //Enter Power Down
- }
- }
|