📄 clock.psm
字号:
CONSTANT LED_port, 80 ;8 simple LEDs
CONSTANT LED0, 01 ; LED 0 - bit0
CONSTANT LED1, 02 ; 1 - bit1
CONSTANT LED2, 04 ; 2 - bit2
CONSTANT LED3, 08 ; 3 - bit3
CONSTANT LED4, 10 ; 4 - bit4
CONSTANT LED5, 20 ; 5 - bit5
CONSTANT LED6, 40 ; 6 - bit6
CONSTANT LED7, 80 ; 7 - bit7
;
CONSTANT switch_port, 00 ;Read switches and press buttons
CONSTANT switch0, 01 ; Switches SW0 - bit0
CONSTANT switch1, 02 ; SW1 - bit1
CONSTANT switch2, 04 ; SW2 - bit2
CONSTANT switch3, 08 ; SW3 - bit3
CONSTANT BTN_east, 10 ; Buttons East - bit4
CONSTANT BTN_south, 20 ; South - bit5
CONSTANT BTN_north, 40 ; North - bit6
CONSTANT BTN_west, 80 ; West - bit7
;
CONSTANT rotary_port, 01 ;Read status of rotary encoder
CONSTANT rotary_left, 01 ; Direction of last move Left=1 Right=0 - bit0
CONSTANT rotary_press, 02 ; Centre press contact (active High) - bit1
;
;LCD interface ports
;
;The master enable signal is not used by the LCD display itself
;but may be required to confirm that LCD communication is active.
;This is required on the Spartan-3E Starter Kit if the StrataFLASH
;is used because it shares the same data pins and conflicts must be avoided.
;
CONSTANT LCD_output_port, 40 ;LCD character module output data and control
CONSTANT LCD_E, 01 ; active High Enable E - bit0
CONSTANT LCD_RW, 02 ; Read=1 Write=0 RW - bit1
CONSTANT LCD_RS, 04 ; Instruction=0 Data=1 RS - bit2
CONSTANT LCD_drive, 08 ; Master enable (active High) - bit3
CONSTANT LCD_DB4, 10 ; 4-bit Data DB4 - bit4
CONSTANT LCD_DB5, 20 ; interface Data DB5 - bit5
CONSTANT LCD_DB6, 40 ; Data DB6 - bit6
CONSTANT LCD_DB7, 80 ; Data DB7 - bit7
;
CONSTANT LCD_input_port, 02 ;LCD character module input data
CONSTANT LCD_read_spare0, 01 ; Spare bits - bit0
CONSTANT LCD_read_spare1, 02 ; are zero - bit1
CONSTANT LCD_read_spare2, 04 ; - bit2
CONSTANT LCD_read_spare3, 08 ; - bit3
CONSTANT LCD_read_DB4, 10 ; 4-bit Data DB4 - bit4
CONSTANT LCD_read_DB5, 20 ; interface Data DB5 - bit5
CONSTANT LCD_read_DB6, 40 ; Data DB6 - bit6
CONSTANT LCD_read_DB7, 80 ; Data DB7 - bit7
CONSTANT BIT7, 80 ;
CONSTANT BIT6, 40 ;
CONSTANT BIT5, 20 ;
CONSTANT BIT4, 10 ;
CONSTANT BIT3, 08 ;
CONSTANT BIT2, 04 ;
CONSTANT BIT1, 02 ;
CONSTANT BIT0, 01 ;
;
;**************************************************************************************
;Scratch Pad Memory Locations
;**************************************************************************************
;
CONSTANT rotary_status, 00 ;Status of rotary encoder
CONSTANT ISR_s0, 01 ;Preserve s0 contents during ISR
CONSTANT LED_pattern, 02 ;LED pattern used in rotation mode
;
CONSTANT mode, 03 ;control mode 00=switch and button FF=rotary
CONSTANT ms1, 04
CONSTANT secL, 05
CONSTANT secH, 06
CONSTANT minL, 07
CONSTANT minH, 08
CONSTANT hourL, 09
CONSTANT hourH, 0A
CONSTANT week, 0B
CONSTANT year1, 0C
CONSTANT year2, 0D
CONSTANT year3, 0E
CONSTANT year4, 0F
CONSTANT ms2, 10
CONSTANT ms500, 11
CONSTANT ISR_s1, 12
CONSTANT ms100, 13
CONSTANT ROTA_CNT, 14
CONSTANT ISR_s2, 15
CONSTANT temp, 16
CONSTANT pressed, 17
CONSTANT disp_flag, 18
CONSTANT blink_flag, 19
CONSTANT disp_flag2, 1A ;;;;;no use
CONSTANT monH, 1B
CONSTANT monL, 1C
CONSTANT dayH, 1D
CONSTANT dayL, 1E
CONSTANT DAY_UP, 1F
CONSTANT year100, 20
CONSTANT hourB, 21
CONSTANT minB, 22
CONSTANT secB, 23
CONSTANT yearB, 24
CONSTANT monB, 25
CONSTANT dayB, 26
CONSTANT DMAX, 27 ;
CONSTANT JAN, 28 ;
CONSTANT FEB, 29 ;
CONSTANT MAR, 2A ;
CONSTANT APR, 2B ;
CONSTANT MAY, 2C ;
CONSTANT JUN, 2D ;
CONSTANT JUL, 2E ;
CONSTANT AUG, 2F ;
CONSTANT SEP, 30 ;
CONSTANT OCT, 31 ;
CONSTANT NOV, 32 ;
CONSTANT DEC, 33 ;
CONSTANT JAN2, 34 ;
CONSTANT FEB2, 35 ;
CONSTANT MAR2, 36 ;
CONSTANT APR2, 37 ;
CONSTANT MAY2, 38 ;
CONSTANT JUN2, 39 ;
CONSTANT JUL2, 3A ;
CONSTANT AUG2, 3B ;
CONSTANT SEP2, 3C ;
CONSTANT OCT2, 3D ;
CONSTANT NOV2, 3E ;
CONSTANT DEC2, 3F ;
;The main operation of the program uses 1ms delays to set the shift rate
;of the LCD display. A 16-bit value determines how many milliseconds
;there are between shifts
;
;Tests indicate that the fastest shift rate that the LCD display supports is
;500ms. Faster than this and the display becomes less clear to read.
;
CONSTANT shift_delay_msb, 01 ;delay is 500ms (01F4 hex)
CONSTANT shift_delay_lsb, F4
;
; delay_1us_constant = (clock_rate - 6)/4 Where 'clock_rate' is in MHz
;
;Example: For a 50MHz clock the constant value is (10-6)/4 = 11 (0B Hex).
;For clock rates below 10MHz the value of 1 must be used and the operation will
;become lower than intended.
;
CONSTANT delay_1us_constant, 0B
;ASCII table
;
CONSTANT character_a, 61
CONSTANT character_b, 62
CONSTANT character_c, 63
CONSTANT character_d, 64
CONSTANT character_e, 65
CONSTANT character_f, 66
CONSTANT character_g, 67
CONSTANT character_h, 68
CONSTANT character_i, 69
CONSTANT character_j, 6A
CONSTANT character_k, 6B
CONSTANT character_l, 6C
CONSTANT character_m, 6D
CONSTANT character_n, 6E
CONSTANT character_o, 6F
CONSTANT character_p, 70
CONSTANT character_q, 71
CONSTANT character_r, 72
CONSTANT character_s, 73
CONSTANT character_t, 74
CONSTANT character_u, 75
CONSTANT character_v, 76
CONSTANT character_w, 77
CONSTANT character_x, 78
CONSTANT character_y, 79
CONSTANT character_z, 7A
CONSTANT character_A, 41
CONSTANT character_B, 42
CONSTANT character_C, 43
CONSTANT character_D, 44
CONSTANT character_E, 45
CONSTANT character_F, 46
CONSTANT character_G, 47
CONSTANT character_H, 48
CONSTANT character_I, 49
CONSTANT character_J, 4A
CONSTANT character_K, 4B
CONSTANT character_L, 4C
CONSTANT character_M, 4D
CONSTANT character_N, 4E
CONSTANT character_O, 4F
CONSTANT character_P, 50
CONSTANT character_Q, 51
CONSTANT character_R, 52
CONSTANT character_S, 53
CONSTANT character_T, 54
CONSTANT character_U, 55
CONSTANT character_V, 56
CONSTANT character_W, 57
CONSTANT character_X, 58
CONSTANT character_Y, 59
CONSTANT character_Z, 5A
CONSTANT character_0, 30
CONSTANT character_1, 31
CONSTANT character_2, 32
CONSTANT character_3, 33
CONSTANT character_4, 34
CONSTANT character_5, 35
CONSTANT character_6, 36
CONSTANT character_7, 37
CONSTANT character_8, 38
CONSTANT character_9, 39
CONSTANT character_colon, 3A
CONSTANT character_stop, 2E
CONSTANT character_semi_colon, 3B
CONSTANT character_minus, 2D
CONSTANT character_divide, 2F ;'/'
CONSTANT character_plus, 2B
CONSTANT character_comma, 2C
CONSTANT character_less_than, 3C
CONSTANT character_greater_than, 3E
CONSTANT character_equals, 3D
CONSTANT character_space, 20
CONSTANT character_CR, 0D ;carriage return
CONSTANT character_question, 3F ;'?'
CONSTANT character_dollar, 24
CONSTANT character_exclaim, 21 ;'!'
CONSTANT character_BS, 08 ;Back Space command character
;
reset: CALL LCD_reset
ENABLE INTERRUPT
LOAD sD, FF
LOAD s0, 00 ;
STORE s0, hourH
STORE s0, minL
STORE s0, minH
STORE s0, secH
STORE s0, secL
STORE s0, year2
STORE s0, year3
STORE s0, monH
STORE s0, minB ;;;;;;;;;;
STORE s0, secB ;;;;;;;;;;
LOAD s0, 09 ;
STORE s0, hourL
STORE s0, hourB ;;;;;;;;;
LOAD s0, 02 ;
STORE s0, year1
STORE s0, dayH
LOAD s0, 06 ;
STORE s0, dayL
STORE s0, year4
STORE s0, yearB ;;;;;;;;;
LOAD s0, 05 ;
STORE s0, monL
STORE s0, week
STORE s0, monB ;;;;;;;;;
LOAD s0, 1A
STORE s0, dayB ;;;;;;;;;
LOAD s0, 1F
STORE s0, JAN ;1
STORE s0, MAR ;3
STORE s0, MAY ;5
STORE s0, JUL ;7
STORE s0, AUG ;8
STORE s0, OCT ;10
STORE s0, DEC ;12
LOAD s0, 1E
STORE s0, APR ;4
STORE s0, JUN ;6
STORE s0, SEP ;9
STORE s0, NOV ;11
LOAD s0, 1C
STORE s0, FEB ;2
LOAD s0, 03
STORE s0, JAN2
STORE s0, OCT2
LOAD s0, 06
STORE s0, FEB2
STORE s0, MAR2
STORE s0, NOV2
LOAD s0, 02
STORE s0, APR2
STORE s0, JUL2
LOAD s0, 04
STORE s0, MAY2
LOAD s0, 00
STORE s0, JUN2
LOAD s0, 05
STORE s0, AUG2
LOAD s0, 01
STORE s0, SEP2
STORE s0, DEC2
LOAD sF, 00 ;
restart:
LOAD s5, 10
CALL LCD_cursor
CALL disp_msg1
LOAD s5, 20
CALL LCD_cursor
CALL disp_msg2
LOAD s3, 35
STORE s3, temp
BLINK10: LOAD s3, 00
STORE s3, ms100
BLINK1: FETCH s3, ms100
COMPARE s3, 05
JUMP C, BLINK1
LOAD s5, 2F
CALL LCD_cursor
FETCH s5, temp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -