亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? an027.c

?? 53607935C8051F-Programmer-designed-by-yourself.rar
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------------
//
//	CYGNAL INTEGRATED PRODUCTS, INC.
//
// FILE NAME		: AN027.c
// TARGET DEVICE	: C8051F00x
// CREATED ON		: 12/01
// CREATED BY		: JS
//
// Example code to program a C8051F30x device through its C2 interface.
// 
// This software targets a C8051F00x device, though it could be easily
// ported to any Cygnal C8051Fxxx device.
//
// Code assumes the following Port pin connections:
//    C8051F0xx:  |  C8051F30x:
//    P1.0        ->  C2CK
//    P1.1        ->  C2D
//    VDD         ->  VDD
//    DGND        ->  GND      
//
// Program includes:
//    - FLASH programming routines (Block Write, Block Read, Page Erase,
//       Device Erase)
//    - Primitive C2 communication routines (Address Write, Address Read,
//       Data Write, Data Read, Target Reset)
//    - Test software for the above routines
//
// Calling sequences for FLASH Programming Routines:
//
// C2 Initialization Procedure:
//    1) Call C2_Reset()
//    2) Call C2_Init()
//
// Note: All following routines assume the C2 Initialization Procedure
// has been executed prior to their calling
//
// Block Read Procedure:
//    1) Set <FLASH_ADDR> to the target FLASH starting address
//    2) Set <NUM_BYTES> to the number of bytes to read
//    3) Initialize the pointer <C2_PTR> to the location to store the 
//       read data
//    4) Call C2_BlockRead() (will return a '1' if successful, 
//       '0' otherwise)
//
// Block Write Procedure:
//    1) Set <FLASH_ADDR> to the target FLASH starting address
//    2) Set <NUM_BYTES> to the number of bytes to write
//    3) Initialize the pointer <C2_PTR> to the location of the data
//       to be written
//    4) Call C2_BlockWrite() (will return a '1' if successful, 
//       '0' otherwise)
//
// Page Erase Procedure:
//    1) Set <FLASH_ADDR> to a location within the page to be erased
//    2) Call C2_PageErase()
//
// Device Erase Procedure:
//    1) Call C2_DeviceErase()
//
//-----------------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------------
#include <c8051f000.h>				      // SFR declarations
#include <stdio.h>
#include <string.h>

//-----------------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------------

// FLASH information
#define  FLASH_SIZE        8192           // FLASH size in bytes
#define  NUM_PAGES         FLASH_SIZE/512 // Number of 512-byte FLASH pages


// C2 status return codes
#define  INVALID_COMMAND   0x00
#define  COMMAND_FAILED    0x02
#define  COMMAND_OK        0x0D

// C2 interface commands
#define  GET_VERSION       0x01
#define  BLOCK_READ        0x06
#define  BLOCK_WRITE       0x07
#define  PAGE_ERASE        0x08
#define  DEVICE_ERASE      0x03

// C2 Registers
#define  FPDAT             0xB4
#define  FPCTL             0x02
#define  DEVICEID          0x00
#define  REVID             0x01

// Program MACROS
#define  Poll_OutReady     while(!(C2_ReadAR()&0x01)) 
#define  Poll_InBusy       while((C2_ReadAR()&0x02))
#define  StrobeC2CK        C2CK = LOW; C2CK = HIGH

#define  C2D_DriverOn      PRT1CF |= 0x02                // Configures C2D pin as
                                                         // push-pull output

#define  C2D_DriverOff     PRT1CF &= ~(0x02);P1 |= 0x02  // Configures C2D pin as 
                                                         // open-drain input
// Misc constants
#define  SYSCLK            16000000
#define  LOW               0
#define  HIGH              1

// C2 Signals
sbit  C2CK = P1 ^ 0;                   // Assign Port pin P1.0 as C2CK
sbit  C2D = P1 ^ 1;                    // Assign Port pin P1.1 as C2D

