/**************************************************************************//**
* [url=home.php?mod=space&uid=288409]@file[/url] main.c
* [url=home.php?mod=space&uid=895143]@version[/url] V1.00
* $Revision: 2 $
* $Date: 15/08/18 11:54a $
* [url=home.php?mod=space&uid=247401]@brief[/url] NUC200 Series I2S Controller Sample Code
*
* @note
* Copyright (C) 2011 Nuvoton Technology Corp. All rights reserved.
*
******************************************************************************/
#include <stdio.h>
#include "NUC230_240.h"
#include "NuEdu-Basic01.h"
volatile unsigned int data;
volatile unsigned int count;
volatile unsigned int p_flag;
/**
* @brief Timer0 IRQ
*
* @param None
*
* [url=home.php?mod=space&uid=266161]@return[/url] None
*
* [url=home.php?mod=space&uid=1543424]@Details[/url] The Timer0 default IRQ, declared in startup_M051Series.s.
*/
void TMR0_IRQHandler(void)
{
/* Clear Timer0 time-out interrupt flag */
TIMER_ClearIntFlag(TIMER0);
if(count!=0)
{
if((data&0x01)==0x01)
PA0=1;
else
PA0=0;
data=data>>1;
count--;
}
}
void UART_GPIO(unsigned char uart_data)
{
data=0;
data=(uart_data<<1)|(1<<9); //STOP BIT + 8 DATA BIT + START BIT
count=10;
/* Start Timer0 counting */
TIMER_Start(TIMER0);
while(count!=0);
/* Stop timer0 counting */
TIMER_Stop(TIMER0);
}
void SW_UART_INIT(void)
{
GPIO_SetMode(PA, BIT0, GPIO_PMD_OUTPUT);
/* Enable peripheral clock */
CLK->APBCLK |= CLK_APBCLK_TMR0_EN_Msk ;
/* Peripheral clock source */
CLK->CLKSEL1 |= CLK_CLKSEL1_TMR0_S_HIRC;
/* Open Timer0 frequency 115200 in periodic mode, and enable interrupt */
TIMER0->TCMPR = (22118400/115200);
TIMER0->TCSR = TIMER_TCSR_IE_Msk | TIMER_PERIODIC_MODE;
TIMER_SET_PRESCALE_VALUE(TIMER0, 0);
/* Enable Timer0 NVIC */
NVIC_EnableIRQ(TMR0_IRQn);
}
/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
unsigned int temp_count;
SYS_Init();
SW_UART_INIT();
for(temp_count=0;temp_count<256;temp_count++)
{
UART_GPIO(temp_count&0xff);
}
while(1);
}
|