📄 app1.c
字号:
/*****************************************************************************
* app1.c: main C entry file for NXP LPC24xx Family Microprocessors
*
* 应用程序,从串口接收文件,然后烧写到Flash上
*
* History
* 2007.12.13 ver 1.00 Prelimnary version, first Release
*
******************************************************************************/
#include "LPC2468.h" /* LPC23xx/24xx definitions */
#include "type.h"
#include "target.h"
#include "irq.h"
#include "uart.h"
#include "ex_sdram.h"
#include "ex_norflash.h"
#define BAUDRATE 9600
/*****************************************************************************
** Main Function main()
*****************************************************************************/
int main (void)
{
unsigned long i,length,count,address=0xa0000000;
volatile WORD *ip;
char *buf;
DWORD NorFlashAdr;
TargetResetInit();
SDRAMInit();
UARTInit(BAUDRATE);
NORFLASHInit();
/* 接收文件 */
printf("This is a Uart/Flash application.It'll transfer file by uart,then write it into Flash.\n");
printf("Please transfer the file now...\n");
length = LoadFromUart(address) ; // 收下来的字节数
count = length / SECTOR_SIZE; // 需要的扇区数
ip = (WORD *)address;
buf = (char *)address;
// puts(buf);
/* Flash烧写 */
if ( NORFLASHCheckID() == FALSE )
{
printf("NOR Flash ID error!\r\n");
while ( 1 );
}
for(i=0;i<=count;i++)NORFLASHSectorErase(i); // Flash使用之前要先擦除
NorFlashAdr = 0x0;
for ( i = 0; i < (length+1)/2; i++ ) // 因为存储单元为字,当length为奇数个字节时需要多补一个字节
{
if(!NORFLASHWriteWord( NorFlashAdr, *ip ))
{
printf("Write error!\n");
while(1);
}
NorFlashAdr++;
ip++;
}
printf("\nThe application successed!\n");
while(1);
}
/*****************************************************************************
** End Of File
*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -