打印
[Atmel]

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

[复制链接]
774|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 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里添了个反转函数
/*******************************************************
This program was created by the CodeWizardAVR V3.24
Automatic Program Generator
?Copyright 1998-2015 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date    : 2016/1/27
Author  :
Company :
Comments:


Chip type               : ATxmega128B1
Program type            : Application
AVR Core Clock frequency: 2.000000 MHz
Memory model            : Small
Data Stack size         : 2048
*******************************************************/

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

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


#include <iobits.h>

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

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

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

// Declare your global variables here

void main(void)
{
// Declare your local variables here
unsigned char n;

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

// System clocks initialization
system_clocks_init();

// Event system initialization
event_system_init();

// Ports initialization
ports_init();

// Virtual Ports initialization
vports_init();

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

      }
}


运行效果打断点观察正确


相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2398

主题

6949

帖子

66

粉丝