fg_ctrl.rmh
来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 1,476 行 · 第 1/5 页
RMH
1,476 行
// #353: ;calculation highly predictable. The '6' in the following equation even allows for// #354: ;'CALL delay_1us' instruction in the initiating code.// #355: ;// #356: ; delay_1us_constant = (clock_rate - 6)/4 Where 'clock_rate' is in MHz// #357: ;// #358: ;Example: For a 50MHz clock the constant value is (10-6)/4 = 11 (0B Hex).// #359: ;For clock rates below 10MHz the value of 1 must be used and the operation will// #360: ;become lower than intended.// #361: ;// #362: CONSTANT(delay_1us_constant,11)// #363: ;// #364: ;// #365: ;// #366: ;ASCII table// #367: ;// #368: CONSTANT(character_a,97)// #369: CONSTANT(character_b,98)// #370: CONSTANT(character_c,99)// #371: CONSTANT(character_d,100)// #372: CONSTANT(character_e,101)// #373: CONSTANT(character_f,102)// #374: CONSTANT(character_g,103)// #375: CONSTANT(character_h,104)// #376: CONSTANT(character_i,105)// #377: CONSTANT(character_j,106)// #378: CONSTANT(character_k,107)// #379: CONSTANT(character_l,108)// #380: CONSTANT(character_m,109)// #381: CONSTANT(character_n,110)// #382: CONSTANT(character_o,111)// #383: CONSTANT(character_p,112)// #384: CONSTANT(character_q,113)// #385: CONSTANT(character_r,114)// #386: CONSTANT(character_s,115)// #387: CONSTANT(character_t,116)// #388: CONSTANT(character_u,117)// #389: CONSTANT(character_v,118)// #390: CONSTANT(character_w,119)// #391: CONSTANT(character_x,120)// #392: CONSTANT(character_y,121)// #393: CONSTANT(character_z,122)// #394: CONSTANT(character_A,65)// #395: CONSTANT(character_B,66)// #396: CONSTANT(character_C,67)// #397: CONSTANT(character_D,68)// #398: CONSTANT(character_E,69)// #399: CONSTANT(character_F,70)// #400: CONSTANT(character_G,71)// #401: CONSTANT(character_H,72)// #402: CONSTANT(character_I,73)// #403: CONSTANT(character_J,74)// #404: CONSTANT(character_K,75)// #405: CONSTANT(character_L,76)// #406: CONSTANT(character_M,77)// #407: CONSTANT(character_N,78)// #408: CONSTANT(character_O,79)// #409: CONSTANT(character_P,80)// #410: CONSTANT(character_Q,81)// #411: CONSTANT(character_R,82)// #412: CONSTANT(character_S,83)// #413: CONSTANT(character_T,84)// #414: CONSTANT(character_U,85)// #415: CONSTANT(character_V,86)// #416: CONSTANT(character_W,87)// #417: CONSTANT(character_X,88)// #418: CONSTANT(character_Y,89)// #419: CONSTANT(character_Z,90)// #420: CONSTANT(character_0,48)// #421: CONSTANT(character_1,49)// #422: CONSTANT(character_2,50)// #423: CONSTANT(character_3,51)// #424: CONSTANT(character_4,52)// #425: CONSTANT(character_5,53)// #426: CONSTANT(character_6,54)// #427: CONSTANT(character_7,55)// #428: CONSTANT(character_8,56)// #429: CONSTANT(character_9,57)// #430: CONSTANT(character_colon,58)// #431: CONSTANT(character_stop,46)// #432: CONSTANT(character_semi_colon,59)// #433: CONSTANT(character_minus,45)// #434: CONSTANT(character_divide,47) ;'/'// #435: CONSTANT(character_plus,43)// #436: CONSTANT(character_comma,44)// #437: CONSTANT(character_less_than,60)// #438: CONSTANT(character_greater_than,62)// #439: CONSTANT(character_equals,61)// #440: CONSTANT(character_space,32)// #441: CONSTANT(character_CR,13) ;carriage return// #442: CONSTANT(character_question,63) ;'?'// #443: CONSTANT(character_dollar,36)// #444: CONSTANT(character_exclaim,33) ;'!'// #445: CONSTANT(character_BS,8) ;Back Space command character// #446: ;// #447: ;// #448: ;// #449: ;// #450: ;// #451: ;**************************************************************************************// #452: ;Initialise the system// #453: ;**************************************************************************************// #454: ;// @000 #455: [cold_start]30215 // @000 #455: CALL(LCD_reset) ;initialise LCD display// #456: ;// #457: ;Write 'Frequency Generator' to LCD display and display for 4 seconds// #458: ;00510 // @001 #459: LOAD(s5,16) ;Line 1 position 03022b // @002 #460: CALL(LCD_cursor)3018b // @003 #461: CALL(disp_Frequency)00522 // @004 #462: LOAD(s5,34) ;Line 2 position 23022b // @005 #463: CALL(LCD_cursor)3019e // @006 #464: CALL(disp_Generator)301cd // @007 #465: CALL(delay_1s) ;wait 4 seconds301cd // @008 #466: CALL(delay_1s)301cd // @009 #467: CALL(delay_1s)301cd // @00a #468: CALL(delay_1s)30226 // @00b #469: CALL(LCD_clear) ;clear screen// #470: ;// #471: ;// #472: ;Initial frequency of 100MHz// #473: ;00000 // @00c #474: LOAD(s0,0)00101 // @00d #475: LOAD(s1,1)2e003 // @00e #476: STORE(s0,BCD_digit0)2e004 // @00f #477: STORE(s0,BCD_digit1)2e005 // @010 #478: STORE(s0,BCD_digit2)2e006 // @011 #479: STORE(s0,BCD_digit3)2e007 // @012 #480: STORE(s0,BCD_digit4)2e008 // @013 #481: STORE(s0,BCD_digit5)2e009 // @014 #482: STORE(s0,BCD_digit6)2e00a // @015 #483: STORE(s0,BCD_digit7)2e10b // @016 #484: STORE(s1,BCD_digit8)// #485: ;00004 // @017 #486: LOAD(s0,4) ;Start position for editing frequency is 1MHz digit2e010 // @018 #487: STORE(s0,cursor_position)00009 // @019 #488: LOAD(s0,BCD_digit6)2e011 // @01a #489: STORE(s0,edit_digit_pointer)// #490: ;// #491: ;3c001 // @01b #492: ENABLE(INTERRUPT) ;interrupts are used to detect rotary controller301c3 // @01c #493: CALL(delay_1ms)00000 // @01d #494: LOAD(s0,0) ;clear the status of any spurious rotary events2e000 // @01e #495: STORE(s0,rotary_status) ; as a result of system turning on.// #496: ;// #497: ;**************************************************************************************// #498: ; Main program// #499: ;**************************************************************************************// #500: ;// #501: ; The main program is centred on the task of editing the frequency. It waits until the// #502: ; rotary control is used and then makes the appropriate changes. If the actual digit// #503: ; digit value is changed then the calculation to drive the DDS is performed each time.// #504: ;// #505: ; The start state is that of allowing the edit cursor position to be moved. Rotary// #506: ; inputs are detected by the interrupt service routine and set a flag bit which the// #507: ; main program then uses to adjust the cursor position and pointer to the corresponding// #508: ; BCD digit in memory.// #509: ;// #510: ; A press of the rotary control is detected by polling and used to change to the digit// #511: ; editing mode.// #512: ;// #513: ;// @01f #514: [move_mode]30084 // @01f #514: CALL(compute_DDS_words) ;compute DDS control values300b4 // @020 #515: CALL(display_freq) ;refresh display with cursor position shown00001 // @021 #516: LOAD(s0,LED0) ;indicate move mode on LEDs2c080 // @022 #517: OUTPUT(s0,LED_port)// @023 #518: [move_wait]04000 // @023 #518: INPUT(s0,rotary_port) ;read rotary encoder12002 // @024 #519: TEST(s0,rotary_press) ;test for press of button which changes mode35445 // @025 #520: JUMP(NZ,edit_mode)06000 // @026 #521: FETCH(s0,rotary_status) ;check for any rotation of rotary control12080 // @027 #522: TEST(s0,rotary_event)35023 // @028 #523: JUMP(Z,move_wait)// #524: ;0a07f // @029 #525: AND(s0,127) ;clear flag now that action it is being processed2e000 // @02a #526: STORE(s0,rotary_status)06a10 // @02b #527: FETCH(sA,cursor_position) ;read current position06b11 // @02c #528: FETCH(sB,edit_digit_pointer)12001 // @02d #529: TEST(s0,rotary_left) ;determine direction to move cursor35039 // @02e #530: JUMP(Z,move_right)// #531: ;// @02f #532: [move_left]14b0b // @02f #532: COMPARE(sB,BCD_digit8) ;can not move left of 100MHz digit3501f // @030 #533: JUMP(Z,move_mode)18b01 // @031 #534: ADD(sB,1) ;move to next higher BCD digit1ca01 // @032 #535: SUB(sA,1) ;move cursor to match digit to be edited14a09 // @033 #536: COMPARE(sA,9) ;must skip over space separator35037 // @034 #537: JUMP(Z,skip_left)14a05 // @035 #538: COMPARE(sA,5) ;must skip over decimal point35442 // @036 #539: JUMP(NZ,edit_point_update)// @037 #540: [skip_left]1ca01 // @037 #540: SUB(sA,1) ;move cursor further left34042 // @038 #541: JUMP(edit_point_update)// #542: ;// @039 #543: [move_right]14b03 // @039 #543: COMPARE(sB,BCD_digit0) ;can not move right of 1Hz digit3501f // @03a #544: JUMP(Z,move_mode)1cb01 // @03b #545: SUB(sB,1) ;move to next lower BCD digit18a01 // @03c #546: ADD(sA,1) ;move cursor to match digit to be edited14a09 // @03d #547: COMPARE(sA,9) ;must skip over space separator35041 // @03e #548: JUMP(Z,skip_right)14a05 // @03f #549: COMPARE(sA,5) ;must skip over decimal point35442 // @040 #550: JUMP(NZ,edit_point_update)// @041 #551: [skip_right]18a01 // @041 #551: ADD(sA,1) ;move cursor further right// #552: ;// @042 #553: [edit_point_update]2ea10 // @042 #553: STORE(sA,cursor_position) ;update edit value in memory2eb11 // @043 #554: STORE(sB,edit_digit_pointer)3401f // @044 #555: JUMP(move_mode)// #556: ;// #557: ;// #558: ; The edit mode is reached by pressing the rotary control. Since this is a simple switch// #559: ; a software de-bounce delay is used to wait for the knob to be released fully before// #560: ; entering the digit editing mode fully.// #561: ;// #562: ; In this mode rotations of the detected by the interrupt service routine are used to// #563: ; increment or decrement the digit value at the cursor position with carry/borrow to// #564: ; the left.// #565: ;// #566: ; A new press of the rotary control is detected by polling and used to change back to the// #567: ; cursor moving mode.// #568: ;// #569: ;// @045 #570: [edit_mode]3007d // @045 #570: CALL(wait_switch_release) ;wait for switch press to end// @046 #571: [edit_display]30084 // @046 #571: CALL(compute_DDS_words) ;compute DDS control values300b4 // @047 #572: CALL(display_freq) ;refresh display with new values00002 // @048 #573: LOAD(s0,LED1) ;indicate edit mode on LEDs2c080 // @049 #574: OUTPUT(s0,LED_port)// @04a #575: [edit_wait]04000 // @04a #575: INPUT(s0,rotary_port) ;read rotary encoder12002 // @04b #576: TEST(s0,rotary_press) ;test for press of button which changes mode3547b // @04c #577: JUMP(NZ,end_edit_mode)06000 // @04d #578: FETCH(s0,rotary_status) ;check for any rotation of rotary control12080 // @04e #579: TEST(s0,rotary_event)3504a // @04f #580: JUMP(Z,edit_wait)// #581: ;0a07f // @050 #582: AND(s0,127) ;clear flag now that action it is being processed2e000 // @051 #583: STORE(s0,rotary_status)06b11 // @052 #584: FETCH(sB,edit_digit_pointer) ;read pointer to BCD digit for initial change12001 // @053 #585: TEST(s0,rotary_left) ;determine direction to increment or decrement35068 // @054 #586: JUMP(Z,inc_digit)// #587: ;// #588: ; Decrement the value starting at the current position and borrowing from the left.// #589: ; However the value needs to bottom out at all 0's from the editing position.// #590: ;// #591: ;// @055 #592: [dec_digit]07ab0 // @055 #592: FETCH(sA,sB) ;read digit value at pointer position1ca01 // @056 #593: SUB(sA,1) ;decrement digit14aff // @057 #594: COMPARE(sA,FF) ;test for borrow from next digit3505b // @058 #595: JUMP(Z,dec_borrow)2fab0 // @059 #596: STORE(sA,sB) ;store decremented digit value34046 // @05a #597: JUMP(edit_display) ;decrement task complete// @05b #598: [dec_borrow]00a09 // @05b #598: LOAD(sA,9) ;current digit rolls over to nine2fab0 // @05c #599: STORE(sA,sB) ;store '9' digit value14b0b // @05d #600: COMPARE(sB,BCD_digit8) ;check if working on 100MHz digit35061 // @05e #601: JUMP(Z,set_min_value)18b01 // @05f #602: ADD(sB,1) ;increment pointer to next most significant digit34055 // @060 #603: JUMP(dec_digit) ;decrement next digit up.// #604: ;// @061 #605: [set_min_value]06b11 // @061 #605: FETCH(sB,edit_digit_pointer) ;Must fill digits from insert to MS-Digit with 000...00a00 // @062 #606: LOAD(sA,0)// @063 #607: [fill_min]2fab0 // @063 #607: STORE(sA,sB)14b0b // @064 #608: COMPARE(sB,BCD_digit8) ;check if filled to 100MHz digit35046 // @065 #609: JUMP(Z,edit_display)18b01 // @066 #610: ADD(sB,1) ;fill next higher digit34063 // @067 #611: JUMP(fill_min)// #612: ;// #613: ; Increment the value starting at the current position and carrying to the left.// #614: ; However the value needs to saturate to all 9's from the editing position.// #615: ;// @068 #616: [inc_digit]07ab0 // @068 #616: FETCH(sA,sB) ;read digit value at pointer position18a01 // @069 #617: ADD(sA,1) ;increment digit14a0a // @06a #618: COMPARE(sA,10) ;test for carry to next digit3506e // @06b #619: JUMP(Z,inc_carry)2fab0 // @06c #620: STORE(sA,sB) ;store incremented digit value34046 // @06d #621: JUMP(edit_display) ;increment task complete// @06e #622: [inc_carry]00a00 // @06e #622: LOAD(sA,0) ;current digit rolls over to zero2fab0 // @06f #623: STORE(sA,sB) ;store zero digit value14b0b // @070 #624: COMPARE(sB,BCD_digit8) ;check if working on 100MHz digit35074 // @071 #625: JUMP(Z,set_max_value)18b01 // @072 #626: ADD(sB,1) ;increment pointer to next most significant digit34068 // @073 #627: JUMP(inc_digit) ;increment next digit up.// #628: ;// @074 #629: [set_max_value]06b11 // @074 #629: FETCH(sB,edit_digit_pointer) ;Must fill digits from insert to MS-Digit with 999...00a09 // @075 #630: LOAD(sA,9)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?