📄 main.c
字号:
/*******************************************************************
** Filename : main.c
** Project : window comparator example
** Processor : MC9S08QG8
** Version : $v
** Location : h:\projects\freescale\window comp\
** Author : A. Black
** Company : Highlander Technologies
** Date : 11/01/2005, 11:11 AM
** Compiler : Metrowerks CodeWarrior HC08 C Compiler
** Notes : HC9S08QG Quick Start Example
** : This example can be used on the DEMO9S08QG8 board
**
*******************************************************************/
#include <hidef.h> /* for EnableInterrupts macro */
#include <MC9S08QG8.h> /* include peripheral declarations */
int ADC_val_H;
int ADC_val_L;
void main(void)
{
// set up adc
ADCSC1_ADCH = 0x1f; // all channels selected disables the ADC during config
ADCCFG_ADICLK = 0; // clock source, 00=bus clock, 11 = async. clock
ADCCFG_MODE = 2; // conversion mode, 00 = 8 bit, 10 = 10 bit mode
ADCCFG_ADLSMP = 1; // sample time, 1 = long sample time
ADCCFG_ADIV = 0; // clock divide, 0 = input clock
ADCCFG_ADLPC = 0; // low power config, 1 = low power
ADCSC2_ADTRG = 0; // trigger select, 0 = software trigger
ADCSC2_ACFE = 1; // compare function, 1 = enable compare function
ADCSC2_ACFGT = 1; // 1 = compare function greater than
ADCSC1_ADCO = 1; // enable single conversion, 1 is continuous conversion
ADCSC1_AIEN = 1; // enable ADC interrupt
APCTL1_ADPC2 = 1; // disable I/O control on pin
ADCCVL = 0x90; // set a compare value
ADCCVH = 0x01; // set a compare value
// set up comparator
ACMPSC_ACMOD = 1; // 1 = comparator output on falling edge
ACMPSC_ACOPE = 0; // 0 = output pin disabled
ACMPSC_ACIE = 1; // 1 = comparator interrupt enabled
ACMPSC_ACBGS = 1; // 1 = use internal reference on ACMP+
ACMPSC_ACME = 1; // 1 = comparator enabled
ACMPSC_ACF = 1; // writing 1 clears event flag
// set up output port for an indicator
PTBDD_PTBDD6 = 1; //set PTB.6 as an output
PTBD_PTBD7 = 0;
PTBDD_PTBDD7 = 1; //set PTB.7 as an output
PTBD_PTBD7 = 0;
// set up kbi
PTAPE_PTAPE3 = 1; // enable pullup for kb3
KBIPE_KBIPE3 =1; // enable kb 3
KBISC_KBACK = 1; // clear kb interrupts
KBISC_KBIE = 1; // enable Keyboard Interrupts
EnableInterrupts; // enable interrupts
for(;;) {
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
}
//KBI ISR
interrupt 18 void KBI_ISR(void)
{
PTBD_PTBD6 = 1;
PTBD_PTBD7 = 1;
ADCSC1_ADCH = 2;
KBISC_KBACK = 1; // clear kb interrupt
ACMPSC_ACF = 1; // writing 1 clears event flag
}
// ADC ISR
interrupt 19 void ADC_ISR(void)
{
ADC_val_H = ADCRH;
ADC_val_L = ADCRL;
PTBD_PTBD6 = 0; // toggle PTB.6 pin
ADCSC1_ADCH = 0x1f; // disable the ADC when done
}
//ACMP ISR
interrupt 20 void ACMP_ISR(void)
{
PTBD_PTBD7 = 0; // toggle PTB.7 pin
ACMPSC_ACF = 1; // writing 1 clears event flag
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -