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

📄 example.c

📁 C Flash Drivers for the T89C5115 for Keil Compilers rev 1.2.0
💻 C
字号:
/*C**************************************************************************
* NAME: test_api.c 
*----------------------------------------------------------------------------
* AUTHOR:        $Author: jberthy $
* REVISION       $Revision: 1.2 $
* DATE:          $Date: 2002/12/11 09:25:43 $
*----------------------------------------------------------------------------
* PURPOSE: 
*
*****************************************************************************/

/*_____ I N C L U D E S ____________________________________________________*/
#include "stdio.h"
#include "config.h"

/*_____ M A C R O S ________________________________________________________*/

/*_____ D E F I N I T I O N ________________________________________________*/
Uchar	xdata tab[120];
/*_____ D E C L A R A T I O N ______________________________________________*/
void read_configuration_bytes (void);


/*F**************************************************************************
* NAME: uart_init 
*----------------------------------------------------------------------------
* AUTHOR: Jean-Sebatien BERTHY 
*****************************************************************************/
void uart_init (void)
{
  SCON = 0x50;
  TMOD = TMOD | 0x20 ;      /*  Timer1 in mode 2 & not gated */
  TH1 = 0xF3;               /*  2400 bauds at 12 MHZ */
  TL1 = 0xF3; 
  PCON = PCON & 0X80;
  TCON |= 0x40;         
  TI=1;
}

/*F**************************************************************************
* NAME: bin_to_asc.        
* PARAMS:  
* to_convert: byte to parse in ascii
*----------------------------------------------------------------------------
* PURPOSE: This function return the ascii value
*****************************************************************************/
Uchar bin_to_ascii (Uchar to_convert)
{
  Uchar convert;

  if ((to_convert >= 0) &&
      (to_convert <= 9)   )
  {
    convert = to_convert + 0x30;
  }
  else
  {
    convert = to_convert + 0x37;
  }
  return (convert);
}

/*F**************************************************************************
* NAME: tx_data 
*----------------------------------------------------------------------------
* PARAMS:  
* data_to_tx: byte to transmit on the line
*----------------------------------------------------------------------------
* PURPOSE: This function send on UART the value
*****************************************************************************/
void tx_data (Uchar data_to_tx)
{
  while(!TI);
  TI = 0;
  SBUF = data_to_tx;
}

/*F**************************************************************************
* NAME: send_byte_ascii 
*----------------------------------------------------------------------------
* PARAMS:  
* byte_to_tx: byte to send on UART in ascii
*----------------------------------------------------------------------------
* PURPOSE: 
*****************************************************************************/
void send_byte_ascii(Uchar byte_to_tx)
{
  Uchar data_to_tx;

  data_to_tx = bin_to_ascii( byte_to_tx >> 4);
  tx_data(data_to_tx);
  data_to_tx = bin_to_ascii( byte_to_tx & 0x0F);
  tx_data(data_to_tx);
}

/*F**************************************************************************
* NAME: send_cr_lf 
*----------------------------------------------------------------------------
* PARAMS:  
*----------------------------------------------------------------------------
* PURPOSE: 
*****************************************************************************/
void send_cr_lf(void)
{
  tx_data(0x0D);
  tx_data(0x0A);
}

