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

📄 listing4.txt

📁 flash programming in linx
💻 TXT
字号:
/* Boot Loader.c */
#include <reg52.h>
#include "iboot.h"

unsigned short CalculateCCITT(unsigned short CurrentCRC, unsigned char NextByte);
void RestorePowerOnDefaults(void);

#define FLASH 0
#define SRAM  1
sbit TalkTo = P1^5;

bit BootCodeRunning;

// Application code pointer
code void (*RunApplication)(void) = 0x2000;

void main(void)
{
    unsigned char xdata *FlashPointer = 0;
    unsigned int CRC_CCITT = 0;
    unsigned int i;

    // check for download command
    for (i = 0; i < MAILBOX_LENGTH; i++)
        if (BootCodeMailBox[i] != DOWNLOAD_MODE) break;

    if (i == MAILBOX_LENGTH)
    {
        // download Flash
    } /* if-then */

    // setup the processor for the boot code
    BootCodeRunning = 1;
    RestorePowerOnDefaults();

    // display the message "Verifying Software"

    /*
        Loop through all but the last byte of the flash (since j is only
        two bytes I have to stop when j == 65536; otherwise the loop would
        never end).
    */
    for (j = 0; j < 65535; j++, FlashPointer++)
        CRC_CCITT = CalculateCCITT(CRC_CCITT, *FlashPointer);

    // add the last byte
    CRC_CCITT = CalculateCCITT(CRC_CCITT, *FlashPointer);

    TalkTo = SRAM;

    // if the CRC failed...
    if (CRC_CCITT)
    {
        // display message "VERIFICATION FAILED!"
        // start the download procedure
    } /* if-then */

    BootCodeRunning = 0;
    RestorePowerOnDefaults();
    RunApplication();
} /* main */


unsigned short CalculateCCITT(unsigned short CurrentCRC, unsigned char NextByte)
{
    char i;

    for (i = 0; i < 8; i++)
    {
        if ((NextByte ^ CurrentCRC) & 1)
            CurrentCRC = (CurrentCRC >> 1) ^ 0x8408;
        else
            CurrentCRC >>= 1;

        NextByte >>= 1;
    } /* for */

    return (CurrentCRC);
} /* CalculateCCITT */


void RestorePowerOnDefaults(void)
{
    P0     = 0xFF;
    P1     = 0xFF;
    P2     = 0xFF;
    P3     = 0xFF;
    PCON   = 0;
    TCON   = 0;
    TMOD   = 0;
    TL0    = 0;
    TL1    = 0;
    TH0    = 0;
    TH1    = 0;
    IE     = 0;
    IP     = 0;
    SCON   = 0;
    T2CON  = 0;
    RCAP2L = 0;
    RCAP2H = 0;
    TL2    = 0;
    TH2    = 0;
} /* RestorePowerOnDefaults */

⌨️ 快捷键说明

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