打印
[技术问答]

N76E003 SPI ADC / Bandgap input demo code

[复制链接]
466|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
darklighttt|  楼主 | 2020-3-30 19:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

//***********************************************************************************************************
//  Website: http://www.nuvoton.com
//  E-Mail : MicroC-8bit@nuvoton.com
//  Date   : Jan/21/2017
//***********************************************************************************************************

//***********************************************************************************************************
//  File Function: N76E003 SPI ADC / Bandgap input demo code
//***********************************************************************************************************
#include "N76E003.h"
#include "SFR_Macro.h"
#include "Function_define.h"
#include "Common.h"
#include "Delay.h"

//*****************  The Following is in define in Fucntion_define.h  ***************************
//****** Always include Function_define.h call the define you want, detail see main(void) *******
//***********************************************************************************************
#if 0
//#define Enable_ADC_AIN0                        ADCCON0&=0xF0;P17_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT0;ADCCON1|=SET_BIT0                                                                        //P17
//#define Enable_ADC_AIN1                        ADCCON0&=0xF0;ADCCON0|=0x01;P30_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT1;ADCCON1|=SET_BIT0                //P30
//#define Enable_ADC_AIN2                        ADCCON0&=0xF0;ADCCON0|=0x02;P07_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT2;ADCCON1|=SET_BIT0                //P07
//#define Enable_ADC_AIN3                        ADCCON0&=0xF0;ADCCON0|=0x03;P06_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT3;ADCCON1|=SET_BIT0                //P06
//#define Enable_ADC_AIN4                        ADCCON0&=0xF0;ADCCON0|=0x04;P05_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT4;ADCCON1|=SET_BIT0                //P05
//#define Enable_ADC_AIN5                        ADCCON0&=0xF0;ADCCON0|=0x05;P04_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT5;ADCCON1|=SET_BIT0                //P04
//#define Enable_ADC_AIN6                        ADCCON0&=0xF0;ADCCON0|=0x06;P03_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT6;ADCCON1|=SET_BIT0                //P03
//#define Enable_ADC_AIN7                        ADCCON0&=0xF0;ADCCON0|=0x07;P11_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT7;ADCCON1|=SET_BIT0                //P11
//#define Enable_ADC_BandGap        ADCCON0|=SET_BIT3;ADCCON0&=0xF8;                                                                                                                                                                                                                                                        //Band-gap 1.22V

//#define PWM0_FALLINGEDGE_TRIG_ADC                ADCCON0&=~SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1
//#define PWM2_FALLINGEDGE_TRIG_ADC                ADCCON0&=~SET_BIT5;ADCCON0|=SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1
//#define PWM4_FALLINGEDGE_TRIG_ADC                ADCCON0|=SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1
//#define PWM0_RISINGEDGE_TRIG_ADC                ADCCON0&=~SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1
//#define PWM2_RISINGEDGE_TRIG_ADC                ADCCON0&=~SET_BIT5;ADCCON0|=SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1
//#define PWM4_RISINGEDGE_TRIG_ADC                ADCCON0|=SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1

//#define P04_FALLINGEDGE_TRIG_ADC                ADCCON0|=0x30;ADCCON1&=0xF3;ADCCON1|=SET_BIT1;ADCCON1&=~SET_BIT6
//#define P13_FALLINGEDGE_TRIG_ADC                ADCCON0|=0x30;ADCCON1&=0xF3;ADCCON1|=SET_BIT1;ADCCON1|=SET_BIT6
//#define P04_RISINGEDGE_TRIG_ADC                        ADCCON0|=0x30;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1;ADCCON1&=~SET_BIT6
//#define P13_RISINGEDGE_TRIG_ADC                        ADCCON0|=0x30;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1;ADCCON1|=SET_BIT6
#endif

/******************************************************************************
The main C function.  Program execution starts
here after stack initialization.
******************************************************************************/
void main (void)
{
                P12_Quasi_Mode;                                                                                                                        //For GPIO1 output, Find in "Function_define.h" - "GPIO INIT"
                InitialUART0_Timer1(115200);
                Enable_ADC_BandGap;                                                                                                        //Find in "Function_define.h" - "ADC INIT"

                while(1)
    {
                        clr_ADCF;
                        set_ADCS;                                                                                                                                        // Each time ADC start trig signal
      while(ADCF == 0);
                        printf ("\n Value = 0x%bx",ADCRH);
                        printf ("\n Value = 0x%bx",ADCRL);
                        clr_GPIO1;
//                        Timer0_Delay1ms(100);
                        set_GPIO1;
    }
}




使用特权

评论回复
沙发
jiekou001| | 2020-3-30 22:01 | 只看该作者
003非常好用

使用特权

评论回复
板凳
antusheng| | 2020-3-31 21:49 | 只看该作者
测电压 应用?

使用特权

评论回复
地板
heimaojingzhang| | 2020-4-6 16:03 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
5
keaibukelian| | 2020-4-6 16:03 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
6
labasi| | 2020-4-6 16:04 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
7
paotangsan| | 2020-4-6 16:04 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
8
renzheshengui| | 2020-4-6 16:04 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
9
antusheng| | 2020-4-7 20:15 | 只看该作者
不清楚这个功能是干啥

使用特权

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

本版积分规则

21

主题

132

帖子

0

粉丝