標(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]


  1. //ICC-AVR application builder : 2016/12/12 18:18:36
  2. // Target : m48
  3. // Crystal: 4.0000Mhz

  4. #include <iom48v.h>
  5. #include <macros.h>
  6. void delay(void)
  7. {
  8.     unsigned int i,j;
  9.     for(i=0;i<1000;i++)
  10.     {
  11.        for(j=0;j<500;j++)
  12.        ;
  13.     }
  14. }
  15. void port_init(void)
  16. {
  17. PORTB = 0xff;
  18. DDRB  = 0xff;
  19. PORTC = 0x00; //m103 output only
  20. DDRC  = 0x00;
  21. PORTD = 0x00;
  22. DDRD  = 0x00;
  23. }
  24. //Comparator initialize
  25. // trigger on: Output toggle
  26. void comparator_init(void)
  27. {
  28. ACSR = ACSR & 0xF7; //ensure interrupt is off before changing
  29. ACSR = 0x48;
  30. }
  31. #pragma interrupt_handler ana_comp_isr:iv_ANA_COMP
  32. void ana_comp_isr(void)
  33. {
  34. if(ACSR&(1<<ACO))
  35. {
  36. PORTB|=0x01;
  37. PORTB&=0xef;
  38. delay();
  39. }
  40. else
  41. {
  42. PORTB|=0x10;
  43. PORTB&=0xfe;
  44. delay();
  45. }
  46. }
  47. //call this routine to initialize all peripherals
  48. void init_devices(void)
  49. {
  50. //stop errant interrupts until set up
  51. CLI(); //disable all interrupts
  52. port_init();
  53. comparator_init();
  54. SEI(); //re-enable interrupts

  55. }
  56. void main(void)
  57. {
  58. init_devices();
  59. while(1);
  60. //insert your functional code here...
  61. }
復(fù)制代碼

QQ截圖20161212193146.png (79.33 KB, 下載次數(shù): 118)

PROTUES

PROTUES





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1