国产成人av人人爽人人澡-亚洲国产日韩欧美一区-好吊日视频这里只有精品-日本高清精品视频在线

您好,歡迎進入深圳市穎特新科技有限公司官方網(wǎng)站!

您現(xiàn)在的位置:首頁 新聞資訊 >> 新聞頭條 >> N76E003之IAP
新聞資訊
NEWS INFORMATION

N76E003之IAP

關(guān)鍵字:單片機燒錄 N76E003 發(fā)布時間:2019-05-22

修改FLASH數(shù)據(jù)通常需要很長時間,不像RAM那樣可以實時操作。而且擦除、編程或讀取FLASH數(shù)據(jù)需要遵循相當復(fù)雜的時序步驟。N76E003提供方便FALSH編程方式,可以幫助用戶通過IAP方式,重新編程FLASH內(nèi)容。IAP就是通過軟件實現(xiàn)在線電擦除和編程的方法。

通過設(shè)置IAPEN(CHPCON.0受TA保護)使能IAP,并且設(shè)置IAPUEN寄存器的相應(yīng)位,使能需要升級的FLASH區(qū)域(CONFIG、LDROM、APROM),用戶將16位操作地址寫入IAPAH和IAPAL,數(shù)據(jù)寫入IAPFD,命令寫入IAPCN。然后通過設(shè)置觸發(fā)位IAPGO(IAPTRG.0),去執(zhí)行IAP。注意:IAPTRG也受TA保護。此時,CPU保持程序計數(shù)器,內(nèi)嵌IAP自動控制內(nèi)部充電泵提高電壓和信號時序。擦除和編程時間是內(nèi)部控制的,與工作電壓和頻率無關(guān)。通常頁擦除時間是5ms,字節(jié)編程時間是 3.5μs。IAP動作完成后,程序計數(shù)器繼續(xù)運行之后的指令,IAPGO位將自動清零。IAPFF (CHPCON.6)是IAP錯誤標志,可以用來檢查之前IAP操作成功與否。通過這些純軟件的設(shè)置,用戶可以很方便對FLASH存儲器進行擦除、編程和校驗。

 

 

IAP可以方便用戶更新FLASH內(nèi)容,不過用戶必須遵循一定規(guī)則,以確保IAP正確執(zhí)行,否則可能引起不確定的結(jié)果,甚至損壞器件。此外,下文對于正確執(zhí)行IAP有很好建議。
(1)沒有IAP操作時,用戶必須清IAPEN (CHPCON.0)位。可以防止系統(tǒng)意外觸發(fā)IAP。此外,IAP需要使用內(nèi)部HIRC振蕩器。如果選擇外部時鐘源,禁止IAP將停止內(nèi)部HIRC,可以達到省電的目的。注:寫IAPEN受TA保護。
(2)當LOCK位(CONFIG0.1) 被激活,IAP讀、寫或擦除仍然有效。


在進行IAP時,如果中斷打開應(yīng)該臨時清除EA位
擦除或編程的頁不能是當前代碼執(zhí)行的頁。否則會出現(xiàn)不可預(yù)計程序動作,甚至破壞存儲的數(shù)據(jù)

使用flash存儲器作為數(shù)據(jù)存儲
在一般應(yīng)用中,有時需要一些數(shù)據(jù)在斷電情況下不能丟失,以便用戶讀回或更新,作為系統(tǒng)控制的參數(shù)。N76E003支持IAP功能并且存儲在flash中的字節(jié)都可以用MOVC指令讀取,所以很適合作為非易失數(shù)據(jù)存儲器。Flash寫次數(shù)為100,000次,以下參考應(yīng)用代碼:

匯編例程如下:
;******************************************************************************
; This code illustrates how to use IAP to make APROM 201h as a byte of
; Data Flash when user code is executed in APROM.
;******************************************************************************
PAGE_ERASE_AP EQU 00100010b
BYTE_PROGRAM_AP EQU 00100001b
ORG 0000h
MOV TA,#0Aah ;CHPCON is TA protected
MOV TA,#55h
ORL CHPCON,#00000001b ;IAPEN = 1, enable IAP mode
MOV TA,#0Aah ;IAPUEN is TA protected
MOV TA,#55h
ORL IAPUEN,#00000001b ;APUEN = 1, enable APROM update
MOV IAPCN,#PAGE_ERASE_AP ;Erase page 200h~27Fh
MOV IAPAH,#02h
MOV IAPAL,#00h
MOV IAPFD,#0FFh
MOV TA,#0Aah ;IAPTRG is TA protected
MOV TA,#55h
ORL IAPTRG,#00000001b ;write ‘1’ to IAPGO to trigger IAP process
MOV IAPCN,#BYTE_PROGRAM_AP ;Program 201h with 55h
MOV IAPAH,#02h
MOV IAPAL,#01h
MOV IAPFD,#55h

MOV TA,#0Aah
MOV TA,#55h
ORL IAPTRG,#00000001b
MOV TA,#0Aah
MOV TA,#55h
ANL IAPUEN,#11111110b ;APUEN = 0, disable APROM update
MOV TA,#0Aah
MOV TA,#55h
ANL CHPCON,#11111110b ;IAPEN = 0, disable IAP mode
MOV DPTR,#201h
CLR A
MOVC A,@A+DPTR ;Read content of address 201h
MOV P0,A
SJMP $

C 語言例程如下:
//******************************************************************************
// This code illustrates how to use IAP to make APROM 201h as a byte of
// Data Flash when user code is executed in APROM.
//******************************************************************************
#define PAGE_ERASE_AP 0x22
#define BYTE_PROGRAM_AP 0x21
/*Data Flash, as part of APROM, is read by MOVC. Data Flash can be defined as
128-element array in “code” area from absolute address 0x0200 */
volatile unsigned char code Data_Flash[128] _at_ 0x0200;
Main (void)
{
TA = 0xAA; //CHPCON is TA protected
TA = 0x55;
CHPCON |= 0x01; //IAPEN = 1, enable IAP mode
TA = 0xAA; //IAPUEN is TA protected
TA = 0x55;
IAPUEN |= 0x01; //APUEN = 1, enable APROM update
IAPCN = PAGE_ERASE_AP; //Erase page 200h~27Fh
IAPAH = 0x02;
IAPAL = 0x00;
IAPFD = 0xFF;
TA = 0xAA; //IAPTRG is TA protected
TA = 0x55;
IAPTRG |= 0x01; //write ‘1’ to IAPGO to trigger IAP process
IAPCN = BYTE_PROGRAM_AP; // Program 201h with 55h
IAPAH = 0x02;
IAPAL = 0x01;

IAPFD = 0x55;

TA = 0xAA;
TA = 0x55;
IAPTRG |= 0x01; //write ‘1’ to IAPGO to trigger IAP process
TA = 0xAA; //IAPUEN is TA protected
TA = 0x55;
IAPUEN &= ~0x01; //APUEN = 0, disable APROM update
TA = 0xAA; //CHPCON is TA protected
TA = 0x55;
CHPCON &= ~0x01; //IAPEN = 0, disable IAP mode
P0 = Data_Flash[1]; //Read content of address 200h+1
while(1);
}

 N76E003 APROM程序DATAFLASH為EEPROM方式

#include <stdio.h>
#include "N76E003.h"
#include "Common.h"
#include "Delay.h"
#include "SFR_Macro.h"
#include "Function_Define.h"

bit BIT_TMP;

//-------------------------------------------------------------------------
UINT8 read_APROM_BYTE(UINT16 code *u16_addr)
{
    UINT8 rdata;
    rdata = *u16_addr>>8;
    return rdata;
}
//-------------------------------------------------------------------------


