Forum Discussion
assn1
New Contributor
4 years agoI need help with coding...
I'm making a digital watch code. There is no problem with the code itself, but as I input things like BUTTON_SW and BUS_SW, I didn't have enough buttons in my kit to run the hour, minute, second, an...
ak6dn
Regular Contributor
4 years agoI really have no idea what the question is that you are asking. Can you be more specific?
There is no problem with the code itself, but as I input things like BUTTON_SW and BUS_SW, I didn't have enough buttons in my kit to run the hour, minute, second, and mode conversion… So I want to allocate BUTTON_SW to work as much as the DIP button in the kit is turned on. But that code failed.
By the way, I would have written your code like this...
always @(posedge CLK_100HZ or negedge RESETN) begin if (~RESETN) DIP <= 1'b0; else if (DIP < 17) DIP <= BUTTON_SW[DIP[3:0]]; end
which is much more succinct.
I also prefer to use a non-blocking register assignment (<=) as opposed to a blocking (=) assignment UNLESS you specifically need the functionality of a blocking assignment (ie, if you are computing temporary intermediate values).
And I always put the clock edge first in the always @() block to make it clear what clock edge is providing state transition.