Easwar
Joined: 27 Oct 2009 Posts: 1 Location: India
|
27 Oct 2009 6:49 Re: bmp to hex tool for ks0108 graphic lcd |
|
|
|
|
You can use this code for converting BMP to Hex
| Code: |
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#define HEXFILE1 "mono.bmp" //Use ur bmp file here
#define OUTPUTFILE "hex.txt" // Ur output file
#define READ_PLUS_MODE "rb"
#define ERROR_FILE_OPEN -1
#define ERROR_FSEEK -2
#define ERROR_FREAD -3
#define ERROR_FWRITE -4
union
{
unsigned char readdata[4];
unsigned int readint;
}p;
int main()
{
FILE *fp, *dp;
int rwsize, ret, rp, i;
dp = fopen(OUTPUTFILE, "w+");
if(dp == NULL) // Checks whether the file is present
{
printf("\nOutput File\n");
return ERROR_FILE_OPEN;
}
fp = fopen(HEXFILE1,READ_PLUS_MODE);
if(fp == NULL)
{
printf("\nInput File\n");
fclose(dp);
return ERROR_FILE_OPEN;
}
ret = fseek(fp, 0, SEEK_END);
if(ret != 0)
{
printf("\nSeek End\n");
fclose(dp);
fclose(fp);
return ERROR_FSEEK;
}
rwsize = ftell(fp);
printf( "file size is %d\n",rwsize);
////////////////////////////////////////////////////////
if(ret != 0)
{
printf("\nSeek Set\n");
fclose(dp);
fclose(fp);
return ERROR_FSEEK;
}
////////////////////////////////////////////////////////
for (i=0;i<(rwsize-0x3E)/4; i++)
{
ret = fread(&p.readint,1,4,fp);
fprintf (dp, "0x%02X%02X%02X%02X, ", p.readdata[0],p.readdata[1],p.readdata[2],p.readdata[3]);
if(i%4==6) fprintf(dp, "\n");
}
// ret = fwrite(readdata, 1, rwsize, dp); //
fclose(fp);
fclose(dp);
return 0;
}
|
|
|