⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 This program shows how to configure and use the A/D Converter of the following microcontrollers:
💻 C
字号:
#include <reg51.h>
#include <stdio.h>

sfr ADCON  = 0xC5;
sfr ADDAT1 = 0xC3;
sfr ADDAT0 = 0xC2;

void main (void)
{
unsigned char chan_2_convert;

/*-----------------------------------------------
Configure the serial port to run at 9600 Baud.
-----------------------------------------------*/
#ifndef MONITOR

SCON  = 0x50;
TMOD |= 0x20;
TH1   = 0xFA;
TR1   = 1;
TI    = 1;
PCON |= 0x80;

#endif

printf ("MAX7651 A/D Converter Example\r\n\r\n");

/*-----------------------------------------------
Configure the A/D to sequentially convert each
input channel.
-----------------------------------------------*/
for (chan_2_convert = 0; 1; chan_2_convert = (chan_2_convert + 1) % 8)
  {
  unsigned int conv_val;

/*-----------------------------------------------
Start a conversion and wait for it to complete.
-----------------------------------------------*/
  ADCON = chan_2_convert;
  while ((ADCON & 0x80) == 0);

/*-----------------------------------------------
Read A/D data and print it out.
-----------------------------------------------*/
  conv_val = (ADDAT0 >> 4) | ((unsigned) ADDAT1 << 4);

  printf ("Ch#%bu=0x%3.3X",
          (unsigned char) chan_2_convert,
          (unsigned) conv_val);

  if (chan_2_convert == 7)
    {
    printf ("\r\n");
    }
  else
    {
    printf ("  ");
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -