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

📄 main.c

📁 EASYARM2103测试程序
💻 C
字号:
/****************************************Copyright (c)***************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info--------------------------------------------------------------------------------
** File name:			main.c
** Last modified Date:  2004-09-16
** Last Version:		1.0
** Descriptions:		The main() function example template
**
**-------------------------------------------------------------------------------------------------------
** Created by:			Chen Mingji
** Created date:		2004-09-16
** Version:				1.0
** Descriptions:		The original version
**
**-------------------------------------------------------------------------------------------------------
** Modified by:         Li Baihua
** Modified date:       2008-04-08
** Version:             1.1
** Descriptions:        利用ADC对通道0 的电压进行采样,并把值发送到PC机显示出来
**
*********************************************************************************************************/
# include "config.h"
# include <stdio.h>
# include "UART.H"

/*********************************************************************************************************
** Function name:		DelayNS
** Descriptions:		延时函数
** input parameters:    uiDly   延时值
** output parameters:   无
** Returned value:      无
*********************************************************************************************************/
void DelayNS (uint32 uiDly)
{
    uint32 i;
    for(; uiDly > 0; uiDly--){
        for(i=0; i<50000; i++);
    }
}

/*********************************************************************************************************
** Function name:		Main
** Descriptions:		利用ADC对通道0 的电压进行采样,并把值发送到PC机显示出来
** input parameters:    无
** output parameters:   无
** Returned value:      无
*********************************************************************************************************/
int main(void)
{ 
    uint32 uiVal;
    char   cStr[20];
    
    PINSEL1 = PINSEL1 & (~(0x03 << 12));                                /*  将P0.22设置为AD功能         */
    PINSEL1 = PINSEL1 | (0x03 << 12);
    
    UARTInit();		                                                    /*  串口初始化                  */
    
    /*  
     * 进行ADC模块设置        
     */
    AD0CR = (1 << 0)  |                                                 /*  选择通道0                   */
            (((Fpclk / 1000000) - 1) << 8)  |                           /*  转换时钟为1MHz              */
            (0 << 16) |                                                 /*  BURST = 0,软件控制转换操作  */
            (0 << 17) |                                                 /*  CLKS = 0,使用11clock转      */
            (1 << 21) |                                                 /*  PDN = 1,正常工作模式       */
            (0 << 22) |                                                 /*  TEST = 0,正常工作模式      */
            (1 << 24) |                                                 /*  设置直接启动模式            */
            (0 << 27 );                                                 /*  设置模式,直接启动模式下无效*/   
      
    while(1) {
            
       /*  
        * 启动AD转换        
        */
        AD0CR |= (1 <<24);
        while ((AD0STAT & 0x01) == 0);                                  /*  读取AD0STAT的通道0的Done    */
        AD0CR |= (1 <<24);
        while ((AD0STAT & 0x01) == 0);                                  /*  读取AD0STAT的通道0的Done    */            
        
        DelayNS(10);                                                    /*  至少等待11个AD转换时钟后才
                                                                            读取数据否则会造成死等待    */
        
        uiVal = AD0DR0;
        uiVal = (uiVal >> 6) & 0x3FF;  
        uiVal = (uiVal * 3300)/1024;		                            /*  ADC的参考电压为3300mV       */
        
        sprintf(cStr,"%4d mV VIN0", uiVal);                             /*  格式化显示数据              */
        ISendStr (0,0,0x30,cStr);			                            /*  将数据发送到PC机显示        */
        
        DelayNS(50);          
    }
    
    return (0); 
}
/*********************************************************************************************************
**                            End Of File
*********************************************************************************************************/

⌨️ 快捷键说明

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