標(biāo)題:
mega48的模擬比較器在PROTUES仿真下的問題
[打印本頁]
作者:
iop273252933
時(shí)間:
2016-12-12 19:35
標(biāo)題:
mega48的模擬比較器在PROTUES仿真下的問題
RT:
我用mega48做模擬比較器時(shí),選擇能隙基準(zhǔn)電壓1.23V作為正輸入端AIN0,AIN1作為負(fù)輸入端,但仿真時(shí)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...
}
復(fù)制代碼
QQ截圖20161212193146.png
(79.33 KB, 下載次數(shù): 118)
下載附件
2016-12-12 19:34 上傳
PROTUES
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1