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

📄 main.c

📁 基于P87LPC760的DALI从机
💻 C
字号:
#include <REG767.H>
#include <stdio.h>

void main (void)
{
unsigned char channel;

/*-----------------------------------------------
Disable P0 Output and Input.
-----------------------------------------------*/
P0M2 &= ~0x78;  /* Set P0 for Input Only */
P0M1 |=  0x78;
PT0AD =  0x78;  /* Disable Digital Inputs */

/*-----------------------------------------------
Enable the A/D Converter and use the CPU clock
as the A/D clock.
-----------------------------------------------*/
ENADC = 1;
RCCLK = 0;

/*-----------------------------------------------
Configure the serial port to run at 1200 Baud.
-----------------------------------------------*/
SCON  = 0x50;
TMOD |= 0x20;
TH1   = 0xA9;
TR1   = 1;
TI    = 1;

/*-----------------------------------------------
Perform conversions forever.
-----------------------------------------------*/
while (1)
  {
/*-----------------------------------------------
Update the channel number and store it in ADCON.
-----------------------------------------------*/
  channel = (channel + 1) % 4;

  ADCON &= ~0x03;
  ADCON |= (channel & 0x03);

/*-----------------------------------------------
Start a conversion and wait for it to complete.
-----------------------------------------------*/
  ADCI = 0;                  /* Clear conversion status */
  ADCS = 1;                  /* Start conversion */
  while (ADCI == 0);         /* Wait until conversion done */

/*-----------------------------------------------
Read A/D data and print it out.
-----------------------------------------------*/
  printf ("ADC Channel %bu = 0x%2.2bX\r\n",
          (unsigned char) channel,
          (unsigned char) DAC0);
  }
}

⌨️ 快捷键说明

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