//-----------------------------------------------------------------------------------
// Global VARIABLES
//-----------------------------------------------------------------------------------

unsigned char NUM_BYTES;
unsigned int  FLASH_ADDR;
unsigned char idata *C2_PTR;
unsigned char idata R_BUF[128];

//-----------------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------------

// FLASH programming functions
void C2_Init();
unsigned char C2_GetDevID(void);
char C2_BlockRead(void);
char C2_BlockWrite(void);
char C2_PageErase(void);
char C2_DeviceErase(void);

// Primitive C2 functions
void C2_Reset(void);
void C2_WriteAR(char);
unsigned char C2_ReadAR(void);
void C2_WriteDR(char);
unsigned char C2_ReadDR(void);

// Utility functions
void Timer3us(unsigned int);
void Port_Init(void);

//-----------------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------------

void main()
{
   unsigned int i, j;                  // Misc. counters
   unsigned char W_BUF[] = "Hook 'em!";

   WDTCN = 0xDE;                       // Disable Watchdog Timer
   WDTCN = 0xAD;

   OSCICN |= 0x03;                     // Configure internal oscillator for
                                       // highest setting (16MHz)
   Port_Init();                        // Configure P1.0 as C2CK and P1.1 as C2D

   // Read Device ID
   C2_Reset();                         // Reset target
   j = C2_GetDevID();                  // Device ID should be 0x04 for 'F30x devices
      
   if (j != 0x04)                      // Spin here if an 'F30x device is not found
      while (1);

   // Initiate C2 FLASH Programming
   C2_Reset();                         // Start with a target device reset
   C2_Init();                          // Enable FLASH programming via C2
   
   // Erase entire FLASH code space
   C2_DeviceErase();                   // Erase entire code space

   // Read back entire FLASH memory (should be all '1's)
   FLASH_ADDR = 0x0000;                // Set target addresss (0x0000)
   NUM_BYTES = 128;                    // Set number of bytes to be read
   for (i=0;i<60;i++)                  // Perform 60 128-byte block reads (15 512-byte
   {                                   // FLASH pages, excluding reserved area)
      C2_PTR = R_BUF;                  // Initialize C2 pointer to the read buffer
      C2_BlockRead();                  // Initiate FLASH read            
      for (j=0;j<128;j++)              // Check read data
      {
         if (R_BUF[j] != 0xFF)
            while (1);                 // Spin here if any FLASH byte != 0xFF
      }
   }

   // Write FLASH block
   FLASH_ADDR = 0x0100;                // Set target FLASH address (0x0100)
   NUM_BYTES = strlen(W_BUF) + 1;      // Set number of bytes to be written (size of
                                       // string stored in W_BUF, +1 for null)
   C2_PTR = W_BUF;                     // Initialize C2 pointer to the target string
   C2_BlockWrite();                    // Initiate block write

   // Read back FLASH block
   FLASH_ADDR = 0x0100;                // Set target FLASH address          
   NUM_BYTES = strlen(W_BUF) + 1;      // Set number of bytes to be read (size of
                                       // previously written string, +1 for null)
   C2_PTR = R_BUF;                     // Initialize C2 pointer to the read buffer
   C2_BlockRead();                     // Initiate FLASH read

   if (strcmp(R_BUF, W_BUF) != 0)      // Compare written string with read data
      while (1);                       // Spin here if strings do not match

   // Erase FLASH block
   FLASH_ADDR = 0x0100;                // Set target FLASH address (page containing 
                                       // this address will be erased)
   C2_PageErase();                     // Perform Erase

   // Read back FLASH block
   FLASH_ADDR = 0x0100;                // Set target FLASH address (0x0100)
   NUM_BYTES = strlen(W_BUF) + 1;      // Set number of bytes to be read (size of
                                       // previously written string, +1 for null)
   C2_PTR = R_BUF;                     // Initialize C2 pointer to the read buffer
   C2_BlockRead();                     // Initiate FLASH read

   // Check read data (should be all 1's)
   for (i=0;i<NUM_BYTES;i++)          
   {
      if (R_BUF[i] != 0xFF)            // If read data != 0xFF, an error occured
         while (1);                    // Spin here to indicate error
   }

   while(1);                           // Program successful
}   