/*****************************************************************************************************************
write_DATAFLASH_BYTE :
user can copy all this subroutine into project, then call this function in main.
******************************************************************************************************************/        
void write_DATAFLASH_BYTE(UINT16 u16_addr,UINT8 u8_data)
{
    UINT8 looptmp=0,u8_addrl_r;
    unsigned char code *cd_longaddr;
    unsigned char xdata *xd_tmp;
    
//Check page start address
    u8_addrl_r = u16_addr;
    if (u8_addrl_r<0x80)
    {
        u8_addrl_r = 0;
    }
    else 
    {
        u8_addrl_r = 0x80;
    }
//Save APROM data to XRAM
    xd_tmp = 0x80;
    cd_longaddr = (u16_addr&0xff00)+u8_addrl_r;    
    while (xd_tmp !=0x100)
    {
        *xd_tmp = *cd_longaddr;
        looptmp++;
        xd_tmp++;
        cd_longaddr++;
    }
// Modify customer data in XRAM
    u8_addrl_r = u16_addr;
    if (u8_addrl_r<0x80)
    {
        xd_tmp = u8_addrl_r+0x80;
    }
    else
    {
        xd_tmp = u8_addrl_r+0;
    }
    *xd_tmp = u8_data;
//Erase APROM DATAFLASH page
        IAPAL = u16_addr;
        IAPAH = u16_addr>>8;
        IAPFD = 0xFF;
      set_IAPEN; 
        set_APUEN;
    IAPCN = 0x22;         
         set_IAPGO; 
//Save changed RAM data to APROM DATAFLASH
    u8_addrl_r = u16_addr;
    if (u8_addrl_r<0x80)
    {
        u8_addrl_r =0;
    }
    else
    {
        u8_addrl_r = 0x80;
    }
        xd_tmp = 0x80;
      IAPAL = u8_addrl_r;
    IAPAH = u16_addr>>8;
        set_IAPEN; 
        set_APUEN;
      IAPCN = 0x21;
        while (xd_tmp !=0xFF)
        {
            IAPFD = *xd_tmp;
            set_IAPGO;
            IAPAL++;
            xd_tmp++;
        }
        clr_APUEN;
        clr_IAPEN;
}    
/******************************************************************************************************************/        


void main (void) 
{
        UINT8 datatemp;
/* -------------------------------------------------------------------------*/
/*  Dataflash use APROM area                                                                         */
/*    APROM 0x3800~0x38FF demo as dataflash                                                         */
/* Please use Memory window key in C:0x3800 to check earse result                      */          
/* -------------------------------------------------------------------------*/
    
//call write byte 
        write_DATAFLASH_BYTE (0x3881,0x55);
        write_DATAFLASH_BYTE (0x3882,0x56);
        write_DATAFLASH_BYTE (0x3855,0xaa);
        write_DATAFLASH_BYTE (0x3856,0x66);
//call read byte
        datatemp = read_APROM_BYTE(0x3882);
    while(1);
}

下面針對每一個調(diào)用函數(shù)進行講解

void write_DATAFLASH_BYTE(UINT16 u16_addr,UINT8 u8_data)
{
    UINT8 looptmp=0,u8_addrl_r;
    unsigned char code *cd_longaddr;
    unsigned char xdata *xd_tmp;
    
//Check page start address
    u8_addrl_r = u16_addr;
    if (u8_addrl_r<0x80)
    {
        u8_addrl_r = 0;
    }
    else 
    {
        u8_addrl_r = 0x80;
    }
//Save APROM data to XRAM
    xd_tmp = 0x80;
    cd_longaddr = (u16_addr&0xff00)+u8_addrl_r;    
    while (xd_tmp !=0x100)
    {
        *xd_tmp = *cd_longaddr;
        looptmp++;
        xd_tmp++;
        cd_longaddr++;
    }
// Modify customer data in XRAM
    u8_addrl_r = u16_addr;
    if (u8_addrl_r<0x80)
    {
        xd_tmp = u8_addrl_r+0x80;
    }
    else
    {
        xd_tmp = u8_addrl_r+0;
    }
    *xd_tmp = u8_data;
//Erase APROM DATAFLASH page
        IAPAL = u16_addr;
        IAPAH = u16_addr>>8;
        IAPFD = 0xFF;
        set_IAPEN; 
        set_APUEN;
    IAPCN = 0x22;         
         set_IAPGO; 
//Save changed RAM data to APROM DATAFLASH
    u8_addrl_r = u16_addr;
    if (u8_addrl_r<0x80)
    {
        u8_addrl_r =0;
    }
    else
    {
        u8_addrl_r = 0x80;
    }
        xd_tmp = 0x80;
      IAPAL = u8_addrl_r;
    IAPAH = u16_addr>>8;
        set_IAPEN; 
        set_APUEN;
      IAPCN = 0x21;
        while (xd_tmp !=0xFF)
        {
            IAPFD = *xd_tmp;
            set_IAPGO;
            IAPAL++;
            xd_tmp++;
        }
        clr_APUEN;
        clr_IAPEN;
}    

