1. 開啟"BlueFlash"工具.
2. 使用滑鼠按下"Start Processor",在按"Dump".
3. 可以修改存檔名稱,如無修改就按下"存檔".
4. 之後開始從開發平台上Dump出燒錄檔.
5. 最後產生出xxx.xdv和xxx.xpv燒錄檔.
#include <stdio.h>
int main()
{
#define A 1
#define C 1
#define E 1
#if A //true
printf("HelloWorle-1\n");
#endif
#if B //false
printf("HelloWorle-2\n");
#endif
#if defined(C) //true
printf("HelloWorle-3\n");
#endif
#if defined(D) //false
printf("HelloWorle-4\n");
#endif
#if !defined(E) //true
printf("HelloWorle-5\n");
#endif
#if !defined(F) //false
printf("HelloWorle-6\n");
#endif
return 0;
}
結果:
#if #if defined(x) #if !defined(x) 結尾都要加上#endif,由上述的程式範例可以看到反白處都是編譯器不會被編譯到的程式碼.
當#if #if defined(x) #if !defined(x)的判斷式沒有被#define宣告,就為"0",反之當被#define宣告為為"1"時,編譯器就會被編譯到判斷式內的程式碼.
#include <stdio.h>
#include <stdlib.h>
char hex2ascii(char Number2)
{
char outtxt;
switch(Number2)
{
case 0x0:
outtxt = '0';
break;
case 0x1:
outtxt = '1';
break;
case 0x2:
outtxt = '2';
break;
case 0x3:
outtxt = '3';
break;
case 0x4:
outtxt = '4';
break;
case 0x5:
outtxt = '5';
break;
case 0x6:
outtxt = '6';
break;
case 0x7:
outtxt = '7';
break;
case 0x8:
outtxt = '8';
break;
case 0x9:
outtxt = '9';
break;
case 0xA:
outtxt = 'A';
break;
case 0xB:
outtxt = 'B';
break;
case 0xC:
outtxt = 'C';
break;
case 0xD:
outtxt = 'D';
break;
case 0xE:
outtxt = 'E';
break;
case 0xF:
outtxt = 'F';
break;
default:
printf("?");
break;
}
return outtxt;
}
char ascii2hex(char Number1)
{
char chbit;
switch(Number1)
{
case '0':
chbit = 0x0;
break;
case '1':
chbit = 0x1;
break;
case '2':
chbit = 0x2;
break;
case '3':
chbit = 0x3;
break;
case '4':
chbit = 0x4;
break;
case '5':
chbit = 0x5;
break;
case '6':
chbit = 0x6;
break;
case '7':
chbit = 0x7;
break;
case '8':
chbit = 0x8;
break;
case '9':
chbit = 0x9;
break;
case 'A':
chbit = 0xA;
break;
case 'B':
chbit = 0xB;
break;
case 'C':
chbit = 0xC;
break;
case 'D':
chbit = 0xD;
break;
case 'E':
chbit = 0xE;
break;
case 'F':
chbit = 0xF;
break;
case 'a':
chbit = 0xA;
break;
case 'b':
chbit = 0xB;
break;
case 'c':
chbit = 0xC;
break;
case 'd':
chbit = 0xD;
break;
case 'e':
chbit = 0xE;
break;
case 'f':
chbit = 0xF;
break;
default:
printf("?");
break;
}
return chbit;
}
int main(void)
{
FILE *fs,*fd;
char sfilename[20],dfilename[20];
char data;
char word8[8];
char conversion[10][2]; //ADC0 ADC1
unsigned short outword = 0;
int adc0=0,adc1=0;
char outputtxt = 0;
char checkbit = 0;
char buffer1[5] = {0,0,0,0,0};
char buffer2[5] = {0,0,0,0,0};
int filepointer;
int sdatacount = 0;
printf("Output source file name:");
scanf("%s",dfilename);
if((fd=fopen(dfilename,"w"))==NULL)
{
printf("\nObject file unable to open!");
system("PAUSE");
return 0;
}
while(1)
{
printf("\nInput source file name:");
scanf("%s",sfilename);
if((fs=fopen(sfilename,"r"))==NULL)
{
printf("\nSource file unable to open!");
fclose(fd);
system("PAUSE");
return 0;
}
while((data=fgetc(fs))!=EOF) //read source file
{
int x=0x78;
if(x != (x & data))
{
printf("%c",data);
}
else
{
printf("%c",data); //'x'
*(word8+0) = fgetc(fs);
printf("%c",*(word8+0));
*(word8+1) = fgetc(fs);
printf("%c",*(word8+1));
*(word8+2) = fgetc(fs);
printf("%c",*(word8+2));
*(word8+3) = fgetc(fs);
printf("%c",*(word8+3));
*(word8+4) = fgetc(fs);
printf("%c",*(word8+4));
*(word8+5) = fgetc(fs);
printf("%c",*(word8+5));
*(word8+6) = fgetc(fs);
printf("%c",*(word8+6));
*(word8+7) = fgetc(fs);
printf("%c",*(word8+7));
checkbit = ascii2hex(*(word8+7));
if(adc0<10) //to array
{
*(*(conversion+adc0)+(adc1+0)) = checkbit & 0x1; //bit_0
checkbit >>= 1;
*(*(conversion+adc0)+(adc1+1)) = checkbit & 0x1; //bit_1
adc1 = 0;
adc0++;
}
sdatacount++;
}
if(adc0==10) //move array data
{
adc0 = 0;
if((sdatacount > 40) && (sdatacount < 1321)) //taken out the data(1280)
{
//to object DEC file
outword = *(*(conversion+0)+1) & 0x1; //ADC1
outword <<= 1;
outword = outword | (*(*(conversion+1)+1) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+2)+1) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+3)+1) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+4)+1) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+5)+1) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+6)+1) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+7)+1) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+8)+1) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+9)+1) & 0x1);
itoa(outword,buffer1,10); //numerical value to character string
fseek(fd,filepointer,SEEK_SET); //shift file pointer
fputc(*(buffer1+0),fd); //word to new file
fputc(*(buffer1+1),fd);
fputc(*(buffer1+2),fd);
fputc(*(buffer1+3),fd);
fputc(0x09,fd); //Tab
outword = *(*(conversion+0)+0) & 0x1; //ADC0
outword <<= 1;
outword = outword | (*(*(conversion+1)+0) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+2)+0) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+3)+0) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+4)+0) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+5)+0) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+6)+0) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+7)+0) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+8)+0) & 0x1);
outword <<= 1;
outword = outword | (*(*(conversion+9)+0) & 0x1);
itoa(outword,buffer2,10); //numerical value to character string
fputc(*(buffer2+0),fd); //word to new file
fputc(*(buffer2+1),fd);
fputc(*(buffer2+2),fd);
fputc(*(buffer2+3),fd);
fputc(0x0A,fd); //line feed
*(buffer1+0) = 0; //clean buffer
*(buffer1+1) = 0;
*(buffer1+2) = 0;
*(buffer1+3) = 0;
*(buffer2+0) = 0;
*(buffer2+1) = 0;
*(buffer2+2) = 0;
*(buffer2+3) = 0;
}
}
filepointer = ftell(fd); //read file pointer
}
filepointer = ftell(fd); //read file pointer
fclose(fs);
sdatacount = 0;
}
fclose(fd);
printf("\nCopy OK!");
system("PAUSE");
return 0;
}*********************************