⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 DownLoad_sst39sf010.zip--嵌入式系统中关于SST39SF010的FLASH的BOOTLOADER源程序(KC51)
💻 C
字号:
/*********************************************************************
 
  (c) copyright Extell Company 2001 
  ALL RIGHTS RESERVED
 
 *********************************************************************
        ESR-700 Demonstration Program for Voice Recognition Application
 *********************************************************************

  File:		main.c
 
  Project:      ESR-700 demo program for Demo Board DownLoad
 
  Description:  DownLoad Main Program
 
  Date:         Sep. 2001
   
 ********************************************************************/

#include <stdio.h>
#include "extell51.h"
#include "main.h"


#define BUFFER_LEN	64

union BLOCK_SIZE {
	unsigned short length;
	struct {
		unsigned char msb;
		unsigned char lsb;
	} div;
};


void delay(unsigned int count)
{
	unsigned int data i;
	for(i=0;i<count;i++){}
}


void init()
{

	// 12.288 MHz => 0xfb
	TH1 = 0xfb;		// f3(4800), fb(12800)
	TL1 = 0xff;
	PCON = 0x80;
	TMOD = 0x22;
	SM0 = 0;
	SM1 = 1;
	TI = 1;
	RI = 1;
	TR1 = 1;
	REN = 1;

	// interrupt enable
	EA = 1;
	// edge sensitivie
	IT1 = 1;
}

void erase_flash()
{
	unsigned short data addr;
	MXRAM = 1;
	for(addr=0;addr<=0xf000;addr+=0x1000)
	{
		while(SectorErase(addr)!=OK);
		if(addr==0xf000)break;
	}
	MXRAM = 0;
}

void main()
{
	unsigned char data rdata;
	unsigned char data check_sum;
	unsigned short data flash_addr;
	union BLOCK_SIZE block;
	unsigned short data block_written;
	unsigned char data i;
	unsigned char data buffer[BUFFER_LEN];
	char mode;
	unsigned char led1;
	unsigned char count;

	init();
	P1 = 0xff;

	count = 0;
	while(1)
	{
		while(1)
		{
			RI = 0;
			while( !RI );
			if(SBUF=='H')
			{
				TI = 0;
				SBUF = 0x00;
				while( !TI );
	
				RI = 0;
	
				while( !RI );
				if(SBUF=='Y')
				{
					TI = 0;
					SBUF = 0x00;
					while( !TI );
	
					RI = 0;
					while( !RI );
					if(SBUF=='S') { break;}
				}
			}
			P1 = 0xff;
		}
	
		P1 = 0xff;
		TI = 0;
		SBUF = 0X00;
		while( !TI );
	
		// ready to receive data
	
		// receive bank index

		RI = 0;
		while( !RI );
		
		delay(100);

		// erase selected bank flash
		erase_flash();

		TI = 0;
		SBUF = 0x00;
		while( !TI );
	
		// receive block size infomation
		P1_6 = 0;
	
		RI = 0;
		while( !RI );	
		block.div.msb = SBUF;	
		TI = 0;
		SBUF = 0x00;
		while( !TI );
	
		RI = 0;
		while( !RI );
		block.div.lsb = SBUF;
		TI = 0;
		SBUF = 0x00;
		while( !TI );

		flash_addr = 0;
		mode = 0;
		block_written = 0;

		led1 = 0xfe;
		P1 = led1;

		while(1)
		{
			// ready to receive !!

			RI = 0;
			while( !RI );

			check_sum = 0;

			TI = 0;
			SBUF = 0x00;
			while( !TI );

			for( i=0; i<BUFFER_LEN; i++)
			{
				RI = 0;
				while( !RI );

				buffer[i] = SBUF;
				check_sum += SBUF;
			}

			// get check sum
			RI = 0;
			while( !RI );
			rdata = SBUF;

			if( rdata == check_sum )
			{
				mode = 0;
				for( i=0; i<BUFFER_LEN; i++)
				{
					rdata = buffer[i];
					MXRAM = 1;
					FlashWrite(flash_addr,rdata);
					delay(5);
					MXRAM = 0;
					flash_addr++;
				}
				block_written ++;
			}
			else
				mode = 1;

			if( block_written == block.length )
			{
				P1 = 0xff;
				P1_0 = 0;
				P1_1 = 0;

				if( mode == 0 )
				{
					TI = 0;
					SBUF = 0x00;
					while( !TI );
				}
				else
				{
					TI = 0;
					SBUF = 0x0f;
					while( !TI );
				}

				break;
			}

			count ++;

			if( count%12 == 0 )
			{
				P1 = led1;
				led1 = led1 << 1;
				led1 = led1 | 0x01;
				if( led1==0xff )
					led1 = 0xfe;
			}

			if( mode == 0 )
			{
				TI = 0;
				SBUF = 0x00;
				while( !TI );
			}
			else
			{
				TI = 0;
				SBUF = 0x0f;
				while( !TI );
			}

		}	

		while(1)
		{
			delay(60000);delay(60000);delay(60000);
			P1_0 = ~ P1_0;
			P1_1 = ~ P1_1;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -