找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2426|回复: 0
打印 上一主题 下一主题
收起左侧

mega48的模拟比较器在PROTUES仿真下的问题

[复制链接]
跳转到指定楼层
楼主
1黑币
RT:
我用mega48做模拟比较器时,选择能隙基准电压1.23V作为正输入端AIN0,AIN1作为负输入端,但仿真时AIN1一直在和5V比较,不知是程序还是硬件连接问题,有谁用过么?

附上代码:


  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. }
复制代码

QQ截图20161212193146.png (79.33 KB, 下载次数: 83)

PROTUES

PROTUES
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表