📄 adc.bak
字号:
//********************************************************************
// File name: adc.c
//
// Copyright 2003 Texas Instruments Inc as an unpublished work.
//
// Version 1.0
//
// Compiler Version (Keil V2.38), (Raisonance V6.10.13)
//
// Module Description:
// ADC Example Program
//
//********************************************************************
#include "legal.c" //Texas Instruments, Inc. copyright and liability
#include <REG1200.H> // The header file with the MSC register definitions
#include <stdio.h> // Standard I/O so we can use the printf function
extern signed long bipolar(void);
extern void autobaud(void);
#define LSB 298e-9
#ifndef XTAL // if no XTAL compiler variable defined use:
#define XTAL 11059200 // XTAL frequency 11.0592 MHz
#endif
Main(void) {
char i,j;
float result;
PDCON = 0x75; // Turn on the A/D
ACLK = XTAL/1000000; // ACLK freq. = XTAL Freq./(ACLK +1) = 0.9216 MHz
// 0.9216 Mhz/64 = 14,400 Hz
DECIMATION = 1440; // Data Rate = 14,400/1,440 = 10 Hz
ADMUX = 0x88; // AINP = AIN7, AINN = AIN6
ADCON0 = 0x30; // Vref On, 2.5V, Buffer Off, PGA=1
CKCON = 0x10; // MSC1200 Timer1 div 4
TCON = 0; // MSC1200 Stop TR1
autobaud();
ADCON1 = 0x01; // bipolar, auto, self calibration, offset, gain
printf("ADC Test, ACLK=%d\n",ACLK);
//wait for the calibration to take place
for (i=0;i<3;i++){ // dump 3 conversions
while(!(AIPOL&0x20)) {}
j=ADRESL;
}
j=1;
while(1){
while(!(AIPOL&0x20)) {} // Waiting for conversion
result=bipolar(); // Save Results
printf ("%10.8f\t", result*LSB);
if (!(j++%5)) printf("\n"); // Print 2 lines each second
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -