vc生成MIF文件,ROM使用
1 #include <stdio.h> 2 #include <string.h> 3 #include"stdlib.h" 4 5 unsigned char src[640*481]; 6 unsigned char dst[640*481]; 7 /*-- 文字: 1 --*/ 8 /*-- 微软雅黑24; 此字体下对应的点阵为:宽x高=20x42 --*/ 9 /*-- 宽度不是8的倍数,现调整为:宽度x高度=24x42 --*/ 10 unsigned char number1[]= 11 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 12 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x0F,0xFC, 13 0x00,0x3F,0xFC,0x00,0x3F,0xFC,0x00,0x3F,0xFC,0x00,0x3D,0xFC,0x00,0x01,0xFC,0x00, 14 0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01, 15 0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC, 16 0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x3F,0xFF,0xE0,0x3F,0xFF,0xE0, 17 0x3F,0xFF,0xE0,0x3F,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 18 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 19 main() 20 { 21 FILE *fp; 22 unsigned long i,j,m; 23 int c; 24 unsigned char ch; 25 26 if ((fp=fopen("test.mif","wb+"))==NULL)//打开MIF源文件 27 { /* 以只读方式打开文件1 */ 28 printf("cannot open file1\n"); 29 exit(0); 30 //return(0); 31 } 32 33 fprintf(fp,"WIDTH=%d;\n",1); //写入mif 存储数据宽度 34 35 fprintf(fp,"DEPTH=%d;\n",262144); //写入mif 存储数据总量 36 37 fprintf(fp,"\n"); 38 39 fprintf(fp,"ADDRESS_RADIX=DEC;\n"); //十进制表示地址 40 41 fprintf(fp,"DATA_RADIX=HEX;\n"); //十六进制表示数据 42 43 fprintf(fp,"CONTENT BEGIN;\n"); //内容开始 44 45 fprintf(fp,"\n"); 46 47 i=0; 48 m=0; 49 50 //for(i=0;i<512;i++) 51 for(j=0;j<24*42/8;j++) 52 { 53 for(i=0;i<8;i++) 54 { 55 if((number1[j]>>i)&0x01==1) 56 fprintf(fp,"\t%d\t:\t%x;\n",m,1); 57 else 58 fprintf(fp,"\t%d\t:\t%x;\n",m,0); 59 m++; 60 } 61 } 62 i,j, 63 //fseek(fp, 0, SEEK_SET); 64 fprintf(fp,"\n"); 65 fprintf(fp,"END;"); 66 fclose(fp); 67 }
1、MIF文件格式
http://quartushelp.altera.com/13.0/mergedProjects/reference/glossary/def_mif.htm
% multiple-line comment
multiple-line comment %
-- single-line comment
DEPTH = 32; -- The size of memory in words
WIDTH = 8; -- The size of data in bits
ADDRESS_RADIX = HEX; -- The radix for address values
DATA_RADIX = BIN; -- The radix for data values
CONTENT -- start of (address : data pairs)
BEGIN
00 : 00000000; -- memory address : data
01 : 00000001;
02 : 00000010;
03 : 00000011;
04 : 00000100;
05 : 00000101;
06 : 00000110;
07 : 00000111;
08 : 00001000;
09 : 00001001;
0A : 00001010;
0B : 00001011;
0C : 00001100;
END;
Address : Data Pairs Syntax Rules |
Definition |
Example |
A : D |
Addr[A] = D |
2 : 4 |
[A0..A1] : D |
Addr[A0] to [A1] contain data D |
[0..7] : 6 |
[A0..A1] : D0 D1 |
Addr[A0] = D0, Addr[A0+3] = D1, until A0+n = A1 |
[0..7] : 5 6 |
A : D0 D1 D2 |
Addr[A] = D0, |
2 : 4 5 6 |
2、VC生成代码
1 #include <stdio.h> 2 #include <string.h> 3 #include"stdlib.h" 4 5 unsigned char src[640*481]; 6 unsigned char dst[640*481]; 7 /*-- 文字: 1 --*/ 8 /*-- 微软雅黑24; 此字体下对应的点阵为:宽x高=20x42 --*/ 9 /*-- 宽度不是8的倍数,现调整为:宽度x高度=24x42 --*/ 10 unsigned char number1[]= 11 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 12 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x0F,0xFC, 13 0x00,0x3F,0xFC,0x00,0x3F,0xFC,0x00,0x3F,0xFC,0x00,0x3D,0xFC,0x00,0x01,0xFC,0x00, 14 0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01, 15 0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC, 16 0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x3F,0xFF,0xE0,0x3F,0xFF,0xE0, 17 0x3F,0xFF,0xE0,0x3F,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 18 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 19 main() 20 { 21 FILE *fp; 22 unsigned long i,j,m; 23 int c; 24 unsigned char ch; 25 26 if ((fp=fopen("test.mif","wb+"))==NULL)//打开MIF源文件 27 { /* 以只读方式打开文件1 */ 28 printf("cannot open file1\n"); 29 exit(0); 30 //return(0); 31 } 32 33 fprintf(fp,"WIDTH=%d;\n",1); //写入mif 存储数据宽度 34 35 fprintf(fp,"DEPTH=%d;\n",262144); //写入mif 存储数据总量 36 37 fprintf(fp,"\n"); 38 39 fprintf(fp,"ADDRESS_RADIX=DEC;\n"); //十进制表示地址 40 41 fprintf(fp,"DATA_RADIX=HEX;\n"); //十六进制表示数据 42 43 fprintf(fp,"CONTENT BEGIN;\n"); //内容开始 44 45 fprintf(fp,"\n"); 46 47 i=0; 48 m=0; 49 50 //for(i=0;i<512;i++) 51 for(j=0;j<24*42/8;j++) 52 { 53 for(i=0;i<8;i++) 54 { 55 if((number1[j]>>i)&0x01==1) 56 fprintf(fp,"\t%d\t:\t%x;\n",m,1); 57 else 58 fprintf(fp,"\t%d\t:\t%x;\n",m,0); 59 m++; 60 } 61 } 62 i,j, 63 //fseek(fp, 0, SEEK_SET); 64 fprintf(fp,"\n"); 65 fprintf(fp,"END;"); 66 fclose(fp); 67 }
1 #include <stdio.h> 2 #include <string.h> 3 #include"stdlib.h" 4 5 unsigned char src[640*481]; 6 unsigned char dst[640*481]; 7 /*-- 文字: 1 --*/ 8 /*-- 微软雅黑24; 此字体下对应的点阵为:宽x高=20x42 --*/ 9 /*-- 宽度不是8的倍数,现调整为:宽度x高度=24x42 --*/ 10 unsigned char number1[]= 11 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 12 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x0F,0xFC, 13 0x00,0x3F,0xFC,0x00,0x3F,0xFC,0x00,0x3F,0xFC,0x00,0x3D,0xFC,0x00,0x01,0xFC,0x00, 14 0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01, 15 0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC, 16 0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x3F,0xFF,0xE0,0x3F,0xFF,0xE0, 17 0x3F,0xFF,0xE0,0x3F,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 18 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 19 main() 20 { 21 FILE *fp; 22 unsigned long i,j,m; 23 int c; 24 unsigned char ch; 25 26 if ((fp=fopen("test.mif","wb+"))==NULL)//打开MIF源文件 27 { /* 以只读方式打开文件1 */ 28 printf("cannot open file1\n"); 29 exit(0); 30 //return(0); 31 } 32 33 fprintf(fp,"WIDTH=%d;\n",1); //写入mif 存储数据宽度 34 35 fprintf(fp,"DEPTH=%d;\n",262144); //写入mif 存储数据总量 36 37 fprintf(fp,"\n"); 38 39 fprintf(fp,"ADDRESS_RADIX=DEC;\n"); //十进制表示地址 40 41 fprintf(fp,"DATA_RADIX=HEX;\n"); //十六进制表示数据 42 43 fprintf(fp,"CONTENT BEGIN;\n"); //内容开始 44 45 fprintf(fp,"\n"); 46 47 i=0; 48 m=0; 49 50 //for(i=0;i<512;i++) 51 for(j=0;j<24*42/8;j++) 52 { 53 for(i=0;i<8;i++) 54 { 55 if(((number1[j]<<i)&0x80)==0x80) 56 fprintf(fp,"\t%d\t:\t%x;\n",m,1); 57 else 58 fprintf(fp,"\t%d\t:\t%x;\n",m,0); 59 m++; 60 } 61 } 62 i,j, 63 //fseek(fp, 0, SEEK_SET); 64 fprintf(fp,"\n"); 65 fprintf(fp,"END;"); 66 fclose(fp); 67 }
3、ROM的建立
tool---megwizard ----creat----memory compiler ------ROM-1PORT-----在 mif init选项中添加 mif文件
4、注意事项
位宽 深度的匹配,,,此例子为vc写入的char型数据的0和1即 FPGA可以认为是二进制的,即ROM的位宽为1位