CodeVisionAVR是Studio7的一个扩展功能,扩展功能怎么打开在前一个贴子有述:
Stuio7的扩展小部件
我觉得相见恨晚,这个是开发AVR,及Xmega的利器。
下载后安装,我默认安装在C盘,其实装D盘也可。
然后点击运行
我想首先点灯吧:
在file下选new然后建立工程:
出现一个弹出对话框,我当然选XMEGA,确定
然后选择芯片型号
单击左边的系统时钟配置
看一下是选择的内部RC2MHz
然后点左边的PORT
因为本开发板是在PORTB的4-7所以把4-7都选择输出
然后点击上边快捷菜单的有个C标志的图标,产生代码
然后再点击刚才旁边的保存图标:
保存到,自已能记信的目录里边,然后要三个文件名
一个是C文件名,一个是工程文件名,一个是CodeVisionAVR能识别的文件名,我都用一个名first。
然后在Studio7中打开这个工程。选择打开,这时到指定的目录里边就能看到Studio能识别的工程。
然后编译,出现了一个奇怪的弹出窗口,显示编译信息。然后我点下载,可以下载。
但主函数没有用户代码,我查了下它的PORT.c文件,里边是直接寄存器操作,那就直接OUT,就可以了。
程序如下,其实我就添了一句话:
PORTB.OUT=0x00;
程序如下:
- /*******************************************************
- 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/23
- 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>
- // Clock System initialization function
- #include "clock_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();
- // Ports initialization
- ports_init();
- // Virtual Ports initialization
- vports_init();
- while (1)
- {
- // Place your code here
- PORTB.OUT=0x00;
- }
- }
|