[Atmel] 跑一下XMEGA-B1程序(22)CodeVisionAVR之五:位取反

[复制链接]
 楼主| ddllxxrr 发表于 2016-1-27 20:34 | 显示全部楼层 |阅读模式
本帖最后由 ddllxxrr 于 2016-1-27 20:35 编辑


位取反,自已起来还得至少三到四行代码,最起码得判断语句加上。

而CodeVisionAVR就很简单,只要在头文件包含<iobits.h>就可以了

它的函数有以下几个:


SETBIT(port,n);设置端口第n位为1

CLRBIT (port,n);设置端口第n位为0


TGLBIT(port,n);设置端口第n位为来回反转


EQUBIT(port,n);给端口第n位为赋值


为了检验我特地编了个工程


建立时只设了端口B的方向:




以下是形成的程序:我只是在while里添了个反转函数
  1. /*******************************************************
  2. This program was created by the CodeWizardAVR V3.24
  3. Automatic Program Generator
  4. ?Copyright 1998-2015 Pavel Haiduc, HP InfoTech s.r.l.
  5. http://www.hpinfotech.com

  6. Project :
  7. Version :
  8. Date    : 2016/1/27
  9. Author  :
  10. Company :
  11. Comments:


  12. Chip type               : ATxmega128B1
  13. Program type            : Application
  14. AVR Core Clock frequency: 2.000000 MHz
  15. Memory model            : Small
  16. Data Stack size         : 2048
  17. *******************************************************/

  18. // I/O Registers definitions
  19. #include <io.h>

  20. // Standard Input/Output functions
  21. #include <stdio.h>


  22. #include <iobits.h>

  23. // Clock System initialization function
  24. #include "clock_init.h"

  25. // Event System initialization function
  26. #include "event_system_init.h"

  27. // I/O Ports initialization function
  28. #include "ports_init.h"

  29. // Declare your global variables here

  30. void main(void)
  31. {
  32. // Declare your local variables here
  33. unsigned char n;

  34. // Interrupt system initialization
  35. // Optimize for speed
  36. #pragma optsize-
  37. // Make sure the interrupts are disabled
  38. #asm("cli")
  39. // Low level interrupt: Off
  40. // Round-robin scheduling for low level interrupt: Off
  41. // Medium level interrupt: Off
  42. // High level interrupt: Off
  43. // The interrupt vectors will be placed at the start of the Application FLASH section
  44. n=(PMIC.CTRL & (~(PMIC_RREN_bm | PMIC_IVSEL_bm | PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm)));
  45. CCP=CCP_IOREG_gc;
  46. PMIC.CTRL=n;
  47. // Set the default priority for round-robin scheduling
  48. PMIC.INTPRI=0x00;
  49. // Restore optimization for size if needed
  50. #pragma optsize_default

  51. // System clocks initialization
  52. system_clocks_init();

  53. // Event system initialization
  54. event_system_init();

  55. // Ports initialization
  56. ports_init();

  57. // Virtual Ports initialization
  58. vports_init();

  59. while (1)
  60.       {
  61.       TGLBIT(PORTB.OUT,4);

  62.       }
  63. }


运行效果打断点观察正确


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

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

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2403

主题

6994

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2403

主题

6994

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部