第一步,做出实体芯片。
module minicpu(clk, reset, run, in, cs, pcout, irout, qtop, abus, dbus, out);
input clk,reset,run;
input [15:0] in;
output [1:0] cs;
output [15:0] irout, qtop, dbus, out;
output [11:0] pcout, abus;
wire [15:0] qnext, ramout, aluout;
reg [11:0] abus;
reg halt, jump, pcinc, push, pop, thru, qthru, dbus2qtop, dbus2ram, dbus2obuf, ir2dbus, qtop2dbus, alu2dbus, ram2dbus, in2dbus;
reg pop2, ir2abus, qtop2abus, qnext2abus;
reg [11:0] pcout, pcnext;
reg [15:0] out;
statef statef0(.clk(clk),.reset(reset),.run(run),.halt(halt),.cs(cs));
stackm stackm0(.clk(clk),.reset(reset),.load(dbus2qtop),.push(push),.pop(pop),.pop2(pop2),.thru(qthru),.d(dbus),.dthru(ramout),.qtop(qtop),.qnext(qnext));
alu alu0(.a(qtop),.b(qnext),.f(irout[4:0]),.s(aluout));
dpram #(16,10,1024) dpram0(.clk(clk),.load1(dbus2ram),.addr1(abus),.addr2(pcnext),.d1(dbus),.q1(ramout),.q2(irout));
物理上是这样的
#!/usr/bin/perl -W
//********
*********//
print "*** LABEL LIST ***\n";
foreach $l (sort(keys(%label))){
printf "%-8s%03X\n",$l,$label{$l};
}
$addr=0;
print "\n*** MACHINE PROGRAM ***\n";
foreach (@source){
$line = $_;
s/\w+://;
if(/PUSHI\s+(-?\d+)/){
printf "%03X:%04X\t$line",$addr++,$MCODE{PUSHI}+($1&0xfff);
} elsif(/(PUSH|POP|JMP|JZ|JNZ)\s+(\w+)/){
printf "%03X:%04X\t$line",$addr++,$MCODE{$1}+$label{$2};
}elsif(/(-?\d+)/){
printf "%03X:%04X\t$line",$addr++,$1&0xffff;
} elsif(/([A-Z]+)/){
printf "%03X:%04X\t$line",$addr++,$MCODE{$1};
} else {
print "\t\t$line";
}
}
%{
#include
%}
%union {char *s; int n;}
%token
NAME NUMBER%destructor { free($$); } NAME NUMBER
%token
IF WHILE DO %type
if0 %token GOTO ELSE INT IN OUT HALT
...
...
%%
int yyerror(char *s){ printf("%s\n",s); }
int main(){ yyparse(); }
%{
#include
#include "y.tab.h"
int n=0;
%}
...
...
while {yylval.n=++n;return(WHILE);}
[0-9]+ {yylval.s=strdup(yytext);return(NUMBER);}
[a-zA-Z][a-zA-Z0-9]* {yylval.s=strdup(yytext);return(NAME);}
. {return(yytext[0]);}
%%
int yywrap(){ return(1);}
%{
start: JK start
nop
sdal 32
sdah 0
datp
loop: ting
inl
ting
inh
jend cxcute
nop
jmp loop
inc
excute: call 32
nop
jmp start
nop
uint SPI_RW(uint uchar)
{
uint bit_ctr;
for(bit_ctr=0;bit_ctr<8;bit_ctr++) // output 8-bit
{
MOSI = (uchar & 0x80); // output 'uchar', MSB to MOSI
uchar = (uchar << 1); // shift next bit into MSB..
SCK = 1; // Set SCK high..
uchar |= MISO; // capture current MISO bit
SCK = 0; // ..then set SCK low again
}
return(uchar); // return read uchar
}
化学,光学,半导体物理,等等就光刻胶涂胶的方式就够你研究一辈子了
其实,21ic论坛的一位道友曾经尝试过制作51单片机,接下来欣赏网友一路向北lm的制作过程:
声明:
推荐阅读▼
硬件精选文章
EMC相关文章
电子元器件
后台回复“加群”,管理员拉你加入同行技术交流群。