本帖最后由 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);
- }
- }
运行效果打断点观察正确
|