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

📄 cksum.c

📁 pic单片机例程
💻 C
字号:
#include <htc.h>
#include "cksum.h"


// the return type (_D_TYPE) is based on definitions in cksum.h
_D_TYPE
cksum(void){
   _D_TYPE  sum;
   unsigned short addr;
   unsigned int counter;

	addr = _START;	// point to start of checksum range
	sum = _OFFSET;		// initial offset (usually zero)
	counter = _SIZE;

	while(counter--){
#if _BYTEOP == 1
   		unsigned short dataread;
		dataread = FLASH_READ(addr);
		_SUM(sum,dataread & 0xff);		// read a word and accumulate a byte
		_SUM(sum,dataread>>8);			// accumulate the upper byte
#else
		_SUM(sum,FLASH_READ(addr));		// read and accumulate a word
#endif
#if BYTEOP == 3
	#error Checksum algorithm +3 and -3 not supported in this demo
#endif
#if _BYTEOP == 4
		addr++;	// read and accumulate the upper word
		_SUM(sum,((unsigned long)FLASH_READ(addr)<<16L));		// read and accumulate a byte
#endif
		addr++;	// select address for next loop iteration
	}
	return sum;
}

⌨️ 快捷键说明

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