上面這個函數(shù),是對DATAFLASH  EEPROM進行讀寫,有主函數(shù)給出地址和數(shù)據(jù),由該函數(shù)進行處理



void write_DATAFLASH_BYTE(UINT16 u16_addr,UINT8 u8_data)
{
    UINT8 looptmp=0,u8_addrl_r;
    unsigned char code *cd_longaddr;
    unsigned char xdata *xd_tmp;
    
//Check page start address
    u8_addrl_r = u16_addr;
    if (u8_addrl_r<0x80)
    {
        u8_addrl_r = 0;
    }
    else 
    {
        u8_addrl_r = 0x80;
    }
//Save APROM data to XRAM
    xd_tmp = 0x80;
    cd_longaddr = (u16_addr&0xff00)+u8_addrl_r;    
    while (xd_tmp !=0x100)
    {
        *xd_tmp = *cd_longaddr;
        looptmp++;
        xd_tmp++;
        cd_longaddr++;
    }
// Modify customer data in XRAM
    u8_addrl_r = u16_addr;
    if (u8_addrl_r<0x80)
    {
        xd_tmp = u8_addrl_r+0x80;
    }
    else
    {
        xd_tmp = u8_addrl_r+0;
    }
    *xd_tmp = u8_data;
//Erase APROM DATAFLASH page
        IAPAL = u16_addr;
        IAPAH = u16_addr>>8;
        IAPFD = 0xFF;
        set_IAPEN; 
        set_APUEN;
    IAPCN = 0x22;         
         set_IAPGO; 
//Save changed RAM data to APROM DATAFLASH
    u8_addrl_r = u16_addr;
    if (u8_addrl_r<0x80)
    {
        u8_addrl_r =0;
    }
    else
    {
        u8_addrl_r = 0x80;
    }
        xd_tmp = 0x80;
      IAPAL = u8_addrl_r;
    IAPAH = u16_addr>>8;
        set_IAPEN; 
        set_APUEN;
      IAPCN = 0x21;
        while (xd_tmp !=0xFF)
        {
            IAPFD = *xd_tmp;
            set_IAPGO;
            IAPAL++;
            xd_tmp++;
        }
        clr_APUEN;
        clr_IAPEN;
}    

標紅部分涉及到兩個寄存器IAPL與IAPH,這起什么作用呢?看一下手冊

由此可知,這兩個寄存器是寫入16位地址字節(jié)的,也就是說u8_addrl_r這個變量的含義是給寄存器提供地址,因此,需要一些數(shù)據(jù)的分析和處理,

 u8_addrl_r = u16_addr;
    if (u8_addrl_r<0x80)
    {
        u8_addrl_r = 0;
    }
    else 
    {
        u8_addrl_r = 0x80;
    }
//Save APROM data to XRAM
    xd_tmp = 0x80;
    cd_longaddr = (u16_addr&0xff00)+u8_addrl_r;    
    while (xd_tmp !=0x100)
    {
        *xd_tmp = *cd_longaddr;
        looptmp++;
        xd_tmp++;
        cd_longaddr++;
    }
