1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development C binary data display?

Discussion in 'Software' started by Kipman725, 3 May 2008.

  1. Kipman725

    Kipman725 When did I get a custom title!?!

    Joined:
    1 Nov 2004
    Posts:
    1,753
    Likes Received:
    0
    Hello I am progressing with my EEPROM programer and have hit what may be a light snag. I have made a program that reads an .OBJ file and then prints the contents of that file however the contents are not printed as the correct value, idealy I would like them to be hex values. I think its some kind of problem with the data type that printf() is using but I don't know enough about C to be able to fix it. Do I need to convert the binary data into intiger data? (although this is rather a waste of memory!), if so could somone show me an example of how to do this?

    I also include the binary file to see if anyone can see any pattens between it and the programs output:
    http://rapidshare.com/files/112133407/test.obj.html
     
  2. HapeMask

    HapeMask What's a Dremel?

    Joined:
    19 Jan 2006
    Posts:
    120
    Likes Received:
    0
    In your final printf statement, try %X or %x (upper or lower case) instead of %d, I'm not on my mac so I can't test it now, but that might work.
     
  3. shadow12

    shadow12 I lie

    Joined:
    30 Sep 2007
    Posts:
    231
    Likes Received:
    1
  4. wyx087

    wyx087 Homeworld 3 is happening!!

    Joined:
    15 Aug 2007
    Posts:
    11,987
    Likes Received:
    706
    i also had faced this problem when programming an interface for USB.

    printf is your friend, so is sprintf.

    to convert 8-bit binary number to type int (00010101 should be turned into 21)
    the %d is correct
    to convert 8-bit binary number to type char but in hex
    i THINK it's %x as HapeMask said. but not quite sure about the output type in-case you want to use sprintf

    although may i ask what exactly are you using to interface with the EEPROM? i am 100% sure if that C code is going into AVR, it's completely wrong.
     
  5. woodshop

    woodshop UnSeenly

    Joined:
    14 Oct 2003
    Posts:
    1,408
    Likes Received:
    8
    edited code
    Code:
    /* This program reads a binary file */
    #include <stdlib.h> /* exit, malloc, etc.. */
    #include <stdio.h>  /* printf, File I/O etcc */
    #include <unistd.h> /* for sleep */
    
    #define BYTES_PER_LINE 16 
    
    /* dump array to stdout with ascii translation */
    void fprintHexDump(unsigned const char* data, const int msgLen) {
        int curByte, bytesThisLine, offset;
    	
        for (offset = 0; offset < msgLen; offset += bytesThisLine) {
            bytesThisLine = ((msgLen-offset) < BYTES_PER_LINE) ? (msgLen-offset) : BYTES_PER_LINE;
            for (curByte = 0; curByte < bytesThisLine; curByte++)
                printf("%02X ", data[curByte+offset]);
            for ( ; curByte < BYTES_PER_LINE; curByte++)
                printf("   ");
            for (curByte = 0; curByte < bytesThisLine; curByte++) {
                char asc = ((data[curByte+offset] < 0x20) || (data[curByte+offset] > 0x7E)) ?
    			'.' : (unsigned char)(data[curByte+offset]);
                printf("%c", asc);
            }
            printf("\n");
        }
    }
    
    int main(int argc, char **argv){ 
    	/* vars */
    	long size;
    	/* Pointers for file and memory heap */
    	FILE *f;
    	/* were dealing with binary data, unsigned should be assumed it helps to prevent accidents */
    	unsigned char * buffer;
    	size_t result;
    	
    	/* begin code */
    	if( argc != 2){
    		printf("Usage:\n%s <file>\n", argv[0]);
    	}
    	printf("opening file %s ... \n", argv[1]);
    	/* open file, print error and exit if problem */ 
    	if ((f = fopen(argv[1], "rb")) ==NULL){
    		printf("Error opening file\n");
    		sleep(2000);
    		exit(1);
    	}
    	printf("Success!!!\n");
    	
    	/* find out how big the file is */
    	/* This is NOT something that will ALWAYS
    	 work and has been an on/oof hot topic
    	 though no better way exist to my knowlage */ 
    	fseek (f, 0, SEEK_END);
    	size=ftell (f);
    	printf ("Size of file %ld bytes.\n",size);
    	rewind (f); /* goto the start of the file */
    	
    	/* lets alocate some heap memory for this file */
    	buffer = (unsigned char*) malloc (sizeof(char)*size);
    	if (buffer == NULL) {
    		printf("Memory error\n"); 
    		exit (2);
    	} 
    	
    	/* copy file into heap */
    	result = fread (buffer,1,size,f);
    	if (result != size) {
    		printf("Reading error\n"); 
    		sleep(2000);
    		exit (3);
    	}
    	
    	/* as a little test print the contents of the file */
    	fprintHexDump(buffer, size);
    	
    	/* clean up */
    	fclose(f); 
    	free(buffer);
    	return 0;
    }
    
    
    running
    ignore the <snip> shorting message </snip>
    i had to comply to the 20,000 char post limit
    Code:
    macbook-pro-15:Desktop woodshop2300$ 
    macbook-pro-15:Desktop woodshop2300$ 
    macbook-pro-15:Desktop woodshop2300$ gcc -Wall -ansi -pedantic read.c 
    macbook-pro-15:Desktop woodshop2300$ ./a.out a.out 
    opening file a.out ... 
    Success!!!
    Size of file 12884 bytes.
    CE FA ED FE 07 00 00 00 03 00 00 00 02 00 00 00 ................
    0B 00 00 00 A8 03 00 00 85 00 00 00 01 00 00 00 ................
    38 00 00 00 5F 5F 50 41 47 45 5A 45 52 4F 00 00 8...__PAGEZERO..
    00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 01 00 00 00 C0 00 00 00 5F 5F 54 45 ............__TE
    58 54 00 00 00 00 00 00 00 00 00 00 00 10 00 00 XT..............
    00 10 00 00 00 00 00 00 00 10 00 00 07 00 00 00 ................
    05 00 00 00 02 00 00 00 00 00 00 00 5F 5F 74 65 ............__te
    78 74 00 00 00 00 00 00 00 00 00 00 5F 5F 54 45 xt..........__TE
    58 54 00 00 00 00 00 00 00 00 00 00 6C 1C 00 00 XT..........l...
    0A 03 00 00 6C 0C 00 00 02 00 00 00 00 00 00 00 ....l...........
    00 00 00 00 00 04 00 80 00 00 00 00 00 00 00 00 ................
    5F 5F 63 73 74 72 69 6E 67 00 00 00 00 00 00 00 __cstring.......
    5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00 __TEXT..........
    76 1F 00 00 87 00 00 00 76 0F 00 00 00 00 00 00 v.......v.......
    00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 ................
    00 00 00 00 01 00 00 00 C0 00 00 00 5F 5F 44 41 ............__DA
    54 41 00 00 00 00 00 00 00 00 00 00 00 20 00 00 TA........... ..
    00 10 00 00 00 10 00 00 00 10 00 00 07 00 00 00 ................
    03 00 00 00 02 00 00 00 00 00 00 00 5F 5F 64 61 ............__da
    74 61 00 00 00 00 00 00 00 00 00 00 5F 5F 44 41 ta..........__DA
    54 41 00 00 00 00 00 00 00 00 00 00 00 20 00 00 TA........... ..
    14 00 00 00 00 10 00 00 02 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    5F 5F 64 79 6C 64 00 00 00 00 00 00 00 00 00 00 __dyld..........
    5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00 __DATA..........
    14 20 00 00 1C 00 00 00 14 10 00 00 02 00 00 00 . ..............
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 01 00 00 00 7C 00 00 00 5F 5F 49 4D ........|...__IM
    50 4F 52 54 00 00 00 00 00 00 00 00 00 30 00 00 PORT.........0..
    00 10 00 00 00 20 00 00 00 10 00 00 07 00 00 00 ..... ..........
    07 00 00 00 01 00 00 00 00 00 00 00 5F 5F 6A 75 ............__ju
    6D 70 5F 74 61 62 6C 65 00 00 00 00 5F 5F 49 4D mp_table....__IM
    50 4F 52 54 00 00 00 00 00 00 00 00 00 30 00 00 PORT.........0..
    46 00 00 00 00 20 00 00 06 00 00 00 00 00 00 00 F.... ..........
    00 00 00 00 08 00 00 04 00 00 00 00 05 00 00 00 ................
    01 00 00 00 38 00 00 00 5F 5F 4C 49 4E 4B 45 44 ....8...__LINKED
    49 54 00 00 00 00 00 00 00 40 00 00 00 10 00 00 IT.......@......
    00 30 00 00 54 02 00 00 07 00 00 00 01 00 00 00 .0..T...........
    00 00 00 00 00 00 00 00 02 00 00 00 18 00 00 00 ................
    00 30 00 00 18 00 00 00 58 31 00 00 FC 00 00 00 .0......X1......
    0B 00 00 00 50 00 00 00 00 00 00 00 03 00 00 00 ....P...........
    03 00 00 00 08 00 00 00 0B 00 00 00 0D 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 20 31 00 00 0E 00 00 00 ........ 1......
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    0E 00 00 00 1C 00 00 00 0C 00 00 00 2F 75 73 72 ............/usr
    2F 6C 69 62 2F 64 79 6C 64 00 00 00 05 00 00 00 /lib/dyld.......
    50 00 00 00 01 00 00 00 10 00 00 00 00 00 00 00 P...............
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 6C 1C 00 00 00 00 00 00 00 00 00 00 ....l...........
    00 00 00 00 00 00 00 00 00 00 00 00 0C 00 00 00 ................
    34 00 00 00 18 00 00 00 02 00 00 00 00 00 01 00 4...............
    00 00 01 00 2F 75 73 72 2F 6C 69 62 2F 6C 69 62 ..../usr/lib/lib
    67 63 63 5F 73 2E 31 2E 64 79 6C 69 62 00 00 00 gcc_s.1.dylib...
    0C 00 00 00 34 00 00 00 18 00 00 00 02 00 00 00 ....4...........
    00 00 6F 00 00 00 01 00 2F 75 73 72 2F 6C 69 62 ..o...../usr/lib
    2F 6C 69 62 53 79 73 74 65 6D 2E 42 2E 64 79 6C /libSystem.B.dyl
    69 62 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ib..............
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    <snip> shorting message </snip>
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 6A 00 89 E5 ............j...
    83 E4 F0 83 EC 10 8B 5D 04 89 5C 24 00 8D 4D 08 .......]..\$..M.
    89 4C 24 04 83 C3 01 C1 E3 02 01 CB 89 5C 24 08 .L$..........\$.
    8B 03 83 C3 04 85 C0 75 F7 89 5C 24 0C E8 3D 01 .......u..\$..=.
    00 00 89 44 24 00 E8 55 13 00 00 F4 E8 00 00 00 ...D$..U........
    00 58 FF B0 5F 03 00 00 8B 80 63 03 00 00 FF E0 .X.._.....c.....
    E8 00 00 00 00 58 8B 80 53 03 00 00 FF E0 55 89 .....X..S.....U.
    E5 53 83 EC 34 E8 00 00 00 00 5B C7 45 F0 00 00 .S..4.....[.E...
    00 00 E9 E6 00 00 00 8B 45 F0 8B 55 0C 89 D1 29 ........E..U...)
    C1 89 C8 89 45 E0 83 7D E0 10 7E 07 C7 45 E0 10 ....E..}..~..E..
    00 00 00 8B 45 E0 89 45 EC C7 45 E8 00 00 00 00 ....E..E..E.....
    EB 26 8B 45 F0 03 45 E8 03 45 08 0F B6 00 0F B6 .&.E..E..E......
    C0 89 44 24 04 8D 83 9C 02 00 00 89 04 24 E8 F5 ..D$.........$..
    12 00 00 8D 45 E8 FF 00 8B 45 E8 3B 45 EC 7C D2 ....E....E.;E.|.
    EB 13 8D 83 A2 02 00 00 89 04 24 E8 D8 12 00 00 ..........$.....
    8D 45 E8 FF 00 83 7D E8 0F 7E E7 C7 45 E8 00 00 .E....}..~..E...
    00 00 EB 4D 8B 45 F0 03 45 E8 03 45 08 0F B6 00 ...M.E..E..E....
    3C 1F 76 21 8B 45 F0 03 45 E8 03 45 08 0F B6 00 <.v!.E..E..E....
    3C 7E 77 11 8B 45 F0 03 45 E8 03 45 08 0F B6 00 <~w..E..E..E....
    88 45 E7 EB 04 C6 45 E7 2E 0F B6 4D E7 88 4D F7 .E....E....M..M.
    0F BE 45 F7 89 04 24 E8 81 12 00 00 8D 45 E8 FF ..E...$......E..
    00 8B 45 E8 3B 45 EC 7C AB C7 04 24 0A 00 00 00 ..E.;E.|...$....
    E8 68 12 00 00 8B 55 EC 8D 45 F0 01 10 8B 45 F0 .h....U..E....E.
    3B 45 0C 0F 8C 0E FF FF FF 83 C4 34 5B C9 C3 55 ;E.........4[..U
    89 E5 53 83 EC 24 E8 00 00 00 00 5B 83 7D 08 02 ..S..$.....[.}..
    74 17 8B 45 0C 8B 00 89 44 24 04 8D 83 95 01 00 t..E....D$......
    00 89 04 24 E8 1F 12 00 00 8B 45 0C 83 C0 04 8B ...$......E.....
    00 89 44 24 04 8D 83 A7 01 00 00 89 04 24 E8 05 ..D$.........$..
    12 00 00 8B 45 0C 83 C0 04 8B 10 8D 83 BD 01 00 ....E...........
    00 89 44 24 04 89 14 24 E8 CD 11 00 00 89 45 EC ..D$...$......E.
    83 7D EC 00 75 26 8D 83 C0 01 00 00 89 04 24 E8 .}..u&........$.
    DE 11 00 00 C7 04 24 D0 07 00 00 E8 E1 11 00 00 ......$.........
    C7 04 24 01 00 00 00 E8 94 11 00 00 8D 83 D3 01 ..$.............
    00 00 89 04 24 E8 B8 11 00 00 C7 44 24 08 02 00 ....$......D$...
    00 00 C7 44 24 04 00 00 00 00 8B 45 EC 89 04 24 ...D$......E...$
    E8 84 11 00 00 8B 45 EC 89 04 24 E8 7E 11 00 00 ......E...$.~...
    89 45 E8 8B 45 E8 89 44 24 04 8D 83 DE 01 00 00 .E..E..D$.......
    89 04 24 E8 70 11 00 00 8B 45 EC 89 04 24 E8 74 ..$.p....E...$.t
    11 00 00 8B 45 E8 89 04 24 E8 55 11 00 00 89 45 ....E...$.U....E
    F0 83 7D F0 00 75 1A 8D 83 F7 01 00 00 89 04 24 ..}..u.........$
    E8 4D 11 00 00 C7 04 24 02 00 00 00 E8 0F 11 00 .M.....$........
    00 8B 55 E8 8B 45 EC 89 44 24 0C 89 54 24 08 C7 ..U..E..D$..T$..
    44 24 04 01 00 00 00 8B 45 F0 89 04 24 E8 FD 10 D$......E...$...
    00 00 89 45 F4 8B 45 E8 3B 45 F4 74 26 8D 83 04 ...E..E.;E.t&...
    02 00 00 89 04 24 E8 07 11 00 00 C7 04 24 D0 07 .....$.......$..
    00 00 E8 0A 11 00 00 C7 04 24 03 00 00 00 E8 BD .........$......
    10 00 00 8B 45 E8 89 44 24 04 8B 45 F0 89 04 24 ....E..D$..E...$
    E8 79 FD FF FF 8B 45 EC 89 04 24 E8 A5 10 00 00 .y....E...$.....
    8B 45 F0 89 04 24 E8 A9 10 00 00 B8 00 00 00 00 .E...$..........
    83 C4 24 5B C9 C3 25 30 32 58 20 00 20 20 20 00 ..$[..%02X .   .
    55 73 61 67 65 3A 0A 25 73 20 3C 66 69 6C 65 3E Usage:.%s <file>
    0A 00 6F 70 65 6E 69 6E 67 20 66 69 6C 65 20 25 ..opening file %
    73 20 2E 2E 2E 20 0A 00 72 62 00 45 72 72 6F 72 s ... ..rb.Error
    20 6F 70 65 6E 69 6E 67 20 66 69 6C 65 00 53 75  opening file.Su
    63 63 65 73 73 21 21 21 00 53 69 7A 65 20 6F 66 ccess!!!.Size of
    20 66 69 6C 65 20 25 6C 64 20 62 79 74 65 73 2E  file %ld bytes.
    0A 00 4D 65 6D 6F 72 79 20 65 72 72 6F 72 00 52 ..Memory error.R
    65 61 64 69 6E 67 20 65 72 72 6F 72 00 00 00 00 eading error....
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 10 00 00 00 10 E0 8F 08 10 E0 8F 00 10 00 00 ................
    0C 20 00 00 08 20 00 00 04 20 00 00 00 20 00 00 . ... ... ... ..
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    <snip> shorting message </snip>
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 ................
    F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 ................
    F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 ................
    F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 ................
    F4 F4 F4 F4 F4 F4 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    <snip> shorting message </snip>
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    02 00 00 00 1E 01 00 00 AC 1C 00 00 1B 00 00 00 ................
    1E 01 00 00 C0 1C 00 00 2E 00 00 00 0E 03 00 00 ................
    10 20 00 00 40 00 00 00 0F 03 00 00 0C 20 00 00 . ..@........ ..
    48 00 00 00 0F 03 00 00 08 20 00 00 50 00 00 00 H........ ..P...
    0F 03 00 00 00 20 00 00 5C 00 00 00 03 00 10 00 ..... ..\.......
    00 10 00 00 70 00 00 00 0F 03 00 00 04 20 00 00 ....p........ ..
    79 00 00 00 0F 01 00 00 CE 1C 00 00 88 00 00 00 y...............
    0F 01 00 00 DF 1D 00 00 8E 00 00 00 0F 01 00 00 ................
    6C 1C 00 00 94 00 00 00 01 00 01 02 00 00 00 00 l...............
    9A 00 00 00 01 00 01 02 00 00 00 00 A2 00 00 00 ................
    01 00 01 02 00 00 00 00 A9 00 00 00 01 00 01 02 ................
    00 00 00 00 B0 00 00 00 01 00 01 02 00 00 00 00 ................
    B6 00 00 00 01 00 01 02 00 00 00 00 BD 00 00 00 ................
    01 00 01 02 00 00 00 00 C4 00 00 00 01 00 01 02 ................
    00 00 00 00 CC 00 00 00 01 00 01 02 00 00 00 00 ................
    D4 00 00 00 01 00 01 02 00 00 00 00 DD 00 00 00 ................
    01 00 01 02 00 00 00 00 E3 00 00 00 01 00 01 02 ................
    00 00 00 00 EB 00 00 00 01 00 01 02 00 00 00 00 ................
    0B 00 00 00 0C 00 00 00 0D 00 00 00 0E 00 00 00 ................
    0F 00 00 00 10 00 00 00 11 00 00 00 12 00 00 00 ................
    13 00 00 00 14 00 00 00 15 00 00 00 16 00 00 00 ................
    00 00 00 40 17 00 00 00 20 00 64 79 6C 64 5F 73 ...@.... .dyld_s
    74 75 62 5F 62 69 6E 64 69 6E 67 5F 68 65 6C 70 tub_binding_help
    65 72 00 5F 5F 64 79 6C 64 5F 66 75 6E 63 5F 6C er.__dyld_func_l
    6F 6F 6B 75 70 00 64 79 6C 64 5F 5F 6D 61 63 68 ookup.dyld__mach
    5F 68 65 61 64 65 72 00 5F 4E 58 41 72 67 63 00 _header._NXArgc.
    5F 4E 58 41 72 67 76 00 5F 5F 5F 70 72 6F 67 6E _NXArgv.___progn
    61 6D 65 00 5F 5F 6D 68 5F 65 78 65 63 75 74 65 ame.__mh_execute
    5F 68 65 61 64 65 72 00 5F 65 6E 76 69 72 6F 6E _header._environ
    00 5F 66 70 72 69 6E 74 48 65 78 44 75 6D 70 00 ._fprintHexDump.
    5F 6D 61 69 6E 00 73 74 61 72 74 00 5F 65 78 69 _main.start._exi
    74 00 5F 66 63 6C 6F 73 65 00 5F 66 6F 70 65 6E t._fclose._fopen
    00 5F 66 72 65 61 64 00 5F 66 72 65 65 00 5F 66 ._fread._free._f
    73 65 65 6B 00 5F 66 74 65 6C 6C 00 5F 6D 61 6C seek._ftell._mal
    6C 6F 63 00 5F 70 72 69 6E 74 66 00 5F 70 75 74 loc._printf._put
    63 68 61 72 00 5F 70 75 74 73 00 5F 72 65 77 69 char._puts._rewi
    6E 64 00 5F 73 6C 65 65 70 24 55 4E 49 58 32 30 nd._sleep$UNIX20
    30 33 00 00                                     03..
    macbook-pro-15:Desktop woodshop2300$ 
    
     
  6. Kipman725

    Kipman725 When did I get a custom title!?!

    Joined:
    1 Nov 2004
    Posts:
    1,753
    Likes Received:
    0
    hmm using %X has partialy worked the output is now:
    [​IMG]
    so the first 3 bytes are correct and then it all goes funny with some of the bytes been preceeded by FFFFFF... the last byte is just garbage as I have acidently made my for loop go on one too long. So overall the right thing but some bytes are preceded by FFFFF.

    *oo lots of replies I didn't see I will act on those now so erm ignore this.

    Also I think the file legnth thing is garunteed to work only for bianry files, but this is a binary file so I'm fine :D
     
  7. Kipman725

    Kipman725 When did I get a custom title!?!

    Joined:
    1 Nov 2004
    Posts:
    1,753
    Likes Received:
    0
    woodshop I am in great debt to you that works perfectly I barley grasp some bits of it but I shall study it some more. Nice one on the well formated output and use of command line argument.

    using your example I have also found the problem in the orginal code which was using a signed char pointer (although I fail to understand how this breaks the program changing it to unsigned has fixed it).

    anyway this works: (not as nice as woodshops though)
    my formating is very different to yours woodshop but I find it easier to understand the code this way, is my indenting so non standard that others have difficulty reading it?

    **its for programing a parallel EEPROM thats going to be hooked upto my paraallel port with a programer I have yet to design. whoever programs 8bit micros in C is rearly silly as the asyembler is easy and far more effeciant, if you only have 1024 code words programing it in c is just maddness! in my veiw when you don't have an OS in the way asyembler is far easier aswell, although complex algorithms may be chalenging most work done on micros is not complex.
     
    Last edited: 3 May 2008
  8. woodshop

    woodshop UnSeenly

    Joined:
    14 Oct 2003
    Posts:
    1,408
    Likes Received:
    8
    formatting is just that formatting, what ever is easy for you.
    I choose that one since it matches the linux hexdump, tcpdump hex dump, and wireshark formatting so its makes it easy for me to do @ a glance comparisons.
     
  9. wyx087

    wyx087 Homeworld 3 is happening!!

    Joined:
    15 Aug 2007
    Posts:
    11,987
    Likes Received:
    706
    contragz in getting it to work.

    if you have yet to decide on a chip for programming EEPROM, may i suggest ATmega48? it's incredibly easy to use! and the compiler can easily change your C code into machine code and be written into the AVR.
     
  10. Kipman725

    Kipman725 When did I get a custom title!?!

    Joined:
    1 Nov 2004
    Posts:
    1,753
    Likes Received:
    0
    no lol you don't understand this is nothing to do with EEPROM memory as part of an 8bit microcontroller. I have laready got a serial programer for those and I2C EEPROMS. This is a programer for parallel EEPROM memory specificly the X28HC256P-90. This EEPROM contains the program for a computer based around a Z80 microproccessor (4MHz clock - 8bit data bus - 16bit registers - 16bit address bus - loads of addressing modes). The test file I have been using is infact the object code for an 8bit binary counter using an I/O port consiting of an octal latch and using the D register. Even at 17bytes I found entering the program with dip switches too error prone so I decided to construct a progrmer. I haven't finalised the memory configuration of the computer yet so I may end up with more rom memory that needs burning, if so I will modify hardware/software apropriatly.


    Anyway I succefully got the filke to output to the parallel port so here is a video:
     
    Last edited: 4 May 2008
  11. capnPedro

    capnPedro Hacker. Maker. Engineer.

    Joined:
    11 Apr 2007
    Posts:
    4,381
    Likes Received:
    241
    [YOUTUBE ]0n1ziiwwA98[/ YOUTUBE]
    Just need the video ID.
     
  12. woodshop

    woodshop UnSeenly

    Joined:
    14 Oct 2003
    Posts:
    1,408
    Likes Received:
    8
    ahhh.. now i see the reasoning behind your output format.. you using it almost like a progress bar it seams.. though i can't really read the screen to be sure..

    btw is that Bloodshed i see? Great thing if you stuck on Windows..
     
  13. Kipman725

    Kipman725 When did I get a custom title!?!

    Joined:
    1 Nov 2004
    Posts:
    1,753
    Likes Received:
    0
    Yep :D

    bloodshed is nice, my main operting system is xp but I plan on changing that over the summer, I have been running various linux distros since one of the first releases of vector linux. Certinaly using the parallel port is far harder on windows than linux as I'm having to use big DLL somone made wheras in linux I could just temporerily give a program the right to access the parallel port :p

    is there anthing like bloodshed for linux as whenever I have wrote programs under linux I just use GCC but a nice frontend reduces typing and cliking increasing speed of programing.
     
  14. woodshop

    woodshop UnSeenly

    Joined:
    14 Oct 2003
    Posts:
    1,408
    Likes Received:
    8
    I still mainly do Java work, as such i'm in love with NetBeans IDE. new with Version 6+ is that C/C++ is no longer a plugin.. its usability is comparable to Bloodshed but WAY larger running footprint, and still no where near as nice as the Java side of it in terms of code completion and auto import/include `ing.. I use it mainly for consistence and SVN integration.
     

Share This Page