˜Ëî}: 6410ADCŸoòŒ„ÓÖ±½Ó²Ù×÷³ÌÐò [´òÓ¡±¾í“]
×÷Õß: hei51hei •rég: 2018-3-20 14:11
˜Ëî}: 6410ADCŸoòŒ„ÓÖ±½Ó²Ù×÷³ÌÐò
#defineGLOBAL_CLK 1
#include<stdlib.h>
#include<string.h>
#include"def.h"
#include"option.h"
#include"2440addr.h"
#include"2440lib.h"
#include"2440slib.h"
#include"mmu.h"
#include"profile.h"
#include"memtest.h"
int Readadc(intch)
{
rADCCON= (1<<14)| (49<<6) | ((ch)<<3);//adcʹÄÜ£¬ÔOÖÃîlÂÊžé1MHZ
rADCTSC=~(0x1<<2);//adcÔOÖÞéÆÕͨÞD“Qģʽ
rADCCON|=0x1;//†¢„Óad
while(rADCCON0x1);//µÈ´ýadÞD“Qé_ʼ
while(!(rADCCON(0x1<<15)));//µÈ´ýadÞD“Q½YÊø
return(rADCDAT0 0x3ff); //×xÈ¡A/DÞD“QµÄ”µ“þ
}
void Main()
{float v0,v1;
int t0,t1;
Uart_Printf("ÕˆÕ{Õû»¬„ÓëŠ×貢ݔÈë1ßx“ñï@ʾ늉ºÖµ£¡\r");
while(Uart_GetIntNum()==1)
{v0=((float)Readadc(0)*3.3)/1024.0;//Ó‹Ëã늉ºÖµ
v1=((float)Readadc(1)*3.3)/1024.0;//Ó‹Ëã늉ºÖµ
t0=(v0-(int)v0)*1000;//Ó‹ËãС”µ²¿·Ö£¬Uart_Printfº¯”µŸo·¨´òÓ¡¸¡üc”µ
t1=(v1-(int)v1)*1000;//Ó‹ËãС”µ²¿·Ö£¬Uart_Printfº¯”µŸo·¨´òÓ¡¸¡üc”µ
Uart_Printf("늉ºÖµžéAIN0£º%d.%-3dVAIN1:%d.%-3dV\r",(int)v0,t0,(int)v1,t1);
Uart_Printf("\n");}}
| šgÓ¹âÅR (http://m.raoushi.com/bbs/) |
Powered by Discuz! X3.1 |