- /*---------------------------------------------------------------------------------------------------------*/
- /* */
- /* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved. */
- /* */
- /*---------------------------------------------------------------------------------------------------------*/
- //***********************************************************************************************************
- // Website: http://www.nuvoton.com
- // E-Mail : MicroC-8bit@nuvoton.com
- //***********************************************************************************************************
- //***********************************************************************************************************
- // File Function: ML51 simple GPIO toggle out demo code
- //***********************************************************************************************************
- #include "ML51.h"
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] ACMP interrupt subroutine
- * @param None
- * [url=home.php?mod=space&uid=266161]@return[/url] None
- * [url=home.php?mod=space&uid=1543424]@Details[/url]
- */
- /**
- * @brief ACMP negtive input use Bandgap voltage
- * @param None
- * @return None
- * @details
- */
- void WKT_ISR(void) interrupt 17 // Vector [url=home.php?mod=space&uid=72445]@[/url] 0x8B
- {
- clr_WKCON_WKTF;
- P14 = 0;
- // _delay_();
- P14 = 1;
- // _delay_();
- P14 = 0;
- }
- void ACMP_ISR (void) interrupt 23
- {
- SFRS = 0x00;
- if ((ACMPSR&SET_BIT2)==SET_BIT2)
- {
- ACMPSR&=CLR_BIT2;
- P14 ^=1;
- }
- else if ((ACMPSR&SET_BIT0)==SET_BIT0)
- {
- ACMPSR&=CLR_BIT0;
- P14 ^=1;
- }
- }
- void main (void)
- {
- unsigned char i;
- /* Setting Multi function pin setting for GPIO toggle
- * include gipo.c in Common for GPIO mode setting
- */
- MFP_P13_GPIO;
- P13_QUASI_MODE;
- MFP_P14_GPIO;
- P14_QUASI_MODE;
- for(i=0;i<0x05;i++)
- {
- P14 = 0;
- _delay_();
- P14 = 1;
- _delay_();
- }
-
- #if 1
- MFP_P23_ACMP0_P1;
- MFP_P24_ACMP0_N0;
- MFP_P41_ACMP0_O;
- ///* ACMP VBG intial
- ///* Initial ACMP0 P2.3 as positive and Bandgap as negetive input, Output to P4.1 */
- // ACMP_Open(ACMP0, ACMP_CTL_POSSEL_P1, ACMP_CTL_NEGSEL_VBG,0, ACMP_CTL_ACMP0_OUTPUT_ENABLE, ACMP_CTL_HYSTERESIS_ENABLE);
- ///* Initial ACMP interrupt enable, wakeup function dis ble.*/
- // ACMP_INTEnable(ACMP0, ACMP_CTL_WAKEUP_ENABLE, ACMP_CTL_INT_ENABLE);
-
- /* ACMP VREF intial
- * include acmp.c in Library for ACMP initial and interrupt setting. */
- // VREF_Open(2);
- /* Initial ACMP0 P2.3 as positive and Bandgap as negetive input, Output to P4.1 */
- ACMP_Open(ACMP0, ACMP_CTL_POSSEL_P1, ACMP_CTL_NEGSEL_CRV, ACMP_CTL_CRV_VREF, ACMP_CTL_ACMP0_OUTPUT_ENABLE, ACMP_CTL_HYSTERESIS_ENABLE);
- /* CRV Value = CRV source voltage * (2+CRV1CTL)/12. so for this example = VREF/2.*/
- ACMP_CRVValue(ACMP0, 4);
- /* Initial ACMP interrupt enable, wakeup function disable.*/
- ACMP_INTEnable(ACMP0, ACMP_CTL_WAKEUP_ENABLE, ACMP_CTL_INT_ENABLE);
-
- WKT_Open(38400,256,100);
- WKT_Interrupt(Enable);
-
- ENABLE_GLOBAL_INTERRUPT;
- #endif
- // BOD_Enable(VBOD24,BOD_RESET_ENABLE);
- // BOD_LowPower_Enable(LPBOD_MODE2,BOD_FT_ENABLE);
- LVR_Enable();
- BOD_Disable();
- POR_Disable();
- // LVR_Disable();
- // LowPowerLVR_Enable();
- // BIAS_ALL_DIGITAL();
- SFRS = 1;
- CKDIV = 0x0c;
- /* Enable Low power run mode */
- // FsysSelect(FSYS_LIRC);
- // set_PCON_LPR;
- //set_PCON_IDLE;
- //set_PCON_PD;
- while(1)
- {
- // P14 = 0;
- // P14 = 1;
- set_PCON_PD;
- }
-
- }
|