/*F**************************************************************************
* NAME: main 
*----------------------------------------------------------------------------
* AUTHOR: Jean-Sebatien BERTHY 
*****************************************************************************/
void main (void)
{
	Uint16 cpt;
  Uchar	value;
  
	uart_init();


/*----- Fill block 1 with 0x55 ---------------------------------------------*/
/*--------------------------------------------------------------------------*/
	printf("Fill block 1 with 0x55\n");	// start address 2000h to 3FFFh
	for (cpt = 0; cpt< 0x10; cpt++)
	{
		tab[cpt] = 0x55;
	} 

	for (cpt=0x2000; cpt<0x3FFF; cpt=cpt+0x10)
	{
	  __api_wr_code_page(cpt, (Uint16)tab ,0x10);
	}
		
	for (cpt=0x2000; cpt<0x4000; cpt++)
	{
	  if(__api_rd_code_byte(cpt)!=tab[0])
    {
			printf("Check block 1 : KO\n");	
      break;
    }
    else
    {
      if (cpt == 0x3FFF)
      {
 			  printf("Check block 1 : OK\n");	
      }
    }
	}


/*----- write code address 0x1500 with 0x33 --------------------------------*/
/*--------------------------------------------------------------------------*/
	printf("write the byte 33h at address 1000");	
  __api_wr_code_byte(0x1500,0x33);

	if(__api_rd_code_byte(0x1500)!=0x33)
  {
	  printf("Check KO\n");	
  }
  else
  {
 	  printf("Check OK\n");	
	}


/*----- Erase block 1 and address 1000h ------------------------------------*/
/*--------------------------------------------------------------------------*/
	printf("Erase block 1 ");	// start address 2000h to 3FFFh
  __api_erase_block(BLOCK_1);


	printf("Erase address 1500h");	
  __api_wr_code_byte(0x1500, 0xFF);

	for (cpt=0x2000; cpt<0x4000; cpt++)
	{
	  if(__api_rd_code_byte(cpt)!= 0xFF)
    {
			printf(" : Erase : KO\n");	
      break;
    }
    else
    {
      if ((cpt == 0x3FFF) && (__api_rd_code_byte(0x1500)==0xFF))
      {
 			  printf(" : Erase : OK\n");	
      }
    }
	}

/*----- Test configuration bytes access ------------------------------------*/
/*--------------------------------------------------------------------------*/
	printf("Write BSB = 0x55");	
	value = __api_wr_BSB (0x55);
	send_cr_lf();

	printf("Write SBV = 0xAA");	
	value = __api_wr_SBV (0xAA);
	send_cr_lf();

	printf("Write SSB = wr_security");	
	value = __api_wr_SSB (WR_SECURITY);
	send_cr_lf();

	printf("Write EB = 5A");	
	value = __api_wr_EB (0x5A);
	send_cr_lf();

	printf("disable bit BLJB ");	
	value = __api_clr_BLJB();
	send_cr_lf();

	printf("enable bit X2 ");	
	value = __api_set_X2();
	send_cr_lf();


/*---- Read Configuration Bytes  -------------------------------------------*/
/*--------------------------------------------------------------------------*/
  read_configuration_bytes();

/*---- Read Manufacturer informations  -------------------------------------*/
/*--------------------------------------------------------------------------*/

	printf("manufacturer = ");	
	value = __api_rd_manufacturer();
	send_byte_ascii(value);
	send_cr_lf();

	printf("device id1 = ");	
	value = __api_rd_device_id1();
	send_byte_ascii(value);
	send_cr_lf();

	printf("device id2 = ");	
	value = __api_rd_device_id2();
	send_byte_ascii(value);
	send_cr_lf();

	printf("device id3 = ");	
	value = __api_rd_device_id3();
	send_byte_ascii(value);
	send_cr_lf();

	printf(" boot version = ");	
	value = __api_rd_bootloader_version ();
	send_byte_ascii(value);
	send_cr_lf();

/*----- Test configuration bytes access ------------------------------------*/
/*--------------------------------------------------------------------------*/
	printf("Write BSB = FFh");	
	value = __api_wr_BSB (0xFF);
	send_cr_lf();

	printf("Erase SBV ");	
	value = __api_erase_SBV ();
	send_cr_lf();

	printf("Write SSB = no_security");	
	value = __api_wr_SSB (NO_SECURITY);
	send_cr_lf();

	printf("Write EB = FFh");	
	value = __api_wr_EB (0xFF);
	send_cr_lf();

	printf("enable bit BLJB ");	
	value = __api_set_BLJB();
	send_cr_lf();

	printf("disable bit X2 ");	
	value = __api_clr_X2();
	send_cr_lf();

/*---- Read Configuration Bytes  -------------------------------------------*/
/*--------------------------------------------------------------------------*/
  read_configuration_bytes();

/*---- fill EEPROM from 100h to 110h with 0x5A -----------------------------*/
/*--------------------------------------------------------------------------*/
	printf("Fill EEPROM from 100h to 110 with 5Ah \n");
	for (cpt = 0x100; cpt<= 0x110; cpt++)
	{
	  while(__api_eeprom_busy()==EEPROM_BUSY);
    value = __api_wr_eeprom_byte(cpt,0x5A);
	}

/*---- Display EEPORM from 100h to 110h ------------------------------------*/
/*--------------------------------------------------------------------------*/
	printf("Read EEPROM from 0x00 to 0x10 \n");
	while(__api_eeprom_busy()==EEPROM_BUSY);
	for (cpt = 0x100; cpt< 0x110; cpt++)
	{
    value = __api_rd_eeprom_byte(cpt);
		send_byte_ascii(value);
		printf(" ");
	}
	send_cr_lf();

/*---- fill EEPROM from 100h to 110h with 0xFF -----------------------------*/
/*--------------------------------------------------------------------------*/
	printf("Fill EEPROM from 100h to 110 with FFh \n");
	for (cpt = 0x100; cpt<= 0x110; cpt++)
	{
	  while(__api_eeprom_busy()==EEPROM_BUSY);
    value = __api_wr_eeprom_byte(cpt,0xFF);
	}

/*---- Start bootloader ---------------------- -----------------------------*/
/*--------------------------------------------------------------------------*/
	printf("Start bootloader ");

// stop application peripherals 
	SCON = 0x00;
	TMOD = 0x00;
	PCON = 0x00;
	TCON = 0x00;

  __api_start_bootloader();
	while(1);

}


/*F**************************************************************************
* NAME: read_configuration_bytes 
*----------------------------------------------------------------------------
* PARAMS:  
* 
*----------------------------------------------------------------------------
* PURPOSE: 
*****************************************************************************/
void read_configuration_bytes (void)
{
  Uchar value;

	printf("BSB = ");	
	value = __api_rd_BSB();
	send_byte_ascii(value);
	send_cr_lf();

	printf("SBV = ");	
	value = __api_rd_SBV();
	send_byte_ascii(value);
	send_cr_lf();

	printf("SSB = ");	
	value = __api_rd_SSB();
	send_byte_ascii(value);
	send_cr_lf();

	printf("EB = ");	
	value = __api_rd_EB();
	send_byte_ascii(value);
	send_cr_lf();

	printf("HSB = ");	
	value = __api_rd_HSB();
	send_byte_ascii(value);
	send_cr_lf();

}





















⌨️ 快捷键说明

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