listing1.txt

来自「flash programming in linx」· 文本 代码 · 共 56 行

TXT
56
字号
/* Boot Loader.c */
unsigned short CalculateCCITT(unsigned short CurrentCRC, unsigned char NextByte);

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


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

    // setup the processor for the boot code

    // 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...
        // display message "VERIFICATION FAILED!"
        // start the download procedure
    // else run the application
} /* 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 */

⌨️ 快捷键说明

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