ckmain.c

来自「pic单片机例程」· C语言 代码 · 共 34 行

C
34
字号
#include <htc.h>
#include "cksum.h"

/** A simple example of how one can runtime-verify a checksum
 * that was generated using the compiler's --checksum option
 * The pre-compiled result is found in the const variable, _checksum0.
 * The header, cksum.h has settings that need to be adjusted to match the
 * --checksum specifications.
 */
void main(void){
	TRISB = 0;		// output mode
	PORTB = 0xFF;
	if( cksum() != _checksum0 ){
		while(1);	// checksum error - no effect on PORTB
		/* The calculated checksum doesn't match the pre-compiled result. Why not?
		 * Here are some likely reasons...
		 * 1) The result, _checksum0 is stored in little endian byte order. If you're
		 *    calculating a multi-byte result, you must specify a negative width component in
		 *    in --checksum.
		 * 2) Do all of the other variables in cksum.h match the --checksum settings?
		 * 3) Is the range of calculation realistic? Did it contain unimplemented memory?
		 * 4) The size of calculation range should be a multiple of the algorithm variable.
		 * 5) Did you get warning 973:"checksum range includes voids or unspecified locations"
		 *    when linking? If so, you'll need to use --FILL to program the unused locations
		 *    with a known value.
		 */
	}else{
		while(1){ 	// Success! Checksum has been verified
			PORTB ^= 0xFF;	// Celebrate on PORTB!
			_delay(8000);	// Regulate speed of PORTB activity
		}
	}
}

⌨️ 快捷键说明

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