fc_ctrl.rmh
来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 1,493 行 · 第 1/4 页
RMH
1,493 行
// #849: ;// @1b0 #850: [delay_20ms]00314 // @1b0 #850: LOAD(s3,20) ;20 x 1ms = 20ms// @1b1 #851: [wait_20ms]301ab // @1b1 #851: CALL(delay_1ms)1c301 // @1b2 #852: SUB(s3,1)355b1 // @1b3 #853: JUMP(NZ,wait_20ms)2a000 // @1b4 #854: RETURN// #855: ;// #856: ;Delay of approximately 1 second.// #857: ;// #858: ;Registers used s0, s1, s2, s3, s4// #859: ;// @1b5 #860: [delay_1s]00432 // @1b5 #860: LOAD(s4,50) ;50 x 20ms = 1000ms// @1b6 #861: [wait_1s]301b0 // @1b6 #861: CALL(delay_20ms)1c401 // @1b7 #862: SUB(s4,1)355b6 // @1b8 #863: JUMP(NZ,wait_1s)2a000 // @1b9 #864: RETURN// #865: ;// #866: ;// #867: ;// #868: ;**************************************************************************************// #869: ;LCD Character Module Routines// #870: ;**************************************************************************************// #871: ;// #872: ;LCD module is a 16 character by 2 line display but all displays are very similar// #873: ;The 4-wire data interface will be used (DB4 to DB7).// #874: ;// #875: ;The LCD modules are relatively slow and software delay loops are used to slow down// #876: ;KCPSM3 adequately for the LCD to communicate. The delay routines are provided in// #877: ;a different section (see above in this case).// #878: ;// #879: ;// #880: ;Pulse LCD enable signal 'E' high for greater than 230ns (1us is used).// #881: ;// #882: ;Register s4 should define the current state of the LCD output port.// #883: ;// #884: ;Registers used s0, s4// #885: ;// @1ba #886: [LCD_pulse_E]0e401 // @1ba #886: XOR(s4,LCD_E) ;E=12c404 // @1bb #887: OUTPUT(s4,LCD_output_port)301a2 // @1bc #888: CALL(delay_1us)0e401 // @1bd #889: XOR(s4,LCD_E) ;E=02c404 // @1be #890: OUTPUT(s4,LCD_output_port)2a000 // @1bf #891: RETURN// #892: ;// #893: ;Write 4-bit instruction to LCD display.// #894: ;// #895: ;The 4-bit instruction should be provided in the upper 4-bits of register s4.// #896: ;Note that this routine does not release the master enable but as it is only// #897: ;used during initialisation and as part of the 8-bit instruction write it// #898: ;should be acceptable.// #899: ;// #900: ;Registers used s4// #901: ;// @1c0 #902: [LCD_write_inst4]0a4f8 // @1c0 #902: AND(s4,F8) ;Enable=1 RS=0 Instruction, RW=0 Write, E=02c404 // @1c1 #903: OUTPUT(s4,LCD_output_port) ;set up RS and RW >40ns before enable pulse301ba // @1c2 #904: CALL(LCD_pulse_E)2a000 // @1c3 #905: RETURN// #906: ;// #907: ;// #908: ;Write 8-bit instruction to LCD display.// #909: ;// #910: ;The 8-bit instruction should be provided in register s5.// #911: ;Instructions are written using the following sequence// #912: ; Upper nibble// #913: ; wait >1us// #914: ; Lower nibble// #915: ; wait >40us// #916: ;// #917: ;Registers used s0, s1, s4, s5// #918: ;// @1c4 #919: [LCD_write_inst8]01450 // @1c4 #919: LOAD(s4,s5)0a4f0 // @1c5 #920: AND(s4,F0) ;Enable=0 RS=0 Instruction, RW=0 Write, E=00c408 // @1c6 #921: OR(s4,LCD_drive) ;Enable=1301c0 // @1c7 #922: CALL(LCD_write_inst4) ;write upper nibble301a2 // @1c8 #923: CALL(delay_1us) ;wait >1us01450 // @1c9 #924: LOAD(s4,s5) ;select lower nibble with20407 // @1ca #925: SL1(s4) ;Enable=120406 // @1cb #926: SL0(s4) ;RS=0 Instruction20406 // @1cc #927: SL0(s4) ;RW=0 Write20406 // @1cd #928: SL0(s4) ;E=0301c0 // @1ce #929: CALL(LCD_write_inst4) ;write lower nibble301a6 // @1cf #930: CALL(delay_40us) ;wait >40us004f0 // @1d0 #931: LOAD(s4,F0) ;Enable=0 RS=0 Instruction, RW=0 Write, E=02c404 // @1d1 #932: OUTPUT(s4,LCD_output_port) ;Release master enable2a000 // @1d2 #933: RETURN// #934: ;// #935: ;// #936: ;// #937: ;Write 8-bit data to LCD display.// #938: ;// #939: ;The 8-bit data should be provided in register s5.// #940: ;Data bytes are written using the following sequence// #941: ; Upper nibble// #942: ; wait >1us// #943: ; Lower nibble// #944: ; wait >40us// #945: ;// #946: ;Registers used s0, s1, s4, s5// #947: ;// @1d3 #948: [LCD_write_data]01450 // @1d3 #948: LOAD(s4,s5)0a4f0 // @1d4 #949: AND(s4,F0) ;Enable=0 RS=0 Instruction, RW=0 Write, E=00c40c // @1d5 #950: OR(s4,12) ;Enable=1 RS=1 Data, RW=0 Write, E=02c404 // @1d6 #951: OUTPUT(s4,LCD_output_port) ;set up RS and RW >40ns before enable pulse301ba // @1d7 #952: CALL(LCD_pulse_E) ;write upper nibble301a2 // @1d8 #953: CALL(delay_1us) ;wait >1us01450 // @1d9 #954: LOAD(s4,s5) ;select lower nibble with20407 // @1da #955: SL1(s4) ;Enable=120407 // @1db #956: SL1(s4) ;RS=1 Data20406 // @1dc #957: SL0(s4) ;RW=0 Write20406 // @1dd #958: SL0(s4) ;E=02c404 // @1de #959: OUTPUT(s4,LCD_output_port) ;set up RS and RW >40ns before enable pulse301ba // @1df #960: CALL(LCD_pulse_E) ;write lower nibble301a6 // @1e0 #961: CALL(delay_40us) ;wait >40us004f0 // @1e1 #962: LOAD(s4,F0) ;Enable=0 RS=0 Instruction, RW=0 Write, E=02c404 // @1e2 #963: OUTPUT(s4,LCD_output_port) ;Release master enable2a000 // @1e3 #964: RETURN// #965: ;// #966: ;// #967: ;// #968: ;// #969: ;Read 8-bit data from LCD display.// #970: ;// #971: ;The 8-bit data will be read from the current LCD memory address// #972: ;and will be returned in register s5.// #973: ;It is advisable to set the LCD address (cursor position) before// #974: ;using the data read for the first time otherwise the display may// #975: ;generate invalid data on the first read.// #976: ;// #977: ;Data bytes are read using the following sequence// #978: ; Upper nibble// #979: ; wait >1us// #980: ; Lower nibble// #981: ; wait >40us// #982: ;// #983: ;Registers used s0, s1, s4, s5// #984: ;// @1e4 #985: [LCD_read_data8]0040e // @1e4 #985: LOAD(s4,14) ;Enable=1 RS=1 Data, RW=1 Read, E=02c404 // @1e5 #986: OUTPUT(s4,LCD_output_port) ;set up RS and RW >40ns before enable pulse0e401 // @1e6 #987: XOR(s4,LCD_E) ;E=12c404 // @1e7 #988: OUTPUT(s4,LCD_output_port)301a2 // @1e8 #989: CALL(delay_1us) ;wait >260ns to access data04509 // @1e9 #990: INPUT(s5,LCD_input_port) ;read upper nibble0e401 // @1ea #991: XOR(s4,LCD_E) ;E=02c404 // @1eb #992: OUTPUT(s4,LCD_output_port)301a2 // @1ec #993: CALL(delay_1us) ;wait >1us0e401 // @1ed #994: XOR(s4,LCD_E) ;E=12c404 // @1ee #995: OUTPUT(s4,LCD_output_port)301a2 // @1ef #996: CALL(delay_1us) ;wait >260ns to access data04009 // @1f0 #997: INPUT(s0,LCD_input_port) ;read lower nibble0e401 // @1f1 #998: XOR(s4,LCD_E) ;E=02c404 // @1f2 #999: OUTPUT(s4,LCD_output_port)0a5f0 // @1f3 #1000: AND(s5,F0) ;merge upper and lower nibbles2000e // @1f4 #1001: SR0(s0)2000e // @1f5 #1002: SR0(s0)2000e // @1f6 #1003: SR0(s0)2000e // @1f7 #1004: SR0(s0)0d500 // @1f8 #1005: OR(s5,s0)00404 // @1f9 #1006: LOAD(s4,4) ;Enable=0 RS=1 Data, RW=0 Write, E=02c404 // @1fa #1007: OUTPUT(s4,LCD_output_port) ;Stop reading 5V device and release master enable301a6 // @1fb #1008: CALL(delay_40us) ;wait >40us2a000 // @1fc #1009: RETURN// #1010: ;// #1011: ;// #1012: ;Reset and initialise display to communicate using 4-bit data mode// #1013: ;Includes routine to clear the display.// #1014: ;// #1015: ;Requires the 4-bit instructions 3,3,3,2 to be sent with suitable delays// #1016: ;following by the 8-bit instructions to set up the display.// #1017: ;// #1018: ; 28 = '001' Function set, '0' 4-bit mode, '1' 2-line, '0' 5x7 dot matrix, 'xx'// #1019: ; 06 = '000001' Entry mode, '1' increment, '0' no display shift// #1020: ; 0C = '00001' Display control, '1' display on, '0' cursor off, '0' cursor blink off// #1021: ; 01 = '00000001' Display clear// #1022: ;// #1023: ;Registers used s0, s1, s2, s3, s4// #1024: ;// @1fd #1025: [LCD_reset]301b0 // @1fd #1025: CALL(delay_20ms) ;wait more that 15ms for display to be ready00430 // @1fe #1026: LOAD(s4,48)301c0 // @1ff #1027: CALL(LCD_write_inst4) ;send '3'301b0 // @200 #1028: CALL(delay_20ms) ;wait >4.1ms301c0 // @201 #1029: CALL(LCD_write_inst4) ;send '3'301ab // @202 #1030: CALL(delay_1ms) ;wait >100us301c0 // @203 #1031: CALL(LCD_write_inst4) ;send '3'301a6 // @204 #1032: CALL(delay_40us) ;wait >40us00420 // @205 #1033: LOAD(s4,32)301c0 // @206 #1034: CALL(LCD_write_inst4) ;send '2'301a6 // @207 #1035: CALL(delay_40us) ;wait >40us00528 // @208 #1036: LOAD(s5,40) ;Function set301c4 // @209 #1037: CALL(LCD_write_inst8)00506 // @20a #1038: LOAD(s5,6) ;Entry mode301c4 // @20b #1039: CALL(LCD_write_inst8)0050c // @20c #1040: LOAD(s5,12) ;Display control301c4 // @20d #1041: CALL(LCD_write_inst8)// @20e #1042: [LCD_clear]00501 // @20e #1042: LOAD(s5,1) ;Display clear301c4 // @20f #1043: CALL(LCD_write_inst8)301ab // @210 #1044: CALL(delay_1ms) ;wait >1.64ms for display to clear301ab // @211 #1045: CALL(delay_1ms)2a000 // @212 #1046: RETURN// #1047: ;// #1048: ;Position the cursor ready for characters to be written.// #1049: ;The display is formed of 2 lines of 16 characters and each// #1050: ;position has a corresponding address as indicated below.// #1051: ;// #1052: ; Character position// #1053: ; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15// #1054: ;// #1055: ; Line 1 - 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F// #1056: ; Line 2 - C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF// #1057: ;// #1058: ;This routine will set the cursor position using the value provided// #1059: ;in register s5. The upper nibble will define the line and the lower// #1060: ;nibble the character position on the line.// #1061: ; Example s5 = 2B will position the cursor on line 2 position 11// #1062: ;// #1063: ;Registers used s0, s1, s2, s3, s4// #1064: ;// @213 #1065: [LCD_cursor]12510 // @213 #1065: TEST(s5,16) ;test for line 135219 // @214 #1066: JUMP(Z,set_line2)0a50f // @215 #1067: AND(s5,15) ;make address in range 80 to 8F for line 10c580 // @216 #1068: OR(s5,128)301c4 // @217 #1069: CALL(LCD_write_inst8) ;instruction write to set cursor2a000 // @218 #1070: RETURN// @219 #1071: [set_line2]0a50f // @219 #1071: AND(s5,15) ;make address in range C0 to CF for line 20c5c0 // @21a #1072: OR(s5,C0)301c4 // @21b #1073: CALL(LCD_write_inst8) ;instruction write to set cursor2a000 // @21c #1074: RETURN// #1075: ;// #1076: ;// #1077: ;// #1078: ;**************************************************************************************// #1079: ;Interrupt Service Routine// #1080: ;**************************************************************************************// #1081: ;// #1082: ;// #1083: ;Each interrupt means that there is a new count value to be read.// #1084: ;However the first 4 interrupts are ignored other than to clear the counter to// #1085: ;ensure that even the first reading is for one complete period.// #1086: ;// #1087: ;After reading the active counter, all calculations are performed and values stored// #1088: ;in scratch pad memory are updated to reflect the new values.// #1089: ;// #1090: ;Registers are preserved and restored by the ISR so main program is unaffected.// #1091: ;// @21d #1092: [ISR]2e030 // @21d #1092: STORE(s0,preserve_s0) ;preserve registers2e131 // @21e #1093: STORE(s1,preserve_s1)2e232 // @21f #1094: STORE(s2,preserve_s2)2e333 // @220 #1095: STORE(s3,preserve_s3)2e434 // @221 #1096: STORE(s4,preserve_s4)2e535 // @222 #1097: STORE(s5,preserve_s5)2e636 // @223 #1098: STORE(s6,preserve_s6)2e737 // @224 #1099: STORE(s7,preserve_s7)2e838 // @225 #1100: STORE(s8,preserve_s8)2e939 // @226 #1101: STORE(s9,preserve_s9)2ea3a // @227 #1102: STORE(sA,preserve_sA)2eb3b // @228 #1103: STORE(sB,preserve_sB)2ec3c // @229 #1104: STORE(sC,preserve_sC)2ed3d // @22a #1105: STORE(sD,preserve_sD)2ee3e // @22b #1106: STORE(sE,preserve_sE)2ef3f // @22c #1107: STORE(sF,preserve_sF)// #1108: ;// #1109: ;Ignore the first 4 interrupts except to clear the counter.// #1110: ;This will ensure a clean start up after reset.// #1111: ;06004 // @22d #1112: FETCH(s0,ISR_count) ;test to see if more that 4 interrupts have occurred14004 // @22e #1113: COMPARE(s0,4)3523c // @22f #1114: JUMP(Z,normal_isr)18001 // @230 #1115: ADD(s0,1) ;increment ISR counter until reaching 42e004 // @231 #1116: STORE(s0,ISR_count)04080 // @232 #1117: INPUT(s0,status_port) ;Check which counter to clear12010 // @233 #1118: TEST(s0,AB_switch) ;if bit0 is Low then A is counting35237 // @234 #1119: JUMP(Z,clear_B_count)// @235 #1120: [clear_A_count]00001 // @235 #1120: LOAD(s0,a_count_reset) ;clear the active counter34238 // @236 #1121: JUMP(clear_counter)// @237 #1122: [clear_B_count]00002 // @237 #1122: LOAD(s0,b_count_reset) ;clear the active counter// @238 #1123: [clear_counter]2c002 // @238 #1123: OUTPUT(s0,count_resetport) ;reset counter with pulse00000 // @239 #1124: LOAD(s0,0) ;end reset pulse to either counter2c002 // @23a #1125: OUTPUT(s0,count_resetport)34256 // @23b #1126: JUMP(restore_reg)// #1127: ;// #1128: ;Normal ISR Routine// #1129: ;// #1130: ;// #1131: ;Read the new counter value and then clear it ready to start again// #1132: ;// #1133: ;// @23c #1134: [normal_isr]04080 // @23c #1134: INPUT(s0,status_port) ;test for active counter12010 // @23d #1135: TEST(s0,AB_switch) ;if bit is low then A is counting35248 // @23e #1136: JUMP(Z,capture_B_count)// @23f #1137: [capture_A_count]000f0 // @23f #1137: LOAD(s0,F0) ;set LEDs to indicate active counter2c001 // @240 #1138: OUTPUT(s0,LED_port)04c00 // @241 #1139: INPUT(sC,A_count0_port) ;read counter A into [sF,sE,SD,sC]04d10 // @242 #1140: INPUT(sD,A_count1_port)04e20 // @243 #1141: INPUT(sE,A_count2_port)04f30 // @244 #1142: INPUT(sF,A_count3_port)00001 // @245 #1143: LOAD(s0,a_count_reset) ;reset counter A2c002 // @246 #1144: OUTPUT(s0,count_resetport)34250 // @247 #1145: JUMP(counters_read)// #1146: ;// @248 #1147: [capture_B_count]0000f // @248 #1147: LOAD(s0,15) ;set LEDs to indicate active counter2c001 // @249 #1148: OUTPUT(s0,LED_port)04c40 // @24a #1149: INPUT(sC,B_count0_port) ;read counter A into [sF,sE,SD,sC]04d50 // @24b #1150: INPUT(sD,B_count1_port)04e60 // @24c #1151: INPUT(sE,B_count2_port)04f70 // @24d #1152: INPUT(sF,B_count3_port)00002 // @24e #1153: LOAD(s0,b_count_reset) ;reset counter B2c002 // @24f #1154: OUTPUT(s0,count_resetport)// @250 #1155: [counters_read]00000 // @250 #1155: LOAD(s0,0) ;end reset pulse to either counter2c002 // @251 #1156: OUTPUT(s0,count_resetport)// #1157: ;2ec00 // @252 #1158: STORE(sC,count0) ;store new counter value2ed01 // @253 #1159: STORE(sD,count1)2ee02 // @254 #1160: STORE(sE,count2)2ef03 // @255 #1161: STORE(sF,count3)// #1162: ;// #1163: ;// #1164: ;// #1165: ;Restore registers and end ISR// #1166: ;// @256 #1167: [restore_reg]06f3f // @256 #1167: FETCH(sF,preserve_sF) ;restore registers06e3e // @257 #1168: FETCH(sE,preserve_sE)06d3d // @258 #1169: FETCH(sD,preserve_sD)06c3c // @259 #1170: FETCH(sC,preserve_sC)06b3b // @25a #1171: FETCH(sB,preserve_sB)06a3a // @25b #1172: FETCH(sA,preserve_sA)06939 // @25c #1173: FETCH(s9,preserve_s9)06838 // @25d #1174: FETCH(s8,preserve_s8)06737 // @25e #1175: FETCH(s7,preserve_s7)06636 // @25f #1176: FETCH(s6,preserve_s6)06535 // @260 #1177: FETCH(s5,preserve_s5)06434 // @261 #1178: FETCH(s4,preserve_s4)06333 // @262 #1179: FETCH(s3,preserve_s3)06232 // @263 #1180: FETCH(s2,preserve_s2)06131 // @264 #1181: FETCH(s1,preserve_s1)06030 // @265 #1182: FETCH(s0,preserve_s0)38001 // @266 #1183: RETURNI(ENABLE)// #1184: ;// #1185: ;// #1186: ;Interrupt vector// #1187: ;@3ff // #1188: ADDRESS(1023)3421d // @3ff #1189: JUMP(ISR)// #1190: ;// #1191: ;// #1192: ;**************************************************************************************// #1193: ;End of Program// #1194: ;**************************************************************************************// #1195: ;// #1196: ;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?