//-----------------------------------------------------------------------------------
// FLASH Programming Routines (High Level)
//-----------------------------------------------------------------------------------
//
// These high-level routines perform the FLASH Programming Interface (FPI)
// command sequences.

//-----------------------------------------------------------------------------------
// C2_Init()
//-----------------------------------------------------------------------------------
// - Initializes the C2 Interface for FLASH programming
//
void C2_Init()
{
   C2_Reset();                         // Reset the target device
   Timer3us(2);                        // Delay for at least 2us
   
   C2_WriteAR(FPCTL);                  // Target the C2 FLASH Programming
                                       // Control register (FPCTL) for C2 Data 
                                       // register accesses

   C2_WriteDR(0x02);                   // Write the first key code to enable 
                                       // C2 FLASH programming
   C2_WriteDR(0x01);                   // Write the second key code to enable 
                                       // C2 FLASH programming

   Timer3us(20000);                    // Delay for at least 20ms to ensure the
                                       // target is ready for C2 FLASH programming
}

//-----------------------------------------------------------------------------------
// C2_GetDevID()
//-----------------------------------------------------------------------------------
// - Reads the target Devcie ID register and Revision ID register
//
unsigned char C2_GetDevID()
{
   C2_WriteAR(DEVICEID);               // Select DeviceID regsiter for C2 Data 
                                       // register accesses
   return C2_ReadDR();                 // Read and return the DeviceID register
}

//-----------------------------------------------------------------------------------
// C2_BlockRead()
//-----------------------------------------------------------------------------------
// - Reads a block of FLASH memory starting at <FLASH_ADDR>
// - The size of the block is defined by <NUM_BYTES>
// - Stores the read data at the location targeted by the pointer <C2_PTR>
// - Assumes that FLASH accesses via C2 have been enabled prior to the function call
// - Function call returns a '1' if successful; returns a '0' if unsuccessful
//
char C2_BlockRead()
{
   unsigned char i;                    // Counter
   unsigned char status;               // FPI status information holder

   C2_WriteAR(FPDAT);                  // Select the FLASH Programming Data register 
                                       // for C2 Data register accesses
   C2_WriteDR(BLOCK_READ);             // Send FLASH block read command
   Poll_InBusy;                        // Wait for input acknowledge

   // Check status before starting FLASH access sequence
   Poll_OutReady;                      // Wait for status information
   status = C2_ReadDR();               // Read FLASH programming interface status
   if (status != COMMAND_OK)
      return 0;                        // Exit and indicate error
   
   C2_WriteDR(FLASH_ADDR >> 8);        // Send address high byte to FPDAT
   Poll_InBusy;                        // Wait for input acknowledge
   C2_WriteDR(FLASH_ADDR & 0x00FF);    // Send address low byte to FPDAT
   Poll_InBusy;                        // Wait for input acknowledge
   C2_WriteDR(NUM_BYTES);              // Send block size
   Poll_InBusy;                        // Wait for input acknowledge

   // Check status before reading FLASH block
   Poll_OutReady;                      // Wait for status information
   status = C2_ReadDR();               // Read FLASH programming interface status
   if (status != COMMAND_OK)
      return 0;                        // Exit and indicate error
   
   // Read FLASH block
   for (i=0;i<NUM_BYTES;i++)
   {
      Poll_OutReady;                   // Wait for data ready indicator
      *C2_PTR++ = C2_ReadDR();         // Read data from the FPDAT register
   }
   return 1;                           // Exit and indicate success
}

//-----------------------------------------------------------------------------------
// C2_BlockWrite()
//-----------------------------------------------------------------------------------
// - Writes a block of FLASH memory starting at <FLASH_ADDR>
// - The size of the block is defined by <NUM_BYTES>
// - Writes the block stored at the location targetted by <C2_PTR>
// - Assumes that FLASH accesses via C2 have been enabled prior to the function call
// - Function call returns a '1' if successful; returns a '0' if unsuccessful
//
char C2_BlockWrite()
{
   unsigned char i;                    // Counter
   unsigned char status;               // FPI status information holder

   C2_WriteAR(FPDAT);                  // Select the FLASH Programming Data register 
                                       // for C2 Data register accesses
   C2_WriteDR(BLOCK_WRITE);            // Send FLASH block write command
   Poll_InBusy;                        // Wait for input acknowledge

   // Check status before starting FLASH access sequence
   Poll_OutReady;                      // Wait for status information
   status = C2_ReadDR();               // Read FLASH programming interface status
   if (status != COMMAND_OK)
      return 0;                        // Exit and indicate error

   C2_WriteDR(FLASH_ADDR >> 8);        // Send address high byte to FPDAT
   Poll_InBusy;                        // Wait for input acknowledge
   C2_WriteDR(FLASH_ADDR & 0x00FF);    // Send address low byte to FPDAT

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线观看中文字幕不卡| 久久机这里只有精品| 99国产精品久久| 亚洲精品水蜜桃| 色屁屁一区二区| 午夜精品免费在线| 日韩免费看的电影| 国产麻豆91精品| 亚洲免费观看高清完整版在线观看 | 亚洲一区av在线| 91精品国产高清一区二区三区 | 97超碰欧美中文字幕| 亚洲女性喷水在线观看一区| 欧美日韩亚洲另类| 精一区二区三区| 中文字幕在线不卡国产视频| 欧美三日本三级三级在线播放| 免费人成在线不卡| 中文字幕不卡一区| 欧美亚州韩日在线看免费版国语版| 丝袜a∨在线一区二区三区不卡| 日韩亚洲欧美成人一区| 成人激情小说网站| 日日摸夜夜添夜夜添国产精品| 国产婷婷一区二区| 欧美四级电影网| 男女男精品视频网| 国产精品国产三级国产aⅴ中文| 欧美性一级生活| 国产成人福利片| 日韩精品免费专区| 国产精品久久久久久久岛一牛影视| 欧美三级在线播放| 菠萝蜜视频在线观看一区| 亚洲国产人成综合网站| 久久精品日韩一区二区三区| 欧美在线观看视频一区二区三区| 国产在线精品一区二区三区不卡 | 久久精品一区二区三区不卡 | 色999日韩国产欧美一区二区| 美腿丝袜亚洲三区| 亚洲黄色小视频| 国产亚洲欧美激情| 91麻豆精品91久久久久同性| 不卡一二三区首页| 狠狠色综合色综合网络| 亚洲一二三四区| 国产欧美一区二区精品秋霞影院 | 91浏览器在线视频| 国产一区亚洲一区| 琪琪久久久久日韩精品| 亚洲综合在线第一页| 亚洲欧洲www| 欧美韩国日本一区| 久久综合狠狠综合| 欧美电影免费观看高清完整版在| 欧日韩精品视频| 91官网在线免费观看| 99久免费精品视频在线观看| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 韩国一区二区视频| 日本成人在线视频网站| 亚洲成人激情社区| 亚洲高清不卡在线| 亚洲一区二区三区在线看| 中文字幕综合网| 亚洲欧美日韩中文字幕一区二区三区 | 极品销魂美女一区二区三区| 亚洲大片在线观看| 亚洲一区二区av电影| 亚洲一卡二卡三卡四卡无卡久久| 亚洲视频一区二区在线| 国产精品久久福利| 国产精品日韩精品欧美在线| 亚洲国产成人自拍| 国产精品传媒在线| 欧美国产成人精品| 中文字幕一区二区在线播放| 亚洲欧洲日韩在线| 亚洲精品国产无套在线观 | 亚洲一区二区三区在线播放 | 免费黄网站欧美| 青青草精品视频| 精品亚洲porn| 国产精品123区| 成人app下载| 色视频成人在线观看免| 欧美日韩成人综合天天影院| 欧美一区二区三区四区久久| 精品欧美一区二区在线观看| 欧美成人精品高清在线播放| 久久午夜老司机| 国产精品不卡一区二区三区| 亚洲免费观看高清完整| 日韩精品一区第一页| 久久99精品久久久久久久久久久久| 国产一区福利在线| 成人app在线| 91精品婷婷国产综合久久性色| 日韩欧美精品在线视频| 国产欧美精品在线观看| 亚洲免费视频中文字幕| 免费看欧美女人艹b| 国产成人精品影院| 欧美日韩精品欧美日韩精品一综合| 欧美一区二区三区啪啪| 国产午夜精品一区二区三区嫩草| 国产精品久久久久9999吃药| 香蕉影视欧美成人| 国产精品一二三区| 色婷婷av一区二区| 日韩区在线观看| 亚洲欧美偷拍卡通变态| 久久99国产精品成人| 波多野结衣精品在线| 91精品国产福利在线观看 | 久久久影院官网| 亚洲免费av高清| 国产麻豆91精品| 欧美性xxxxx极品少妇| 国产亚洲一二三区| 亚洲一二三区不卡| 成人黄页毛片网站| 日韩一区二区在线看片| 亚洲欧美在线另类| 久久国产免费看| 欧洲一区在线观看| 久久久精品免费免费| 天天综合网天天综合色| 波多野结衣中文字幕一区二区三区| 777午夜精品免费视频| 国产精品久久久久久福利一牛影视| 日韩av中文字幕一区二区三区| 97se亚洲国产综合自在线观| 久久新电视剧免费观看| 日韩精品91亚洲二区在线观看| 成年人午夜久久久| 久久亚洲精品国产精品紫薇| 首页国产欧美日韩丝袜| 色婷婷综合中文久久一本| 国产精品美女www爽爽爽| 美女网站在线免费欧美精品| 欧美视频在线观看一区二区| 国产精品九色蝌蚪自拍| 韩国午夜理伦三级不卡影院| 7777精品伊人久久久大香线蕉的 | 亚洲高清在线精品| 91丨九色porny丨蝌蚪| 国产欧美一区二区精品秋霞影院| 久久精品国产**网站演员| 精品视频在线免费| 亚洲免费观看在线视频| 91麻豆精品在线观看| 国产欧美日韩激情| 国产精品1区2区| www久久久久| 国产精品一级二级三级| 久久伊人中文字幕| 国产精品一区二区三区99| 精品国产一二三| 国内精品伊人久久久久av影院| 欧美成人高清电影在线| 久久91精品久久久久久秒播| 亚洲精品一区二区三区蜜桃下载| 免费av成人在线| 欧美成人艳星乳罩| 韩国中文字幕2020精品| 久久综合色综合88| 韩国三级电影一区二区| 久久久99精品免费观看| 国产精品亚洲午夜一区二区三区| 久久久精品综合| www.欧美亚洲| 一区二区久久久久久| 欧美在线短视频| 日韩在线观看一区二区| 欧美日韩aaaaaa| 乱一区二区av| 久久亚洲一区二区三区四区| 国产99久久久精品| 18成人在线观看| 欧美日韩国产综合一区二区| 日本不卡视频在线观看| 亚洲精品一区二区三区在线观看| 国产成人在线免费观看| 国产精品视频在线看| 色狠狠色狠狠综合| 午夜久久电影网| 久久精品在线免费观看| 91在线云播放| 婷婷一区二区三区| 2019国产精品| 色婷婷国产精品综合在线观看| 丝袜美腿亚洲一区| 国产日韩欧美精品电影三级在线| 99精品在线免费| 蜜桃视频在线一区| 亚洲国产精品v| 欧美人与禽zozo性伦| 国产综合成人久久大片91|