📄 adcmain.c
字号:
/*------------------------------------------------------------------------------
adcMain.c : Sample Program that demonstrates the A to D converter of the
following microcontrollers
* Infineon SAB 80C537
Copyright (c) 1988-2001 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/
#include <stdio.h>
sfr ADCON0 = 0xD8;
sfr ADCON1 = 0xDC;
sfr ADDAT = 0xD9;
sfr DAPR = 0xDA;
sfr S0CON = 0x98;
sfr TMOD = 0x89;
sfr TH1 = 0x8D;
sbit TR1 = 0x8E;
sbit TI0 = 0x99;
/*------------------------------------------------------------------------------
Read_ADC( unsigned char ): reads an analog signal from the received unsigned
char and returns the converted value
------------------------------------------------------------------------------*/
unsigned char Read_ADC( unsigned char channel )
{
ADCON1 &= ~0x0F; //Prepare channel selector
ADCON1 |= 0x0F & channel; //Set input channel
DAPR = 0x00; //Setting Vgnd and Vref to 0 and 5
//This starts the conversion process.
while( ADCON0 & 0x10 ); //Wait for conversion to end
return( (unsigned char) ADDAT );
}
/*------------------------------------------------------------------------------
main() : Outputs the digital conversion of channels 0 - 11.
------------------------------------------------------------------------------*/
void main( void )
{
unsigned char i;
S0CON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 221; /* TH1: reload value for 1200 baud @ 16MHz */
TR1 = 1; /* TR1: timer 1 run */
TI0 = 1; /* TI: set TI to send first char of UART */
while(1)
{
for( i = 0; i < 12; i++)
{
printf("Channel %u = %4u\n",(unsigned) i, (unsigned)Read_ADC(i) );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -