亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
中文字幕一区二区三区在线观看| 一区二区三区在线免费视频| 欧美国产精品中文字幕| 国产精品对白交换视频| 麻豆精品一区二区综合av| 91在线视频免费91| 国产亚洲视频系列| 久久国产综合精品| 欧美三级在线播放| 亚洲狼人国产精品| av中文一区二区三区| 欧美精品一区二区三区蜜桃| 日韩—二三区免费观看av| 色婷婷综合久久久久中文| 中日韩av电影| 国产福利一区在线观看| 日韩午夜电影av| 午夜久久久久久久久久一区二区| 91偷拍与自偷拍精品| 国产精品久线观看视频| 福利一区在线观看| 亚洲va欧美va国产va天堂影院| 国产成人a级片| 亚洲精品一区二区在线观看| 麻豆一区二区三| 欧美一区二区性放荡片| 视频一区二区三区在线| 欧美高清精品3d| 日韩电影在线免费观看| 日韩情涩欧美日韩视频| 韩国视频一区二区| 久久久久久久久久久电影| 蜜臀av性久久久久蜜臀av麻豆| 日韩欧美国产三级| 六月丁香婷婷久久| 久久久久久久久99精品| 高清不卡在线观看| 国产精品视频在线看| 99re视频精品| 午夜欧美一区二区三区在线播放| 制服.丝袜.亚洲.中文.综合| 日韩激情在线观看| 久久久久久久综合狠狠综合| 成人午夜在线播放| 亚洲免费观看高清完整版在线 | 日韩av高清在线观看| 日韩西西人体444www| 国产精品亚洲专一区二区三区| 国产偷v国产偷v亚洲高清| a亚洲天堂av| 亚洲成人一区二区| 久久综合久久综合亚洲| 成人免费毛片a| 亚洲综合成人在线| 欧美成人在线直播| 成人av电影在线网| 石原莉奈在线亚洲三区| 久久精品一区八戒影视| 99精品欧美一区二区三区小说| 亚洲线精品一区二区三区八戒| 欧美成人女星排名| 色综合久久综合网97色综合| 日本不卡一区二区三区| 欧美激情在线一区二区三区| 欧美性一区二区| 国产一区二区在线免费观看| 亚洲精品日日夜夜| 精品对白一区国产伦| 色先锋aa成人| 国产真实乱对白精彩久久| 一区二区三区四区精品在线视频| 日韩一卡二卡三卡| 在线亚洲一区观看| 国产精品一区二区果冻传媒| 亚洲成人自拍网| 国产精品毛片高清在线完整版| 在线成人免费视频| 久久久久久久电影| 欧美三级日韩三级国产三级| 成人黄色片在线观看| 久久99日本精品| 亚洲国产精品视频| 一区二区中文字幕在线| 日韩视频一区二区在线观看| 欧美在线观看一区| 91在线精品一区二区三区| 国产中文字幕一区| 老司机午夜精品99久久| 午夜激情综合网| 一区二区三区国产豹纹内裤在线| 国产精品丝袜一区| 精品国产免费视频| 日韩欧美国产综合| 在线电影欧美成精品| 精品视频免费在线| 欧美做爰猛烈大尺度电影无法无天| 高清国产一区二区| 国产精品亚洲午夜一区二区三区 | 蜜臂av日日欢夜夜爽一区| 亚洲第一会所有码转帖| 亚洲视频一二三| 国产精品护士白丝一区av| 国产精品另类一区| 国产视频一区二区在线观看| 久久奇米777| 久久久一区二区三区捆绑**| 欧美一级高清片| 日韩视频免费观看高清完整版在线观看 | 综合在线观看色| 中文在线一区二区| 国产亚洲精品久| 中文一区一区三区高中清不卡| 久久综合色鬼综合色| 久久久蜜桃精品| 久久精品人人做人人综合| 久久久久久99久久久精品网站| 亚洲精品一区二区在线观看| 26uuu亚洲综合色欧美| 精品久久久久一区二区国产| 欧美一区二区成人| 精品成人一区二区三区四区| 精品国产一区二区三区av性色 | 成人免费毛片片v| 本田岬高潮一区二区三区| 成人av高清在线| 色猫猫国产区一区二在线视频| 欧美丝袜丝nylons| 日韩欧美激情在线| 国产午夜精品在线观看| 亚洲四区在线观看| 亚洲成av人片观看| 国产一区二区在线影院| 99精品欧美一区二区三区综合在线| 日本精品视频一区二区| 一级日本不卡的影视| 亚洲超丰满肉感bbw| 国产主播一区二区| 色999日韩国产欧美一区二区| 欧美日本国产一区| 久久九九久久九九| 樱花草国产18久久久久| 免费在线欧美视频| 波多野结衣视频一区| 欧美日本高清视频在线观看| 久久久久国产精品免费免费搜索| 中文字幕在线观看不卡视频| 婷婷久久综合九色综合伊人色| 精品一区二区三区影院在线午夜| 99在线热播精品免费| 日韩一区二区麻豆国产| 1区2区3区欧美| 激情国产一区二区| 欧美三区免费完整视频在线观看| 精品999在线播放| 亚洲五码中文字幕| 大白屁股一区二区视频| 91精品国产品国语在线不卡| 国产精品国产精品国产专区不片| 免费看欧美女人艹b| 91视频免费播放| 国产亚洲欧美色| 蜜桃视频在线观看一区| 在线一区二区视频| 国产精品久久久久久久久搜平片| 日韩影院精彩在线| 91福利资源站| 国产精品国产a| 国产一区在线看| 欧美一级日韩免费不卡| 亚洲人123区| 成人av网站在线观看免费| 久久综合久久综合亚洲| 日本色综合中文字幕| 在线看一区二区| 亚洲欧洲www| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 国产乱码一区二区三区| 91精品国产综合久久精品麻豆 | 精品国产免费视频| 午夜欧美大尺度福利影院在线看| 99国产精品久久| 国产精品系列在线| 国产91露脸合集magnet| 亚洲精品在线观看网站| 免费观看在线综合| 欧美人与z0zoxxxx视频| 亚洲国产一区二区三区青草影视| 91在线观看下载| 亚洲欧美综合网| 99re这里只有精品首页| 亚洲欧洲日产国码二区| 成人av在线网站| 亚洲视频精选在线| 成人av免费在线播放| 国产精品久久久一区麻豆最新章节| 国产九色精品成人porny| 国产亚洲视频系列| 成人午夜免费视频| 国产精品久久久久久户外露出 | 国产亚洲综合色|