?? adcmain.c
字號:
/*------------------------------------------------------------------------------
adcMain.c : Sample Program that demonstrates the A to D converter of the
following microcontrollers
Philips 80C591
Philips 83C591
Philips 87C591
Philips 80C552
Philips 83/87C552
Philips 87C552
Philips 80C554
Philips 83/87C554
Philips 83/87C557E4
Philips 83/87C557E8
Copyright (c) 1988-2001 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/
#include <REG591.h>
#include <stdio.h>
#define V_REF 5
/*------------------------------------------------------------------------------
Read_ADC( unsigned char ): reads an analog signal from the received unsigned
char and returns the converted value
------------------------------------------------------------------------------*/
unsigned Read_ADC( unsigned char channel )
{
ADCON &= ~0x07; /* Clears the input channels */
ADCON |= 0x07 & channel; /* Loads Channel to sampled */
ADCON |= 0x8; /* Starts Conversion */
while( (ADCON & 0x8) ); /* Waits for Conversion to end */
return( ( ( (unsigned) ADCH << 8) | ADCON ) >> 6 );
}
unsigned int reading[8];
/*------------------------------------------------------------------------------
main() : Outputs the digital conversion of channels 0 - 7.
------------------------------------------------------------------------------*/
void main( void )
{
unsigned int i;
/*------------------------------------------------
Setup the serial port for 1200 baud at 16MHz.
------------------------------------------------*/
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 */
TI = 1; /* TI: set TI to send first char of UART */
ADCON = 0x20; /* Set Startmode to start via software */
while(1)
{
for( i = 0; i < 2 ; i++ )
{
i = 0;
reading[i] = Read_ADC(i);
//printf ("ADC #%u Count %4u = %01u.%04u Volts\r",
// (unsigned) i, (unsigned) reading[i],
// (unsigned) (reading[i] * V_REF) >> 10, /* Output Integer Portion */
// (unsigned) ((reading[i] * V_REF * 10000UL) >> 10UL) % 10000); /* Output Decimal Portion */
ADCON &= ~0x10; /*Resets to Ready to Read Flag. */
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -