打印
[DemoCode下载]

MG51使用IO触发ADC采集

[复制链接]
38|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
稳稳の幸福|  楼主 | 2025-5-25 20:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* SPDX-License-Identifier: Apache-2.0                                                                     */
/* Copyright(c) 2023 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

#include "MG51_SDCC.H"

//***********************************************************************************************************
//  File Function: MS51 ADC trig by GPIO demo
//***********************************************************************************************************

BIT  adcintflag;
/******************************************************************************
* FUNCTION_PURPOSE: ADC interrupt Service Routine
******************************************************************************/
void ADC_ISR (void) __interrupt (11)
{
        PUSH_SFRS;
  
    clr_ADCCON0_ADCF;                               //clear ADC interrupt flag
    adcintflag=1;

    POP_SFRS;
}

/******************************************************************************
The main C function.  Program execution starts
here after stack initialization.
******************************************************************************/
void main (void)
{
    UINT16 ADCResult12bit;

  /* UART0 settting for printf function */
    MODIFY_HIRC(HIRC_24);
    Enable_UART0_VCOM_printf_24M_115200();
    printf ("\n Test start ...");

/*---------------------------------------------------------------
  ADC port trig initial setting toggle P0.4 to start ADC
----------------------------------------------------------------*/
    ENABLE_ADC_AIN0;                              // Enable AIN0 P1.7 as ADC pin
    P04_QUASI_MODE;
    P04_FALLINGEDGE_TRIG_ADC;                     // P0.4 falling edge as adc start trig signal
/* Enable ADC interrupt */
    ENABLE_ADC_INTERRUPT;                         // Enable ADC interrupt (if use interrupt)
    ENABLE_GLOBAL_INTERRUPT;
/* Trig P12 falling edge to start adc, no need set ADCS bit   */
    while(1)                                      // Wait ADC interrupt
    {
      if (adcintflag)
      {
            ADCResult12bit = ADCRH<<4;
            ADCResult12bit|= ADCRL&0x0F;
            printf ("\n Value = 0x%x",ADCResult12bit);
            adcintflag =0;
      }
      Timer0_Delay(24000000,500,1000);
    }


}


使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

194

主题

3382

帖子

8

粉丝