/*
;************************************************************************************************************
;*
;* http://blog.chinaunix.net/u3/104083/
;*
;*--------------------------------------------- 文件信息 ----------------------------------------------------
;*
;* 文件名称 : MAIN.c
;* 文件功能 : 应用程序
;* 补充说明 :
;*-------------------------------------------- 最新版本信息 -------------------------------------------------
;* 修改作者 : JackArm
;* 修改日期 : 2009/09/09
;* 版本声明 : V1.0.1
;*-----------------------------------------------------------------------------------------------------------
;*-----------------------------------------------------------------------------------------------------------
;************************************************************************************************************
;*/
#include #include #include #include
#include"../Inc/jack2440.h"
#define UART_BAUD0 115200//串口波特率
#define FCLK 400000000
#define HCLK (FCLK/4)
#define PCLK (HCLK/2)
#define U32 unsigned int
void UartSend_String(char *pdate);
/*
*************************************************************************************************************
- 函数名称 : void Delay(unsigned int tem)
- 函数说明 : 延时函数
- 输入参数 : tem
- 输出参数 : 无
*************************************************************************************************************
*/
void Delay(unsigned int tem)
{
while(tem--);
}
/*
*************************************************************************************************************
- 函数名称 : void UartZero_Rcv(void)
- 函数说明 : 中断初始化函数
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void __irq UartZero_Rcv(void)
{
unsigned char Rcv[2];
Rcv[0] = rURXH0;
Rcv[1] = '\0';
UartSend_String((char*)Rcv);
ClearSubPending(BIT_SUB_RXD0);
ClearPending(BIT_UART0);
}
/*
*************************************************************************************************************
- 函数名称 : void Interrupt_Init(void)
- 函数说明 : 中断初始化函数
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void Interrupt_Init()
{
pISR_UART0=(unsigned int)UartZero_Rcv;//串口收中断函数
rINTMOD=0; //所用中断都是IRQ
rINTMSK=0xefffffff; //开串口的中断
rINTSUBMSK=0x7fe; //开串口收的中断
}
/*
*************************************************************************************************************
- 函数名称 : void UartInit(void)
- 函数说明 : 串口0的初始化函数
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void UartInit(void)
{
rGPHCON = (2 << 6) | (2 << 4) | (2 << 2) | 2;//TXD0-GPH2 RXD0-GPH3 都在H口的
rGPHUP = 0x0F; //GPH[0:7]上拉除能
//初始化Uart相关寄存器
rULCON0 = 0x3;
rUCON0 = 0x245;
rUFCON0 = 0x0;
rUMCON0 = 0x0;
rUBRDIV0=( (int)(PCLK/16./UART_BAUD0+0.5) -1 ); //Baud rate divisior register 0
}
/*
*************************************************************************************************************
- 函数名称 : void UartInit(void)
- 函数说明 : 串口0的初始化函数
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
void UartSend_String(char *pdate)
{
while((*pdate) != '\0' )
{
while(!(rUTRSTAT0&0x4));//等到发送缓冲区为空;
rUTXH0=*pdate; //发送一个BYTE
pdate++; //指针指向下一个字符
}
}
/*
*************************************************************************************************************
- 函数名称 : int Main(void)
- 函数说明 : C代码入口函数
- 输入参数 : 无
- 输出参数 : 无
*************************************************************************************************************
*/
int Main(void)
{
UartInit();
Interrupt_Init();
UartSend_String("/*********************************************/\n");
UartSend_String("/* http://blog.chinaunix.net/u3/104083/ */\n");
UartSend_String("/* JackArm */\n");
UartSend_String("/*********************************************/\n");
while(1)
{
Delay(900000);//灯闪烁
rGPBDAT =(rGPBDAT|(0xA<<5))&(~(rGPBDAT&(0xA<<5)));
}
return 0;
}
文件:
jackarmBootloader.rar
大小:
65KB
下载: