Guest
I have wrote the following code in verilog (using the reading_dna.vhd
file on the xilinx site) to run the picoblaze code that I found
online. I synthesized the code, produced, and send a .bit using ISE
10.1 to the Spartan 3an, however, the LCD screen doesn't display
anything. Can someone run this and check if there is something
wrong ?
module lcdtest(lcd_d,
lcd_rs,
lcd_rw,
lcd_e,
j2_30,
j2_26,
j2_22,
j2_14,
clk);
input clk; // 50MHz clock
output reg [7:0] lcd_d ; //
lcd output
output reg lcd_rs;
output reg lcd_rw;
output reg lcd_e;
output j2_30;
output j2_26;
output j2_22;
output j2_14;
wire [9:0] address; // wires to connect uC
address lines
to ROM
wire [17:0] instruction; // wires to connect uC data
lines,
to ROM
wire [7:0] out_port; // wires to connect uC output
port
to the LED flipflops
wire [7:0] port_id;
wire write_strobe;
wire read_strobe;
wire interrupt;
wire interrupt_ack;
wire reset = 0;
wire lcd_rw_control;
wire [7:0] lcd_output_data;
//instantiate the picoblaze mC
kcpsm3 mcu( address, instruction, port_id, write_strobe, out_port,
read_strobe, in_port, interrupt, interrupt_ack, reset, clk );
//instantiate the program rom
lcd rom(address, instruction, clk );
always @ (posedge clk)
begin
/
*----------------------------------------------------------------------------------------------------------------------------------
-- LCD interface
----------------------------------------------------------------------------------------------------------------------------------
--
-- The LCD will be accessed using the 8-bit mode.
-- lcd_rw is '1' for read and '0' for write */
// 8-bit LCD data output address 40 hex.
if (port_id[6])
begin
if(lcd_rw)
lcd_d <= out_port;
else
lcd_d <= 8'bz; // -- use read/write control
to enable output
buffers.
end
//-- LCD controls at address 20 hex.
if (port_id[5])
begin
lcd_rs <= out_port[2];
lcd_rw <= out_port[1]; //Control of read and write signal
lcd_e <= out_port[0];
end
end
endmodule
///////////////////////////////////////////////////////////////////////////////////////////
The .psm file that I complied can be found online, but I will include
it here:
http://forums.xilinx.com/xlnx/board/message?board.id=PicoBlaze&thread...
;========================================================================
CONSTANT BIN2BCD_SCRATCHPAD, 24 ; change this to your preferred
location
CONSTANT MY_OUTPUT_PORT, 00 ; just for the usage example
ADDRESS 000
usage_example:
LOAD s0, D2
STORE s0, 24 ; this address is BIN2BCD_SCRATCHPAD+0. If only
there were expressions...
LOAD s0, 02
STORE s0, 25 ; this address is BIN2BCD_SCRATCHPAD+1. If only
there were expressions...
LOAD s0, 96
STORE s0, 26 ; this address is BIN2BCD_SCRATCHPAD+2. If only
there were expressions...
LOAD s0, 49
STORE s0, 27 ; this address is BIN2BCD_SCRATCHPAD+3. If only
there were expressions...
LOAD s0, 04 ; byte count of binary number
CALL bin2bcd
LOAD s1, 05 ; BCD byte count for 32-bit (incl. leading zeros)
loop_output:
SUB s2, 01 ; pre-decrement pointer
FETCH s0, (s2)
SR0 s0
SR0 s0
SR0 s0
SR0 s0
ADD s0, 30 ; add ASCII '0'
OUTPUT s0, MY_OUTPUT_PORT
FETCH s0, (s2)
AND s0, 0F
ADD s0, 30 ; add ASCII '0'
OUTPUT s0, MY_OUTPUT_PORT
SUB s1, 01
JUMP NZ, loop_output
stall:
JUMP stall
;----------------------------------------------------------
; bin2bcd
; By Udi Barzilai 2008
; You are free to use / modify / distribute this code
; PROVIDED AS IS WITHOUT ANY WARRANTY
; USE AT YOUR OWN RISK (if any)
;
; Arguments:
; s0: N = byte count to convert
; SCRATCHPAD(0 TO N-1) should contain binary bytes to convert, LSB at
lowest address
; SCRATCHPAD(N TO N+K-1) will contain BCD converted data, K=ceil
(N*5/4)
; Return:
; s2 and s3 point just after the last byte of BCD
;
bin2bcd:
LOAD s4, s0 ; N
LOAD s1, s0 ; N
SL0 s1 ; N*2
SL0 s1 ; N*4
SL0 s1 ; N*8
LOAD s5, s1 ; save N*8
ADD s1, s0 ; N*9
ADD s1, 03
SR0 s1
SR0 s1 ; ceil(N*9/4)
LOAD s3, BIN2BCD_SCRATCHPAD
ADD s3, s1
; point s2 at start of BCD and clear the bytes there
LOAD s2, BIN2BCD_SCRATCHPAD
ADD s2, s4
LOAD s0, 00
loop_clear_bcd:
STORE s0, (s2)
ADD s2, 01
COMPARE s2, s3
JUMP NZ, loop_clear_bcd
loop_shiftadjust:
; shift everything one bit to the left
LOAD s2, BIN2BCD_SCRATCHPAD
LOAD s1, 00
loop_shiftonce:
FETCH s0, (s2)
SR0 s1 ; fetch stored carry
SLA s0
SLA s1 ; store new carry
STORE s0, (s2)
ADD s2, 01
COMPARE s2, s3
JUMP NZ, loop_shiftonce
; test if we've shifted out all BIN bits
SUB s5, 01
RETURN Z ; done if N bits shifted
; adjust the BCD for the next shift
LOAD s2, BIN2BCD_SCRATCHPAD
ADD s2, s4
loop_adjust:
FETCH s0, (s2)
LOAD s1, s0
ADD s1, 03
TEST s1, 08
JUMP Z, dont_keep3
LOAD s0, s1 ; keep added 3
dont_keep3:
LOAD s1, s0
ADD s1, 30
TEST s1, 80
JUMP Z, dont_keep30
LOAD s0, s1 ; keep added 30
dont_keep30:
STORE s0, (s2)
ADD s2, 01
COMPARE s2, s3
JUMP NZ, loop_adjust
JUMP loop_shiftadjust
;========================================================================
///////////////////////////////////////////////
file on the xilinx site) to run the picoblaze code that I found
online. I synthesized the code, produced, and send a .bit using ISE
10.1 to the Spartan 3an, however, the LCD screen doesn't display
anything. Can someone run this and check if there is something
wrong ?
module lcdtest(lcd_d,
lcd_rs,
lcd_rw,
lcd_e,
j2_30,
j2_26,
j2_22,
j2_14,
clk);
input clk; // 50MHz clock
output reg [7:0] lcd_d ; //
lcd output
output reg lcd_rs;
output reg lcd_rw;
output reg lcd_e;
output j2_30;
output j2_26;
output j2_22;
output j2_14;
wire [9:0] address; // wires to connect uC
address lines
to ROM
wire [17:0] instruction; // wires to connect uC data
lines,
to ROM
wire [7:0] out_port; // wires to connect uC output
port
to the LED flipflops
wire [7:0] port_id;
wire write_strobe;
wire read_strobe;
wire interrupt;
wire interrupt_ack;
wire reset = 0;
wire lcd_rw_control;
wire [7:0] lcd_output_data;
//instantiate the picoblaze mC
kcpsm3 mcu( address, instruction, port_id, write_strobe, out_port,
read_strobe, in_port, interrupt, interrupt_ack, reset, clk );
//instantiate the program rom
lcd rom(address, instruction, clk );
always @ (posedge clk)
begin
/
*----------------------------------------------------------------------------------------------------------------------------------
-- LCD interface
----------------------------------------------------------------------------------------------------------------------------------
--
-- The LCD will be accessed using the 8-bit mode.
-- lcd_rw is '1' for read and '0' for write */
// 8-bit LCD data output address 40 hex.
if (port_id[6])
begin
if(lcd_rw)
lcd_d <= out_port;
else
lcd_d <= 8'bz; // -- use read/write control
to enable output
buffers.
end
//-- LCD controls at address 20 hex.
if (port_id[5])
begin
lcd_rs <= out_port[2];
lcd_rw <= out_port[1]; //Control of read and write signal
lcd_e <= out_port[0];
end
end
endmodule
///////////////////////////////////////////////////////////////////////////////////////////
The .psm file that I complied can be found online, but I will include
it here:
http://forums.xilinx.com/xlnx/board/message?board.id=PicoBlaze&thread...
;========================================================================
CONSTANT BIN2BCD_SCRATCHPAD, 24 ; change this to your preferred
location
CONSTANT MY_OUTPUT_PORT, 00 ; just for the usage example
ADDRESS 000
usage_example:
LOAD s0, D2
STORE s0, 24 ; this address is BIN2BCD_SCRATCHPAD+0. If only
there were expressions...
LOAD s0, 02
STORE s0, 25 ; this address is BIN2BCD_SCRATCHPAD+1. If only
there were expressions...
LOAD s0, 96
STORE s0, 26 ; this address is BIN2BCD_SCRATCHPAD+2. If only
there were expressions...
LOAD s0, 49
STORE s0, 27 ; this address is BIN2BCD_SCRATCHPAD+3. If only
there were expressions...
LOAD s0, 04 ; byte count of binary number
CALL bin2bcd
LOAD s1, 05 ; BCD byte count for 32-bit (incl. leading zeros)
loop_output:
SUB s2, 01 ; pre-decrement pointer
FETCH s0, (s2)
SR0 s0
SR0 s0
SR0 s0
SR0 s0
ADD s0, 30 ; add ASCII '0'
OUTPUT s0, MY_OUTPUT_PORT
FETCH s0, (s2)
AND s0, 0F
ADD s0, 30 ; add ASCII '0'
OUTPUT s0, MY_OUTPUT_PORT
SUB s1, 01
JUMP NZ, loop_output
stall:
JUMP stall
;----------------------------------------------------------
; bin2bcd
; By Udi Barzilai 2008
; You are free to use / modify / distribute this code
; PROVIDED AS IS WITHOUT ANY WARRANTY
; USE AT YOUR OWN RISK (if any)
;
; Arguments:
; s0: N = byte count to convert
; SCRATCHPAD(0 TO N-1) should contain binary bytes to convert, LSB at
lowest address
; SCRATCHPAD(N TO N+K-1) will contain BCD converted data, K=ceil
(N*5/4)
; Return:
; s2 and s3 point just after the last byte of BCD
;
bin2bcd:
LOAD s4, s0 ; N
LOAD s1, s0 ; N
SL0 s1 ; N*2
SL0 s1 ; N*4
SL0 s1 ; N*8
LOAD s5, s1 ; save N*8
ADD s1, s0 ; N*9
ADD s1, 03
SR0 s1
SR0 s1 ; ceil(N*9/4)
LOAD s3, BIN2BCD_SCRATCHPAD
ADD s3, s1
; point s2 at start of BCD and clear the bytes there
LOAD s2, BIN2BCD_SCRATCHPAD
ADD s2, s4
LOAD s0, 00
loop_clear_bcd:
STORE s0, (s2)
ADD s2, 01
COMPARE s2, s3
JUMP NZ, loop_clear_bcd
loop_shiftadjust:
; shift everything one bit to the left
LOAD s2, BIN2BCD_SCRATCHPAD
LOAD s1, 00
loop_shiftonce:
FETCH s0, (s2)
SR0 s1 ; fetch stored carry
SLA s0
SLA s1 ; store new carry
STORE s0, (s2)
ADD s2, 01
COMPARE s2, s3
JUMP NZ, loop_shiftonce
; test if we've shifted out all BIN bits
SUB s5, 01
RETURN Z ; done if N bits shifted
; adjust the BCD for the next shift
LOAD s2, BIN2BCD_SCRATCHPAD
ADD s2, s4
loop_adjust:
FETCH s0, (s2)
LOAD s1, s0
ADD s1, 03
TEST s1, 08
JUMP Z, dont_keep3
LOAD s0, s1 ; keep added 3
dont_keep3:
LOAD s1, s0
ADD s1, 30
TEST s1, 80
JUMP Z, dont_keep30
LOAD s0, s1 ; keep added 30
dont_keep30:
STORE s0, (s2)
ADD s2, 01
COMPARE s2, s3
JUMP NZ, loop_adjust
JUMP loop_shiftadjust
;========================================================================
///////////////////////////////////////////////