一、直接上代码,我这里是读显示器edid的内容,read_bin_file.c
#include
#include
#include"edid.h"
typedef unsigned char u8;
typedef unsigned long int u32;
/*************************************************************************************
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: 03 50 08 21 01 13 01 00 00 00 00 01 01 00 00 00
10: 01 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20: 01 17 00 6f ff 00 00 00 10 00 ff 0f ff 02 19 0f
30: 00 00 19 0b 00 00 02 03 00 00 09 00 00 0c 00 0a
40: 00 0c 00 0c 00 07 00 0a 00 0c 00 00 00 7f 00 03
50: 06 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
70: 00 cf 03 00 28 00 0c 1c 80 19 00 34 12 00 71 00
80: 10 50 1f ac 00 40 00 20 40 00 00 00 00 00 00 00
90: 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*************************************************************************************/
//TCL monitor
unsigned char edid[255]={
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x50, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x12, 0x13, 0x01, 0x03, 0x81, 0x52, 0x2e, 0x78, 0x0b, 0xd9, 0xb0, 0xa3, 0x57, 0x49, 0x9c, 0x25,
0x11, 0x49, 0x4b, 0xa9, 0xcf, 0x00, 0x95, 0x00, 0xb3, 0x00, 0x81, 0xc0, 0x81, 0x00, 0x81, 0x40,
0x81, 0x80, 0xa9, 0x40, 0xd1, 0xc0, 0x1b, 0x21, 0x50, 0xa0, 0x51, 0x00, 0x1e, 0x30, 0x48, 0x88,
0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x1f, 0x00, 0x80, 0x51, 0x00, 0x1e, 0x30,
0x40, 0x80, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc,
0x00, 0x54, 0x43, 0x4c, 0x4d, 0x53, 0x36, 0x38, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x02,
0x02, 0x03, 0x20, 0xf1, 0x4d, 0x05, 0x02, 0x03, 0x04, 0x07, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x1f, 0x23, 0x09, 0x57, 0x07, 0x83, 0x01, 0x00, 0x00, 0x65, 0x03, 0x0c, 0x00, 0x10, 0x00,
0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0x65, 0xcc, 0x21, 0x00,
0x00, 0x18, 0x01, 0x1d, 0x00, 0xbc, 0x52, 0xd0, 0x1e, 0x20, 0xb8, 0x28, 0x55, 0x40, 0x32, 0xcc,
0x31, 0x00, 0x00, 0x1e, 0x01, 0x1d, 0x80, 0xd0, 0x72, 0x1c, 0x16, 0x20, 0x10, 0x2c, 0x25, 0x80,
0x32, 0xcc, 0x31, 0x00, 0x00, 0x9e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e,
0x96, 0x00, 0x32, 0xcc, 0x31, 0x00, 0x00, 0x18, 0x8c, 0x0a, 0xd0, 0x90, 0x20, 0x40, 0x31, 0x20,
0x0c, 0x40, 0x55, 0x00, 0x32, 0xcc, 0x31, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14
};
u32 GetBinSize(char *filename)
{
u32 siz = 0;
FILE *fp = fopen(filename, "rb");
if (fp)
{
fseek(fp, 0, SEEK_END);
siz = ftell(fp);
fclose(fp);
}
printf("\nfilename=%s,size=%d \n",filename,siz);
return siz;
}
void read_bin(char *path, u8 *buf, u32 size)
{
FILE *infile;
if((infile=fopen(path,"rb"))==NULL)
{
printf( "\nCan not open the path: %s \n", path);
exit(-1);
}
fread(buf, sizeof(u8), size, infile);
fclose(infile);
}
int main(){
struct fb_videomode *mode, *m;
unsigned char *block;
int num = 0, i, first = 1,size=0;
unsigned char edid_data[1024];
size=GetBinSize("edid.bin");
read_bin("edid.bin", edid_data,size);
for(i=0;i
二、执行结果
三、用notepad查看edid.bin
四、用notepad查看和用程序读结果一样,测试ok。