sc_8bit_updowncounter.cpp
来自「在SystemC下编的fibonicii 的程序」· C++ 代码 · 共 47 行
CPP
47 行
// All systemc modules should include systemc.h header file
#include <systemc.h>
// up_down_counter is module name
SC_MODULE (up_down_counter){
// input ports
sc_in <bool> clk; // clock input of the design
sc_in <bool> reset; // active high, synchronous Reset input
sc_in <bool> enable; // active high enable signal for counter
sc_in <bool> up_down; // up/down function select
// output ports
sc_out <sc_uint<8>> counter_out; // 8 bit vector output of the counter
// local variables here
sc_uint<8> count;
// code starts here
// below function implements actual counter logic
void counter(){
// at every rising edge of clock, we check if reset is active
// if active, we load the counter output with 8 bit 'b00000000'
if (reset.read() == 1){
count = 0;
}
// if enable is active, then we enable the counting
else if (enable.read() == 1){
if (up_down.read() == 1){
count = count + 1;
}
else {
count = count - 1;
}
counter_out.write(count);
}
} // End of function counter
// module constructor
SC_CTOR (up_down_counter){
SC_METHOD (counter);
sensitive << reset;
sensitive << clk.pos();
} // End of constructor
}; // End of module up_down_counter
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?