|
1黑幣
RT:
我用mega48做模擬比較器時,選擇能隙基準電壓1.23V作為正輸入端AIN0,AIN1作為負輸入端,但仿真時AIN1一直在和5V比較,不知是程序還是硬件連接問題,有誰用過么?
附上代碼:
- //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...
- }
復制代碼
|
|