📄 p87lpc769_ad.c
字号:
//Philips P87LPC767/768/769 A/D Example Program
#include <REG767.H>
#include <stdio.h>
#define VREF 5 /* Voltage Reference */
void main (void)
{
/* Disable Digital Output and Input */
PT0AD = 0x78; /* Disable Digital Inputs on A/D input pins */
P0M1 = 0x87; /* Disable Digital Outputs on A/D input pins */
/* Init ADC */
ENADC = 1; /* Enable ADC */
RCCLK = 0; /* Use CPU clock as A/D clock */
/* initialize the serial interface */
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xFB; /* TH1: reload value for 19200 baud */
TR1 = 1; /* TR1: timer 1 run */
TI = 1; /* TI: set TI to send first char of UART */
/* Perform conversions forever */
while (1){
WDRST = 0x1E; /* Reset Watchdog Timer */
WDRST = 0xE1; /* Reset Watchdog Timer */
ADCI = 0; /* Clear conversion status */
ADCS = 1; /* Start conversion */
while (ADCI == 0); /* Wait for conversion */
/* Read A/D data and print it out */
printf ("DAC0 Value %4u = %01u.%04u Volts\r",
(unsigned) DAC0,
(unsigned) (DAC0 * VREF) >> 8, /* Output Integer Portion */
(unsigned) ((DAC0 * VREF * 10000UL) >> 8UL) % 10000); /* Output Decimal Portion */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -