📄 comp.c
字号:
/*********************************************************************
Author : ADI - Apps www.analog.com/MicroConverter
Date : Sept. 2005
File : Comp.c
Hardware : Applicable to ADuC702x rev H or I silicon
Currently targetting ADuC7026.
Description : The comparator is configured to compare ADC2
with DAC0 and generates an interrupt on falling
and rising edge. P4.2 blinks at different speed
depending on the type of edge
*********************************************************************/
#include<ADuC7026.h>
void delay(int);
void My_IRQ_Function(void); // IRQ Function Prototype
unsigned int i;
int main (void) {
GP4DAT = 0x04000000; // P4.2 configured as an output. LED is turned on
REFCON = 0x01; // internal 2.5V reference. 2.5V on Vref pin
CMPCON = 0x6E4; // ADC2 > DAC0 => CMPOUT = 1
// ADC2 < DAC0 => CMPOUT = 0
IRQ = My_IRQ_Function; // Specify Interrupt Service Rountine
IRQEN = 0x10000; // Enable Comparator
DAC0CON = 0x13; // DAC configuration
// range AVdd/AGND
// DAC0 is updated with falling edge of core clock
DAC0DAT = 0x08000000; // midscale
while (1)
{
}
}
void delay (int length)
{
while (length >=0)
{
length--;
}
}
/********************************************************************/
/* */
/* Interrupt Service Routine */
/* */
/********************************************************************/
void My_IRQ_Function()
{
if (CMPCON & 0x1) { // falling edge on CMPOUT
CMPCON = 0x6E5; // clear comparator int bit
for (i=0; i<=20; i++){
delay(100000);
GP4DAT ^= 0x00040000; // Complement P4.2
}
}
if (CMPCON & 0x2) { // rising edge on CMPOUT
CMPCON = 0x6E6; // clear comparator int bit
for (i=0; i<=10; i++){
delay(200000);
GP4DAT ^= 0x00040000; // Complement P4.2
}
}
return ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -