本帖最后由 weshiluwei6 于 2011-8-7 19:02 编辑
初学M0
初学C++ 试试写个C++小程序 再用上大叔的红杏
感谢大叔的教诲
led.cpp-
- /*---------------------------------------------------------------------------------------------------------*/
- /* */
- /* Copyright(c) 2009 Nuvoton Technology Corp. All rights reserved. */
- /* */
- /*---------------------------------------------------------------------------------------------------------*/
- #include <stdio.h>
- #include "NUC1xx.h"
- #include "NUC1xxM051Seriescfg.h" //红杏头文件
- #include "Driver\DrvGPIO.h"
- #include "Driver\DrvSYS.h"
- /*************************************************************************************
- ** Function name: delay_loop
- ** Descriptions: 延时子程序
- ** input parameters: 无
- ** output parameters: 无
- ** Returned value: 无
- *************************************************************************************/
- void DelayMs(uint32_t z)
- {
- uint32_t i,j;
- for(i=z;i>0;i--)
- for(j=2000;j>0;j--);
- }
- class Point
- {
- public:
- int x;
- int y;
- void init()
- {
- x = 0;
- y = 0;
- }
- void output()
- {
- GPIOAs.DOUT.Regs |= 0xff;
- GPIOAs.DOUT.Regs &= x;
- DelayMs(1000);
- GPIOAs.DOUT.Regs |= 0xff;
- GPIOAs.DOUT.Regs &= y;
- DelayMs(1000);
- }
- };
- /*************************************************************************************
- ** Function name: main
- ** Descriptions: LED2跟随LED1的亮灭而灭亮测试程序
- ** 现 象:下载代码,运行程序,则LED1亮LED2灭 LED1灭LED2亮循环反复
- ** input parameters: 无
- ** output parameters: 无
- ** Returned value: 无
- *************************************************************************************/
- int main (void)
- {
- /* SYSCLK =>12Mhz*/
- UNLOCKREG();
- SYSCLK->WRCON.XTL12M_EN = 1;
- LOCKREG();
- //
- // DrvGPIO_Open( E_GPA, 2, E_IO_OUTPUT );
- // DrvGPIO_Open( E_GPA, 3, E_IO_OUTPUT );
- GPIOAs.DMASK.Regs &= 0xf3;
- Point pt;
- pt.init();
- pt.x = 0xfb;
- pt.y = 0xf7;
- while(1)
- {
- pt.output();
- }
- }
[localimg=180,135]2[/localimg]
|