找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

帖子
查看: 3589|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

mega48的模擬比較器在PROTUES仿真下的問(wèn)題

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
#
ID:93718 發(fā)表于 2016-12-12 19:35 | 只看該作者 |只看大圖 回帖獎(jiǎng)勵(lì) |正序?yàn)g覽 |閱讀模式
1黑幣
RT:
我用mega48做模擬比較器時(shí),選擇能隙基準(zhǔn)電壓1.23V作為正輸入端AIN0,AIN1作為負(fù)輸入端,但仿真時(shí)AIN1一直在和5V比較,不知是程序還是硬件連接問(wèn)題,有誰(shuí)用過(guò)么?

附上代碼:


  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
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表