电子说
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));
物理上是这样的
然后此时才刚刚开始。 继续生成电路网表,时序收敛,如果不对继续返回上述流程继续调试。 前置:Synopsys回顾一下
最后不能忘记出片的时候 焚香沐浴更衣,朝南拜三拜,祈祷不会有大问题。
#!/usr/bin/perl -W
//********
*********//
print "*** LABEL LIST *** ";
foreach $l (sort(keys(%label))){
printf "%-8s%03X ",$l,$label{$l};
}
$addr=0;
print " *** MACHINE PROGRAM *** ";
foreach (@source){
$line = $_;
s/w+://;
if(/PUSHIs+(-?d+)/){
printf "%03X:%04X $line",$addr++,$MCODE{PUSHI}+($1&0xfff);
} elsif(/(PUSH|POP|JMP|JZ|JNZ)s+(w+)/){
printf "%03X:%04X $line",$addr++,$MCODE{$1}+$label{$2};
}elsif(/(-?d+)/){
printf "%03X:%04X $line",$addr++,$1&0xffff;
} elsif(/([A-Z]+)/){
printf "%03X:%04X $line",$addr++,$MCODE{$1};
} else {
print " $line";
}
}
编译器 BISON和FLEX(把高级语言转换成汇编语言) 前置:编译原理
终于可以固化进ROM可以跑程序了,你还需要一段小型的开启代码(bootloader)%{
%}
%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 ",s); }
int main(){ yyparse(); }
%{
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
拿着含辛茹苦的板子还需要配置最小系统以及外围器件double KalmanFilter(const double ResrcData,
double ProcessNiose_Q,double MeasureNoise_R,double InitialPrediction)
{
double R = MeasureNoise_R;
double Q = ProcessNiose_Q;
static double x_last;
double x_mid = x_last;
double x_now;
static double p_last;
double p_mid ;
double p_now;
double kg;
x_mid=x_last; //x_last=x(k-1|k-1),x_mid=x(k|k-1)
p_mid=p_last+Q; //p_mid=p(k|k-1),p_last=p(k-1|k-1),Q=噪声
kg=p_mid/(p_mid+R); //kg为kalman filter,R为噪声
x_now=x_mid+kg*(ResrcData-x_mid);//估计出的最优值
p_now=(1-kg)*p_mid;//最优值对应的covariance
p_last = p_now; //更新covariance值
x_last = x_now; //更新系统状态值
return x_now;
}
如果有信号传输
RF天线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
}
责任编辑:xj
原文标题:从零造单片机需要哪些知识?
文章出处:【微信公众号:嵌入式ARM】欢迎添加关注!文章转载请注明出处。
全部0条评论
快来发表一下你的评论吧 !