Verilog $Scannf 使用小结

来源:互联网 发布:蔬菜网络销售 编辑:程序博客网 时间:2024/05/22 11:37

Here is an example:

parameter IR500_CURRENT = "0b00000000000";parameter CURRENT_MODE = "0b0";reg [95:0] IR_CUR;reg [7:0] CUR_MOD;reg [20:0] ir_current;reg cur_mode;integer i,j;supply0 GND;supply1 VCC; initial  begin  IR_CUR= IR500_CURRENT;   CUR_MOD = CURRENT_MODE;  i=$sscanf(IR_CUR, "%b",ir_current);  j=$sscanf(CUR_MOD, "%b",cur_mode); end

The IR_CUR can be anything like binary string...

we can change the formate, based on the input parameter, like we can even use :"0b%b".

Here I only wanto get the binary part.

So, the width of IR_CUR should be [(length-2)*8-1:0] =>[95;0];

Onther way :

function [10:1] str2bin_12 (input [(12+2)*8-1:0] binstr);   integer i, j;   reg [1:8] ch;   begin      for (i=12; i>=1; i=i-1)      begin      for (j=1; j<=8; j=j+1)         ch[j] = binstr[i*8-j];      case (ch)         "0" : str2bin_12[i] = 1'b0;         "1" : str2bin_12[i] = 1'b1;         default: str2bin_12[i] = 1'bx;      endcase      end    endendfunctionwire [11:0] ir_current = str2bin_12(IR500_CURRENT);


 

 

 

0 0
原创粉丝点击