/******* CheckSum.c ************ * * Use the same Fosc = 8 MHz as QwikBug uses. * A checksum for the contents of addresses 0x1A00-0x1FFF * will be sent to the PC. This will allow a check on what revision * of the QwikBug kernal resides in the chip. * The checksum for the 20071029QB kernal is C198. * ******* Program hierarchy ***** * * main * Initial * InitTX * Check * ******************************* */ #include // Define PIC18LF4321 registers and bits /******************************* * Global variables ******************************* */ unsigned char i; // Index into string unsigned char HEX; // One hex character (0-15) unsigned char ASCII; // One ASCII-coded character const char rom *RomPtr; // Pointer to one-byte ROM elements unsigned int CHECKSUM; // Sixteen-bit checksum /******************************* * Table in program memory ******************************* */ const char rom FormHex[] = "0123456789ABCDEF"; /******************************* * Function prototypes ******************************* */ void Initial(void); void Check(void); /******************************* * Macro ******************************* */ #define TXascii(in) TXREG = in; while(!TXSTAbits.TRMT) /////// Main program //////////////////////////////////////////////////// void main() { Initial(); // Initialize everything Check(); // Form checksum and send to PC Sleep(); // Sleep forever Nop(); } /******************************* * Initial * * This function performs all initializations of variables and registers. ******************************* */ void Initial() { OSCCON = 0b01110010; // Use Fosc = 8 MHz (Fcpu = 2 MHz) RCSTA = 0b10010000; // Enable UART TXSTA = 0b00100000; // Enable TX SPBRG = 25; // Set baud rate BAUDCON = 0b00111000; // Invert TX output } /******************************* * Check * * This function forms a checksum on QwikBug residing in program * memory from 0x1A00 to 0x1FFF. It sends the checksum to the PC as * a hex number for display. * Prepared by Jeff Pitcher and Adam McDaniel ******************************* */ void Check() { CHECKSUM = 0; RomPtr = (const char rom *) (0x1A00); while (RomPtr <= (const char rom *)(0x1FFF)) { CHECKSUM += *RomPtr++; // Add into checksum } TXascii('\r'); // Send carriage return TXascii('\n'); // and line feed HEX = (CHECKSUM & 0xF000) >> 12; // Get upper nibble ASCII = FormHex[HEX]; // Convert to ASCII TXascii(ASCII); // and send to console HEX = (CHECKSUM & 0x0F00) >> 8; // Get next nibble ASCII = FormHex[HEX]; TXascii(ASCII); HEX = (CHECKSUM & 0x00F0) >> 4; // Get third nibble ASCII = FormHex[HEX]; TXascii(ASCII); HEX = (CHECKSUM & 0x000F); // Get fourth nibble ASCII = FormHex[HEX]; TXascii(ASCII); }