예제 #1
0
void ihx_read_print(__xdata uint8_t* start_addr, uint16_t len) {
  __xdata char buff[45];
  uint8_t byte, sum, i, chunk;
  
  while (len) {
    sum = 0;
    if(len > 0x10)
      chunk = 0x10;
    else
      chunk = len;
    
    buff[0] = ':';
    to_hex8_ascii(&buff[1], chunk);
    sum += chunk;
    // Write address into buffer
    to_hex16_ascii(&buff[3], (uint16_t)start_addr);
    sum += (uint16_t)start_addr & 0xFF;
    sum += ((uint16_t)start_addr >> 8) & 0xFF;
    // Write record type into buffer
    to_hex8_ascii(&buff[7], 0x00);
    // Write data bytes into buffer
    for (i=0; i<chunk; i++) {
      byte = *(start_addr+i);
      sum += byte;
      to_hex8_ascii(&buff[9 + 2*i], byte);
    }
    // Write checksum into buffer
    to_hex8_ascii(&buff[9 + 2*i], (uint8_t)(-(int8_t)sum));
    buff[11 + 2*i] = '\n';
    buff[12 + 2*i] = 0;
    
    // Print buffer over usb
    usb_putstr(buff);
    
    // Updates for next go round
    if(len > 0x10) {
      start_addr += 0x10;
      len -= 0x10;
    } else // we're done
      len = 0;
  }
  usb_putstr(":00000001FF\n");
}
예제 #2
0
파일: main.c 프로젝트: GBert/EasyCAN
/**
 * Send given value as hexadecimal string
 *
 * @param value Value to send as hex over the UART
 * @param len Count of characters to produce
 */
void sendHex(unsigned long value, unsigned char len) {

    char s[20];
    s[len] = 0;

    while (len--) {

        unsigned char hex = value & 0x0f;
        if (hex > 9) hex = hex - 10 + 'A';
        else hex = hex + '0';
        s[len] = hex;

        value = value >> 4;
    }

    usb_putstr(s);

}