标题:
mega48的模拟比较器在PROTUES仿真下的问题
[打印本页]
作者:
iop273252933
时间:
2016-12-12 19:35
标题:
mega48的模拟比较器在PROTUES仿真下的问题
RT:
我用mega48做模拟比较器时,选择能隙基准电压1.23V作为正输入端AIN0,AIN1作为负输入端,但仿真时AIN1一直在和5V比较,不知是程序还是硬件连接问题,有谁用过么?
附上代码:[qq]273252933[/qq]
//ICC-AVR application builder : 2016/12/12 18:18:36
// Target : m48
// Crystal: 4.0000Mhz
#include <iom48v.h>
#include <macros.h>
void delay(void)
{
unsigned int i,j;
for(i=0;i<1000;i++)
{
for(j=0;j<500;j++)
;
}
}
void port_init(void)
{
PORTB = 0xff;
DDRB = 0xff;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//Comparator initialize
// trigger on: Output toggle
void comparator_init(void)
{
ACSR = ACSR & 0xF7; //ensure interrupt is off before changing
ACSR = 0x48;
}
#pragma interrupt_handler ana_comp_isr:iv_ANA_COMP
void ana_comp_isr(void)
{
if(ACSR&(1<<ACO))
{
PORTB|=0x01;
PORTB&=0xef;
delay();
}
else
{
PORTB|=0x10;
PORTB&=0xfe;
delay();
}
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
comparator_init();
SEI(); //re-enable interrupts
}
void main(void)
{
init_devices();
while(1);
//insert your functional code here...
}
复制代码
QQ截图20161212193146.png
(79.33 KB, 下载次数: 118)
下载附件
2016-12-12 19:34 上传
PROTUES
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1