?? main.c
字號(hào):
/****************************************************************************
【文 件 名 稱(chēng)】44Btest.c
【功 能 描 述】三星S3C44B0X板demo程序代碼
【程 序 版 本】2.0
【創(chuàng)建人及創(chuàng)建日期】龔俊//2003-07-02 15:27
【修改人及修改日期】龔俊//2004-2-12 9:18
****************************************************************************/
//***************************************************************************
#include <stdlib.h>
#include <string.h>
#include "..\inc\def.h"
#include "..\inc\option.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
/****************************************************************************
【功能說(shuō)明】模數(shù)轉(zhuǎn)換初始化
****************************************************************************/
void ADC_Init(void)
{
rCLKCON = rCLKCON | (1<<12); //控制系統(tǒng)主時(shí)鐘進(jìn)入ADC單元模塊
rADCCON = 0x1|(0<<2); //ADC轉(zhuǎn)換使能,選擇AIN7
Delay(100); //延時(shí)若干個(gè)100us
rADCPSR = 10; //ADC轉(zhuǎn)換頻率為:(int)(MCLK/(2*(rADCPSR+1))/16)
Uart_Printf("ADC轉(zhuǎn)換頻率 = %d(Hz)\n\n",(int)(MCLK/(2.*(10+1.))/16.) );
}
//***************************************************************************
/****************************************************************************
【功能說(shuō)明】ADC某一通道進(jìn)行轉(zhuǎn)換,返回轉(zhuǎn)換的數(shù)據(jù)
****************************************************************************/
unsigned short Read_Adc(unsigned char ch)
{
int i;
static int prevCh=-1;
if(prevCh!=ch)
{
rADCCON = 0x1|(ch<<2); //設(shè)置AD轉(zhuǎn)換通道
for(i=0;i<150;i++); //最小15uS
}
rADCCON=0x1|(ch<<2); //開(kāi)始AD轉(zhuǎn)換
while(rADCCON & 0x1); //避免標(biāo)志FLAG錯(cuò)誤
while(!(rADCCON & 0x40)); //等待AD轉(zhuǎn)換結(jié)束
for(i = 0; i < rADCPSR; i++); //避免第二次標(biāo)志FLAG錯(cuò)誤
prevCh=ch;
return rADCDAT; //返回AD轉(zhuǎn)換值
}
//***************************************************************************
/****************************************************************************
【功能說(shuō)明】系統(tǒng)主函數(shù)
****************************************************************************/
void Main(void)
{
int a0=0,a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0;
rNCACHBE0 = ((Non_Cache_End>>12)<<16)|(Non_Cache_Start>>12);
//在上面的數(shù)據(jù)區(qū)域不使用高速緩存
rSYSCFG = CACHECFG; //8K字節(jié)cache,寫(xiě)緩沖使能,data abort使能
Port_Init(); //IO口初始化
Uart_Select( 0 ) ; //選擇串口0
Uart_Init( 32000000, 57600 ) ;
//串口初始化,波特率為57600(系統(tǒng)主頻為32MHz)
Uart_Printf( "\n\n\t優(yōu)龍科技\n" ) ;
Uart_Printf( "Http://www.ucdragon.com\n\n" ) ;
Uart_Printf( "ST44B0X模數(shù)轉(zhuǎn)換器(ADC)測(cè)試!\n\n" ) ;
ADC_Init() ; //模數(shù)轉(zhuǎn)換初始化
while(1)
{
a0 = Read_Adc(0); //ADC某一通道進(jìn)行轉(zhuǎn)換,返回轉(zhuǎn)換的數(shù)據(jù)
a1 = Read_Adc(1); //ADC某一通道進(jìn)行轉(zhuǎn)換,返回轉(zhuǎn)換的數(shù)據(jù)
a2 = Read_Adc(2); //ADC某一通道進(jìn)行轉(zhuǎn)換,返回轉(zhuǎn)換的數(shù)據(jù)
a3 = Read_Adc(3); //ADC某一通道進(jìn)行轉(zhuǎn)換,返回轉(zhuǎn)換的數(shù)據(jù)
a4 = Read_Adc(4); //ADC某一通道進(jìn)行轉(zhuǎn)換,返回轉(zhuǎn)換的數(shù)據(jù)
a5 = Read_Adc(5); //ADC某一通道進(jìn)行轉(zhuǎn)換,返回轉(zhuǎn)換的數(shù)據(jù)
a6 = Read_Adc(6); //ADC某一通道進(jìn)行轉(zhuǎn)換,返回轉(zhuǎn)換的數(shù)據(jù)
a7 = Read_Adc(7); //ADC某一通道進(jìn)行轉(zhuǎn)換,返回轉(zhuǎn)換的數(shù)據(jù)
Uart_Printf("ADC 0-7通道輸出依次為:%4d %4d %4d %4d %4d (%4d) %4d %4d\n",a0,a1,a2,a3,a4,a5,a6,a7);
Delay(2000); //延時(shí)
}
}
//***************************************************************************
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -