本帖最后由 lixiaoxu2meng 于 2011-8-11 12:21 编辑
1.首先要建好自己的工程模板
2.配置好MDK选项
以上两点在论坛上都有详细的说明这里就不说了
3.按照自己的编程习惯向工程里添加代码
main函数代码- *---------------------------------------------------------------------------------------------------------*/
- /* */
- /* Copyright(c) 2011 Nuvoton Technology Corp. All rights reserved. */
- /* */
- /*---------------------------------------------------------------------------------------------------------*/
- #include "includes.h" //包含所需的头文件
- /*************************************************************************************
- ** Function name: main
- ** Descriptions: 4个LED轮流点亮
- ** input parameters: 无
- ** output parameters: 无
- ** Returned value: 无
- *************************************************************************************/
- int main (void)
- {
- Set_System();
- while(1)
- {
- DrvGPIO_SetBit(E_GPA,5);
- DrvGPIO_ClrBit(E_GPA,2);
- delay_ms(1000);
- DrvGPIO_SetBit(E_GPA,2);
- DrvGPIO_ClrBit(E_GPA,3);
- delay_ms(1000);
- DrvGPIO_SetBit(E_GPA,3);
- DrvGPIO_ClrBit(E_GPA,4);
- delay_ms(1000);
- DrvGPIO_SetBit(E_GPA,4);
- DrvGPIO_ClrBit(E_GPA,5);
- delay_ms(1000);
- }
- }
hw_config函数代码 用来封装一些主函数以外的函数- #include "includes.h" //包含所需的头文件
- /*************************************************************************************
- ** Function name: Set_System
- ** Descriptions: 系统配置
- ** input parameters: 无
- ** output parameters: 无
- ** Returned value: 无
- *************************************************************************************/
- void Set_System(void)
- {
- RCC_Configuration(); //配置系统时钟
- GPIO_Configuration(); //配置GPIO
- }
- /*************************************************************************************
- ** Function name: RCC_Configuration
- ** Descriptions: 系统时钟源设置
- ** input parameters: none
- ** output parameters: none
- ** Returned value: none
- *************************************************************************************/
- void RCC_Configuration(void)
- {
- UNLOCKREG(); // 对写保护位操作时 需要一次向0x50000 0100写入 0x59,0x16,0x88,
- DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1);//与其 SYSCLK->WRCON.XTL12M_EN = 1; 等同
- // PWRCON寄存器(这些寄存器在上电复位到用户解锁定之前是锁定的)除了 BIT[6]位其他位都受写保护
- // 解除这些需要向 0x50000 0100写入 0x59,0x16,0x88,
- // 令PWRCON寄存器的BITP[0]为1(即设定12M外部晶振)
- delay_ms(100); //while (DrvSYS_GetChipClockSourceStatus(E_SYS_XTL12M) != 1);//等待外部12MHZ晶振就绪
- LOCKREG(); // 向“0x5000_0100”写入任何值,就可以重锁保护寄存器
- }
- /*************************************************************************************
- ** Function name: GPIO_Configuration
- ** Descriptions: 端口配置
- ** input parameters: none
- ** output parameters: none
- ** Returned value: none
- *************************************************************************************/
- void GPIO_Configuration()
- {
- DrvGPIO_Open( E_GPA, 2, E_IO_OUTPUT );
- DrvGPIO_Open( E_GPA, 3, E_IO_OUTPUT );
- DrvGPIO_Open( E_GPA, 4, E_IO_OUTPUT );
- DrvGPIO_Open( E_GPA, 5, E_IO_OUTPUT );
- }
- /*************************************************************************************
- ** Function name: delay_ms
- ** Descriptions: 1ms(晶振为12MHZ)延时子程序
- ** input parameters: count
- ** output parameters: 无
- ** Returned value: 无
- *************************************************************************************/
- void delay_ms(uint32_t count)
- {
- uint32_t i,j;
- for(i=count;i>0;i--)
- for(j=2395;j>0;j--);
- }
hw_config.h函数代码 用来声明hw_config.c里函数- void Set_System(void);
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- includes.h函数包含所用到的头文件
- [code]#include <stdio.h>
- #include "NUC1xx.h"
- #include "variables.h"
- #include "hw_config.h"
- #include "Driver\DrvGPIO.h"
- #include "Driver\DrvSYS.h"
void delay_ms(uint32_t count);
[/code]
下面上传工程
本工程实现 4个led的轮流点亮
可以将延时 时间设短一点编程流水灯
第一个工程 还请大家 指正
|