/*---------------------------------------------------------------------------------------------------------*/
/* */
/* 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"
uint8_t i;
uint8_t table[] = {0x00,0x6C,0x92,0x82,0x44,0x28,0x10,0x00};
uint8_t colum[] = {
0x7f,0xbf,0xdf,0xef,
0xf7,0xfb,0xfd,0xfe
};
/*************************************************************************************
** Function name: DelayMs
** Descriptions: 延时1ms子程序
** 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--);
}
void Init_GPIO(void)
{
/* PA ------- X */
DrvGPIO_Open( E_GPA, 0, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 1, E_IO_OUTPUT );
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 );
DrvGPIO_Open( E_GPA, 6, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 7, E_IO_OUTPUT );
/* PB ------- Y */
DrvGPIO_Open( E_GPB, 0, E_IO_OUTPUT );
DrvGPIO_Open( E_GPB, 1, E_IO_OUTPUT );
DrvGPIO_Open( E_GPB, 2, E_IO_OUTPUT );
DrvGPIO_Open( E_GPB, 3, E_IO_OUTPUT );
DrvGPIO_Open( E_GPB, 4, E_IO_OUTPUT );
DrvGPIO_Open( E_GPB, 5, E_IO_OUTPUT );
DrvGPIO_Open( E_GPB, 6, E_IO_OUTPUT );
DrvGPIO_Open( E_GPB, 7, E_IO_OUTPUT );
}
void Init_System(void)
{
/* Unlock the locked registers before access */
UNLOCKREG(x); //寄存器锁定键地址寄存器(RegLockAddr) :有些系统控制寄存器需要被保护起来,以防止误操作而影响芯片运行,
//这些寄存器在上电复位到用户解锁定之前是锁定的。用户可以连续依次写入“59h”, “16h” “88h”到0x5000_0100解锁定.
/* Enable the 12MHz oscillator oscillation */
DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1); //SYSCLK->WRCON.XTL12M_EN = 1;
/* Waiting for 12M Xtal stable */
//while (DrvSYS_GetChipClockSourceStatus(E_SYS_XTL12M) != 1); //SYSCLK->CLKSTATUS.XTL12M_STB
/*eClkSrc - [in] E_SYS_XTL12M / E_SYS_XTL32K / E_SYS_OSC22M / E_SYS_OSC10K / E_SYS_PLL */
// Note: Only some of NuMicro NUC100 Series support this function.
DrvSYS_Delay(5000);
LOCKREG(x);
//向“0x5000_0100”写入任何值,就可以重锁保护寄存器
}
/*************************************************************************************
** Function name: main
** Descriptions:
** 现 象:
** input parameters: 无
** output parameters: 无
** Returned value: 无
*************************************************************************************/
int main (void)
{
Init_System();
Init_GPIO();
while(1)
{
for(i = 0;i < 8; i++)
{
GPIOAs.DOUT.Regs = table;
GPIOBs.DOUT.Regs = colum;
DelayMs(2);
}
}
}