; Simple Picoblaze application for the BASYS kit

;br;
br
VHDL "JTAG_Loader_ROM_form.vhd", "Display_demo_rom.vhd", "Display_demo_rom"
br color="#808080"; COE "Romfile.COE"
;br EXEC "JTAG_LOADER.BAT"; EXEC "JTAG_LOADER.BAT"
;br Port definitions; Port definitions
;br;
;br ====================================================================; ====================================================================
br
DIPSW_port DSIN $08 ; 8-Dip Switches
br
Buttons DSIN $09 ; 4-push buttons
br
br
Bcd0 DSIO $00 ; Least significant digit
br
Bcd1 DSIO $01 ; Least significant digit
br
Bcd2 DSIO $02 ; Least significant digit
br
Bcd3 DSIO $03 ; Least significant digit
br
Bcd_lo DSIO $04 ; Two least sign. digits
br
Bcd_hi DSIO $05 ; Two most sign. digits
br
Dp DSIO $06 ; Four decimal points
br
Scale DSOUT $07 ; Time scale for display
br
LEDS_port DSOUT $08 ; 8-Leds
br
;br This Scale not testet yet - please try; This Scale not testet yet - please try
;br =============================================================================; =============================================================================
;br;
;br Special Register usage; Special Register usage
;br;
br
mode_reg EQU sF ; operating mode of processor
;br;
;br Two registers to form a 16-bit counter used to count; Two registers to form a 16-bit counter used to count
;br interrupt pulses generated at 1us intervals.; interrupt pulses generated at 1us intervals.
;br;
br
int_counter_lsb EQU sD ; lower 8-bits
br
int_counter_msb EQU sC ; upper 8-bits
br
seconds EQU s5
mbrminuts
EQU s6
hbrhours
EQU s7
br
;
;br;
;br ============================================================================; ============================================================================
;br scratch pad memory locations; scratch pad memory locations
br
temp EQU 5 ; used to save other values
;br;
;br;
;br UART character strings will be stored in scratch pad memory ending in CR.; UART character strings will be stored in scratch pad memory ending in CR.
;br A string can be up to 16 characters with the start location defined by this .; A string can be up to 16 characters with the start location defined by this .
;br;
br
string_start DS $10
br
br
; Initialise the system
;br;
br
cold_start:
br
LOAD s0, $33
br
OUT s0, LEDS_port ;
br
;br CALL Delay250ms; CALL Delay250ms
;br CALL Delay250ms; CALL Delay250ms
;br CALL Delay250ms; CALL Delay250ms
;br CALL Delay250ms; CALL Delay250ms
br
br
LOAD s0, $55
br
OUT s0, LEDS_port ;
br
br
CALL Delay250ms
br
br
LOAD s2, $75
br
STORE s2, temp ; save value
br
FETCH s3, temp ; retrieve value
;br;
br
LOAD int_counter_lsb, $0F; clear 'us' interrupt counter
br
LOAD int_counter_msb, 0
br
OUT int_counter_lsb, Dp
br
br
EINT ; enable the 1us interrupts
;br;
;br;
;br Start of the main program loop.; Start of the main program loop.
;br;
br
br
main_loop:
br
IN s4, Buttons
br
TEST s4, 2
br
CALL NZ, Show_DIPSW
br
TEST s4, 1
br
JUMP NZ, main_loop
br
ADD Seconds, 1
br
ADDC Minuts, 0
br
OUT Seconds, Bcd_lo
br
OUT Minuts, Bcd_hi
br
; OUT int_counter_lsb, Bcd_lo
;br OUT int_counter_msb, Bcd_hi; OUT int_counter_msb, Bcd_hi
br
Show_Counter:
br
OUT int_counter_msb, LEDS_port
br
JUMP main_loop
br
; =============================================================================
br
Show_DIPSW:
br
IN s0, DIPSW_port
br
OUT s0, LEDS_port ; turn on leds
br
CALL Delay250ms
br
RET
br
br
; =============================================================================
br
delay1us: ; 1us delay loop - assumes 50MHz clock
br
LOAD s0, 12 ; need to check this delay
br
delay1us1: SUB s0, $01
br
JUMP NZ, delay1us1
br
RET
br
; =============================================================================
br
delay16ms: ; approx. 16ms delay loop - assumes 50MHz clock
br
LOAD s2, $50 ; 80 decimal
br
delay16ms0: LOAD s1, $C8 ; 200 decimal (need to check this delay)
br
delay16ms1: CALL delay1us
br
SUB s1, 1
br
JUMP NZ, delay16ms1
br
SUB s2, 1
br
JUMP NZ, delay16ms0
br
RET
br
br
; =============================================================================
br
delay250ms: ; approx. 250ms delay loop - assumes 50MHz clock
;br RET ; for debug purposes; RET ; for debug purposes
br
LOAD s3, 16 ; need to check this delay
br
delay250_1: CALL delay16ms
br
SUB s3, $01
br
JUMP NZ, delay250_1
br
RET
br
br
; =============================================================================
;br Interrupt service routine (ISR); Interrupt service routine (ISR)
;br;
;br The interrupt is used to increment a 16-bit counter formed with two registers; The interrupt is used to increment a 16-bit counter formed with two registers
;br called [int_counter_msb,int_counter_lsb]. This provides a count of the number; called [int_counter_msb,int_counter_lsb]. This provides a count of the number
;br of micro-seconds elapsed. The counter is 'free running' in that it will count; of micro-seconds elapsed. The counter is 'free running' in that it will count
;br up to 65,535 and then roll over to zero. The count value is then used in other; up to 65,535 and then roll over to zero. The count value is then used in other
;br parts of the program as required and where it is less time critical.; parts of the program as required and where it is less time critical.
;br;
;br The ISR only uses the specified counter registers; The ISR only uses the specified counter registers
;br;
br
ORG $3FC
br
ISR:
br
ADD int_counter_lsb, 1 ; add 1us to 16-bit counter
br
ADDC int_counter_msb, 0
br
RETI ENABLE
br
;
;br Interrupt vector; Interrupt vector
;br;
br
ORG $3FF
br
JUMP ISR
br
br
Program example (old)