📄 main.c
字号:
#include <REG515.h>
#include <stdio.h>
#define V_REF 5
#define V_SCALE (0xFF/V_REF)
#define R_SCALE (99/V_REF)
unsigned char volt;
void main(void)
{
//setup serial 0
SCON = 0x50; // SCON0: mode 1, 8-bit UART, enable rcvr
TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit reload
TH1 = 221; // TH1: reload value for 9600 baud @ 16MHz
TR1 = 1; // TR1: timer 1 run
TI = 1; // TI0: set TI to send first char of UART
ADCON |= 0xF8; //Set MUX to pin 0 and mode to single-shot
DAPR = 0x00; //Set voltage range 0-5v and start first sample
while(1)
{
if(!BSY)
{
volt = ADDAT; //Get the result from the ADC
printf("AIN0 Volts = %u.%.3u\n", (int)(volt/V_SCALE), (int)(volt%V_SCALE)*R_SCALE);
IADC = 0; //Clear the ADC interrupt flag
DAPR = 0x00; //Start next sample
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -