📄 sampling.c
字号:
#include <eZ8.h>
#include <stdio.h>
#include <sio.h>
#define ENABLE 0x80 // CEN
#define SAMPLING_PRD 1440 // quarter-second sampling rate
#pragma interrupt
void isrTimer1(void) {
ACTL |= ENABLE; // start a single-shot conversion
}
#pragma interrupt
void isrADC(void) {
int val;
val = ((int)ADHR << 2) | (ADLR >> 6);
printf("%4.3f \n", val/512.0);
}
void InitADC(void) {
PBAF = 0x01; // PB0 = ANA0
ACTL = 0x00; // ANA0, single, int VRef
}
void InitTimer(void) {
DI();
T1CTL = (0x07 << 3) | 0x01; // Cont mode, prescale 2^7=128
T1H = 0x00; T1L = 0x01; // T1 start = 0x0001
T1RH = (SAMPLING_PRD >> 8); // T1 reload value
T1RL = (SAMPLING_PRD & 0xFF);
SET_VECTOR(TIMER1,isrTimer1);
SET_VECTOR(ADC,isrADC);
IRQ0ENH |= 0x41; // high priority timer1 & ADC int
IRQ0ENL |= 0x41;
IRQ0 &= ~0x41; // clr timer1 & ADC int flag
EI();
T1CTL |= 0x80; // Enable timer1
}
void main(void) {
init_uart(_UART0, _DEFFREQ, _DEFBAUD);
printf("Press any key to start sampling\n");
getch();
InitADC();
InitTimer();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -