⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 easyarm2103开发板资料
💻 C
字号:
/***********************************************Copyright (c)*********************************************
**                                Guangzou ZLG-MCU Development Co.,LTD.
**                                     
**                                       http://www.zlgmcu.com
**
**--------------File Info---------------------------------------------------------------------------------
** File name:               main.c
** Last modified Date:      2007-09-20
** Last Version:            1.0
** Descriptions:            The main() function example template
**
**--------------------------------------------------------------------------------------------------------
** Created by:              
** Created date:            
** Version:                 
** Descriptions:            
**
**--------------------------------------------------------------------------------------------------------
** Modified by:             
** Modified Date:           
** Version:                 
** Descriptions:            
**
*********************************************************************************************************/
#include "config.h"
#include <stdio.h>

#define   Vref          3300                                            /*  ADC基准参考电压值           */
/*********************************************************************************************************
** Function name:           delayNS
**
** Descriptions:            延时函数
**
** input parameters:        uiDly     延时参数
** Returned value:          none      无
**                          
*********************************************************************************************************/
void    delayNS (uint32  uiDly)
{
	uint32 i;
	
	for ( ; uiDly > 0; uiDly--) {
		for (i = 0; i < 0xFFFF; i++){
		}
    }
}

/*********************************************************************************************************
** Function name:           main
** Descriptions:            用户主函数,用户写程序需要注意以下几个步骤
**                          1.用户要对自己操作的管脚进行管脚功能设置,设置文件为pinConfig.h
**                          2.如果用户代码需要中断,需要打开内核中断,函数为:IRQEnable(); FIQEnable();
**                          3.用户有中断,需要设置VIC,设置函数请参考IRQManage.h
**                          4.其他功能实现用户可参考相关驱动的头文件或使用说明文档
** Input parameters:        NONE
** Output parameters:       NONE
** Returned value:          NONE
*********************************************************************************************************/
uint8 uiConnectOk[]="Connect Success!\r\n";
int main (void)
{
    static uint32  uiValue;
    static uint32  uiAdcVcc;
           char    *pcArg = "Chn=0x04 ADCClk=4000000 Start=0x01";       /*  通道2,软件控制              */
           char    temp[20];
    
    uartInit(0, "BaudRate=9600 DataBits=8 StopBits=1 Parity=NONE RtsControl=NONE", NULL);
    irqVicSet(UART0_VIC, 3, uart0Isr);                                  /*  设置串口优先级              */

    adcInit(ADC_0,pcArg,NULL);                                          /*  初始化ADC                   */
    if (irqVicSet(AD0_VIC,0,adc0Isr) != -1) {                           /*  申请VIC中断                 */
	                                                                    /*  VIC设置成功                 */
	    IRQEnable();                                                    /*  打开IRQ中断                 */
        
        uartWrite(UART0, uiConnectOk, sizeof(uiConnectOk), NULL);       /*  提示UART0连接成功           */
        
        while (1) {
            adcStart(ADC_0,NULL);                                       /*  启动ADC工作                 */
            delayNS(50);
            uiValue = adcGetValue(ADC_0,ADC_AIN2,NULL);                 /*  获取ADC转换结果             */
            uiAdcVcc = ((uiValue * Vref) / 1024);                       /*  转换为实际电压值(单位:mv)   */
            sprintf(temp,"%4d mV at VIN2\r\n",uiAdcVcc);
            uartWrite(0, (uint8*)temp, strlen(temp), NULL);             /*  输出实际电压值              */

        }    
    }
    

    /*
     * 功率部分测试
     */
    //if (partGetPowerState(PCAD,NULL) == PART_POWER_ON) {    
    //    partPowerManage(PCAD,PART_POWER_OFF,NULL);                      /* 注意执行此句后ADC会停止工作  */
    //}
 	
	while(1);
    return 0;
}


/*********************************************************************************************************
   END FILE
*********************************************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -