pwm_ctrl.rmh
来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 966 行 · 第 1/3 页
RMH
966 行
// #147: CONSTANT(character_U,85)// #148: CONSTANT(character_V,86)// #149: CONSTANT(character_W,87)// #150: CONSTANT(character_X,88)// #151: CONSTANT(character_Y,89)// #152: CONSTANT(character_Z,90)// #153: CONSTANT(character_0,48)// #154: CONSTANT(character_1,49)// #155: CONSTANT(character_2,50)// #156: CONSTANT(character_3,51)// #157: CONSTANT(character_4,52)// #158: CONSTANT(character_5,53)// #159: CONSTANT(character_6,54)// #160: CONSTANT(character_7,55)// #161: CONSTANT(character_8,56)// #162: CONSTANT(character_9,57)// #163: CONSTANT(character_colon,58)// #164: CONSTANT(character_stop,46)// #165: CONSTANT(character_semi_colon,59)// #166: CONSTANT(character_minus,45)// #167: CONSTANT(character_divide,47) ;'/'// #168: CONSTANT(character_plus,43)// #169: CONSTANT(character_comma,44)// #170: CONSTANT(character_less_than,60)// #171: CONSTANT(character_greater_than,62)// #172: CONSTANT(character_equals,61)// #173: CONSTANT(character_space,32)// #174: CONSTANT(character_CR,13) ;carriage return// #175: CONSTANT(character_question,63) ;'?'// #176: CONSTANT(character_dollar,36)// #177: CONSTANT(character_exclaim,33) ;'!'// #178: CONSTANT(character_BS,8) ;Back Space command character// #179: ;// #180: ;// #181: ;// #182: ;// #183: ;// #184: ;**************************************************************************************// #185: ;Initialise the system// #186: ;**************************************************************************************// #187: ;// #188: ; Each PWM channels will be set to a different initial value just for the purposes// #189: ; of demonstration. In practice, the initial duty values will depend on the requirements// #190: ; of a given system but completely off (zero) is normally the safe option.// #191: ;// #192: ; Note that it is difficult to distinguish difference between the intensity of LEDs driven// #193: ; with duty factors more than 40% (40% = 102/256 or 66Hex). So using relatively small values// #194: ; will better demonstrate the PWM control of intensity.// #195: ;// #196: ; Initial values for LEDs give graduated intensity. Large change required for brighter LEDs.// #197: ;// @000 #198: [cold_start]00005 // @000 #198: LOAD(s0,5) ;5/256 = 2%2e001 // @001 #199: STORE(s0,PWM_channel0)0000d // @002 #200: LOAD(s0,13) ;13/256 = 5%2e002 // @003 #201: STORE(s0,PWM_channel1)00014 // @004 #202: LOAD(s0,20) ;26/256 = 8%2e003 // @005 #203: STORE(s0,PWM_channel2)00026 // @006 #204: LOAD(s0,38) ;38/256 = 15%2e004 // @007 #205: STORE(s0,PWM_channel3)00040 // @008 #206: LOAD(s0,64) ;64/256 = 25%2e005 // @009 #207: STORE(s0,PWM_channel4)00058 // @00a #208: LOAD(s0,88) ;88/256 = 34%2e006 // @00b #209: STORE(s0,PWM_channel5)00080 // @00c #210: LOAD(s0,128) ;128/256 = 50%2e007 // @00d #211: STORE(s0,PWM_channel6)000ff // @00e #212: LOAD(s0,FF) ;255/256 = 99.6% Maximum possible2e008 // @00f #213: STORE(s0,PWM_channel7)// #214: ;// #215: ; Initial values for simple outputs match documentation example// #216: ;00011 // @010 #217: LOAD(s0,17) ;17/256 = 7%2e009 // @011 #218: STORE(s0,PWM_channel8)000bc // @012 #219: LOAD(s0,BC) ;188/256 = 73%2e00a // @013 #220: STORE(s0,PWM_channel9)000ef // @014 #221: LOAD(s0,EF) ;239/256 = 93%2e00b // @015 #222: STORE(s0,PWM_channel10)00022 // @016 #223: LOAD(s0,34) ;34/256 = 13%2e00c // @017 #224: STORE(s0,PWM_channel11)// #225: ;3c001 // @018 #226: ENABLE(INTERRUPT) ;interrupts used to drive servo// #227: ;300b9 // @019 #228: CALL(send_welcome) ;Write welcome message to UART// #229: ;// #230: ;// #231: ;// #232: ;**************************************************************************************// #233: ; Main program// #234: ;**************************************************************************************// #235: ;// #236: ; Provides a prompt to which an input with one of the following formats is expected...// #237: ;// #238: ; LDn hh// #239: ;// #240: ; IOk hh// #241: ; IOkk hh// #242: ;// #243: ;// #244: ; Where// #245: ; 'LD' is a command to set one of the LED channels.// #246: ; 'IO' is a command to set one of the simple I/O outputs on J4.// #247: ; 'n' is an LED number in the range 0 to 7.// #248: ; 'k' or 'kk' is a simple I/O number in the range 9 to 12.// #249: ; 'hh' is a 2 digit hex value to specify the PWM duty factor (range 00 to FF).// #250: ;// #251: ; The input allows a degree of editing to be performed and upper and lower case letters// #252: ; to be used.// #253: ;// @01a #254: [warm_start]300e6 // @01a #254: CALL(send_prompt) ;Prompt 'KCPSM3>'30063 // @01b #255: CALL(receive_string) ;obtain input string of up to 16 characters3008b // @01c #256: CALL(upper_case_string) ;convert string to upper case// #257: ;00e30 // @01d #258: LOAD(sE,string_start) ;sE is memory pointer070e0 // @01e #259: FETCH(s0,sE) ;test for carriage return1400d // @01f #260: COMPARE(s0,character_CR)3501a // @020 #261: JUMP(Z,warm_start)1404c // @021 #262: COMPARE(s0,character_L) ;test for 'L' of 'LD' command35028 // @022 #263: JUMP(Z,LD_command)14049 // @023 #264: COMPARE(s0,character_I) ;test for 'I' of 'IO' command35042 // @024 #265: JUMP(Z,IO_command)// @025 #266: [bad_command]300b0 // @025 #266: CALL(send_CR) ;no valid command entered30107 // @026 #267: CALL(send_Error)3401a // @027 #268: JUMP(warm_start)// #269: ;// #270: ;Processing potential 'LD' command// #271: ;// @028 #272: [LD_command]30054 // @028 #272: CALL(read_next_char)14044 // @029 #273: COMPARE(s0,character_D) ;test for 'D' of 'LD' command35425 // @02a #274: JUMP(NZ,bad_command)30054 // @02b #275: CALL(read_next_char) ;test for LED number30093 // @02c #276: CALL(onechar_to_value)35825 // @02d #277: JUMP(C,bad_command)14008 // @02e #278: COMPARE(s0,8) ;test for number in range 0 to 735c25 // @02f #279: JUMP(NC,bad_command)01d00 // @030 #280: LOAD(sD,s0) ;convert number into memory pointer in sD18d01 // @031 #281: ADD(sD,PWM_channel0)// @032 #282: [read_duty_value]30054 // @032 #282: CALL(read_next_char) ;test for a space14020 // @033 #283: COMPARE(s0,character_space)35425 // @034 #284: JUMP(NZ,bad_command)30054 // @035 #285: CALL(read_next_char) ;read two character hex value01300 // @036 #286: LOAD(s3,s0)30054 // @037 #287: CALL(read_next_char)01200 // @038 #288: LOAD(s2,s0)30097 // @039 #289: CALL(ASCII_byte_to_hex) ;convert to value in s035825 // @03a #290: JUMP(C,bad_command)01c00 // @03b #291: LOAD(sC,s0) ;remember value30054 // @03c #292: CALL(read_next_char) ;test for carriage return to end command1400d // @03d #293: COMPARE(s0,character_CR)35425 // @03e #294: JUMP(NZ,bad_command)2fcd0 // @03f #295: STORE(sC,sD) ;store new PWM duty factor for an LED30111 // @040 #296: CALL(send_OK)3401a // @041 #297: JUMP(warm_start)// #298: ;// #299: ;Processing potential 'LD' command// #300: ;// @042 #301: [IO_command]30054 // @042 #301: CALL(read_next_char)1404f // @043 #302: COMPARE(s0,character_O) ;test for '0' of 'IO' command35425 // @044 #303: JUMP(NZ,bad_command)30054 // @045 #304: CALL(read_next_char) ;test for IO number14031 // @046 #305: COMPARE(s0,character_1) ;first number must either be '1' or '9'3504c // @047 #306: JUMP(Z,next_IO_number)14039 // @048 #307: COMPARE(s0,character_9)35425 // @049 #308: JUMP(NZ,bad_command)00d09 // @04a #309: LOAD(sD,PWM_channel8) ;IO9 is controlled by PWM channel834032 // @04b #310: JUMP(read_duty_value)// @04c #311: [next_IO_number]30054 // @04c #311: CALL(read_next_char) ;read next number for IO10 to IO1230093 // @04d #312: CALL(onechar_to_value)35825 // @04e #313: JUMP(C,bad_command)14003 // @04f #314: COMPARE(s0,3) ;test for number in range 0 to 235c25 // @050 #315: JUMP(NC,bad_command)01d00 // @051 #316: LOAD(sD,s0) ;convert number into memory pointer in sD18d0a // @052 #317: ADD(sD,PWM_channel9)34032 // @053 #318: JUMP(read_duty_value)// #319: ;// #320: ;Read next character from scratch pad memory// #321: ;// @054 #322: [read_next_char]18e01 // @054 #322: ADD(sE,1)070e0 // @055 #323: FETCH(s0,sE) ;test for space2a000 // @056 #324: RETURN// #325: ;// #326: ;// #327: ;// #328: ;**************************************************************************************// #329: ; UART communication routines// #330: ;**************************************************************************************// #331: ;// #332: ; Read one character from the UART// #333: ;// #334: ; Character read will be returned in a register called 'UART_data'.// #335: ;// #336: ; The routine first tests the receiver FIFO buffer to see if data is present.// #337: ; If the FIFO is empty, the routine waits until there is a character to read.// #338: ; As this could take any amount of time the wait loop could include a call to a// #339: ; subroutine which performs a useful function.// #340: ;// #341: ;// #342: ; Registers used s0 and UART_data// #343: ;// @057 #344: [read_from_UART]04000 // @057 #344: INPUT(s0,status_port) ;test Rx_FIFO buffer12004 // @058 #345: TEST(s0,rx_data_present) ;wait if empty3545b // @059 #346: JUMP(NZ,read_character)34057 // @05a #347: JUMP(read_from_UART)// @05b #348: [read_character]04f01 // @05b #348: INPUT(UART_data,UART_read_port) ;read from FIFO2a000 // @05c #349: RETURN// #350: ;// #351: ;// #352: ;// #353: ; Transmit one character to the UART// #354: ;// #355: ; Character supplied in register called 'UART_data'.// #356: ;// #357: ; The routine first tests the transmit FIFO buffer to see if it is full.// #358: ; If the FIFO is full, then the routine waits until it there is space.// #359: ;// #360: ; Registers used s0// #361: ;// @05d #362: [send_to_UART]04000 // @05d #362: INPUT(s0,status_port) ;test Tx_FIFO buffer12002 // @05e #363: TEST(s0,tx_full) ;wait if full35061 // @05f #364: JUMP(Z,UART_write)3405d // @060 #365: JUMP(send_to_UART)// @061 #366: [UART_write]2cf20 // @061 #366: OUTPUT(UART_data,UART_write_port)2a000 // @062 #367: RETURN// #368: ;// #369: ;// #370: ;// #371: ;// #372: ;Receive ASCII string from UART// #373: ;// #374: ;An ASCII string will be read from the UART and stored in scratch pad memory// #375: ;commencing at the location specified by a constant named 'string_start'.// #376: ;The string will have a maximum length of 16 characters including a// #377: ;carriage return (0D) denoting the end of the string.// #378: ;// #379: ;As each character is read, it is echoed to the UART transmitter.// #380: ;Some minor editing is supported using backspace (BS=08) which is used// #381: ;to adjust what is stored in scratch pad memory and adjust the display// #382: ;on the terminal screen using characters sent to the UART transmitter.// #383: ;// #384: ;A test is made for the receiver FIFO becoming full. A full status is treated as// #385: ;a potential error situation and will result in a 'Overflow Error' message being// #386: ;transmitted to the UART, the receiver FIFO being purged of all data and an// #387: ;empty string being stored (carriage return at first location).// #388: ;// #389: ;Registers used s0, s1, s2 and 'UART_data'.// #390: ;// @063 #391: [receive_string]00130 // @063 #391: LOAD(s1,string_start) ;locate start of string01210 // @064 #392: LOAD(s2,s1) ;compute 16 character address18210 // @065 #393: ADD(s2,16)// @066 #394: [receive_full_test]04000 // @066 #394: INPUT(s0,status_port) ;test Rx_FIFO buffer for full12010 // @067 #395: TEST(s0,rx_full)3547c // @068 #396: JUMP(NZ,read_error)30057 // @069 #397: CALL(read_from_UART) ;obtain and echo character3005d // @06a #398: CALL(send_to_UART)2ff10 // @06b #399: STORE(UART_data,s1) ;write to memory14f0d // @06c #400: COMPARE(UART_data,character_CR) ;test for end of string2b000 // @06d #401: RETURN(Z)14f08 // @06e #402: COMPARE(UART_data,character_BS) ;test for back space35074 // @06f #403: JUMP(Z,BS_edit)18101 // @070 #404: ADD(s1,1) ;increment memory pointer15120 // @071 #405: COMPARE(s1,s2) ;test for pointer exceeding 16 characters35466 // @072 #406: JUMP(NZ,receive_full_test) ;next character300b6 // @073 #407: CALL(send_backspace) ;hold end of string position on terminal display// @074 #408: [BS_edit]1c101 // @074 #408: SUB(s1,1) ;memory pointer back one14130 // @075 #409: COMPARE(s1,string_start) ;test for under flow3587a // @076 #410: JUMP(C,string_start_again)300b3 // @077 #411: CALL(send_space) ;clear character at current position300b6 // @078 #412: CALL(send_backspace) ;position cursor34066 // @079 #413: JUMP(receive_full_test) ;next character// @07a #414: [string_start_again]300f3 // @07a #414: CALL(send_greater_than) ;restore '>' at prompt34063 // @07b #415: JUMP(receive_string) ;begin again// #416: ;Receiver buffer overflow condition// @07c #417: [read_error]300b0 // @07c #417: CALL(send_CR) ;Transmit error message2ef30 // @07d #418: STORE(UART_data,string_start) ;empty string in memory (start with CR)300f6 // @07e #419: CALL(send_Overflow_Error)300b0 // @07f #420: CALL(send_CR)// @080 #421: [clear_UART_Rx_loop]04000 // @080 #421: INPUT(s0,status_port) ;test Rx_FIFO buffer for data12004 // @081 #422: TEST(s0,rx_data_present)2b000 // @082 #423: RETURN(Z) ;finish when buffer is empty04f01 // @083 #424: INPUT(UART_data,UART_read_port) ;read from FIFO and ignore34080 // @084 #425: JUMP(clear_UART_Rx_loop)// #426: ;// #427: ;// #428: ;**************************************************************************************// #429: ; Useful ASCII conversion and handling routines// #430: ;**************************************************************************************// #431: ;// #432: ;// #433: ;// #434: ; Convert character to upper case// #435: ;// #436: ; The character supplied in register s0.// #437: ; If the character is in the range 'a' to 'z', it is converted// #438: ; to the equivalent upper case character in the range 'A' to 'Z'.// #439: ; All other characters remain unchanged.// #440: ;// #441: ; Registers used s0.// #442: ;// @085 #443: [upper_case]14061 // @085 #443: COMPARE(s0,97) ;eliminate character codes below 'a' (61 hex)2b800 // @086 #444: RETURN(C)1407b // @087 #445: COMPARE(s0,123) ;eliminate character codes above 'z' (7A hex)2bc00 // @088 #446: RETURN(NC)0a0df // @089 #447: AND(s0,DF) ;mask bit5 to convert to upper case2a000 // @08a #448: RETURN// #449: ;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?