Save APROM data to XRAM

首先查看N76E003的數(shù)據(jù)手冊得知這顆芯片的XRAM的大小為:768字節(jié)i ,即大小為0x300另外還可知道Flash每一頁的大小為128字節(jié)即0x80。這段歷程劃分區(qū)域到0X100(256)。

 

 

// Modify customer data in XRAM
    u8_addrl_r = u16_addr;
    if (u8_addrl_r<0x80)
    {
        xd_tmp = u8_addrl_r+0x80;
    }
    else
    {
        xd_tmp = u8_addrl_r+0;
    }
    *xd_tmp = u8_data;
//Erase APROM DATAFLASH page
        IAPAL = u16_addr;
        IAPAH = u16_addr>>8;
        IAPFD = 0xFF;
        set_IAPEN; 
        set_APUEN;
    IAPCN = 0x22;         
         set_IAPGO; 

 

 Modify customer data in XRAM
 在XRAM中修改客戶數(shù)據(jù)

 

 

 

 

//Save changed RAM data to APROM DATAFLASH
    u8_addrl_r = u16_addr;
    if (u8_addrl_r<0x80)
    {
        u8_addrl_r =0;
    }
    else
    {
        u8_addrl_r = 0x80;
    }
        xd_tmp = 0x80;
      IAPAL = u8_addrl_r;
      IAPAH = u16_addr>>8;
        set_IAPEN; 
        set_APUEN;
      IAPCN = 0x21;
        while (xd_tmp !=0xFF)
        {
            IAPFD = *xd_tmp;
            set_IAPGO;
            IAPAL++;
            xd_tmp++;
        }
        clr_APUEN;
        clr_IAPEN;
}    

這部分比較復(fù)雜,我后續(xù)會有更新,如果有什么意見或建議,歡迎評論

知識沒有學(xué)完的時候,我只能保證明天的自己跟今天不一樣,各個方面,無論是做人還是做事,無論是專業(yè)素質(zhì),還是為人處世,待人接物。

聯(lián)系方式0755-82591179

傳真:0755-82591176

郵箱:vicky@yingtexin.net

地址:深圳市龍華區(qū)民治街道民治大道973萬眾潤豐創(chuàng)業(yè)園A棟2樓A08

2019年国产最新视频| 欧美成人欧美一级乱黄| 亚洲综合激情另类专区老铁性 | 精品久久久一区二区三| 日韩成人h视频在线观看| 国产又大又黄又粗又免费| 少妇视频一区二区三区| 亚洲欧美日韩中文字幕二欧美| 日本人妻熟女一区二区三区| 国产成人精品一区二三区在线观看| 99精品国产一区二区青青| 国产精品午夜性色视频| 久久精品亚洲精品一区| 日本99精品在线观看| 日本高清一道一二三区四五区| 亚洲欧美日韩中文字幕二欧美| 男人和女人干逼的视频| 中文字幕亚洲精品乱码加勒比| 99久只有精品免费视频播放| 丝袜诱惑一区二区三区| 欧美胖熟妇一区二区三区| 九九热在线免费在线观看| 日韩三级黄色大片免费观看| 国产一区欧美一区日韩一区| 国产精品午夜小视频观看| 日韩在线免费看中文字幕| 欧美日韩一区二区午夜| 日本男人女人干逼视频| 午夜成年人黄片免费观看| 黄色国产精品一区二区三区| 日韩性生活视频免费在线观看| 日本免费熟女一区二区三区| 国产成人精品99在线观看| 深夜日本福利在线观看| 日韩在线视频精品视频| 91久久精品国产成人| 欧美成人一区二区三区在线 | 色综合久久六月婷婷中文字幕| 亚洲一区二区三区中文久久| 亚洲国产精品一区二区| 加勒比系列一区二区在线观看|