adc_ctrl.rmh

来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 1,582 行 · 第 1/5 页

RMH
1,582
字号
// #1004: ;Convert hexadecimal value provided in register s0 into ASCII character// #1005: ;// #1006: ;Register used s0// #1007: ;// @194 #1008: [hex_to_ASCII]1c00a // @194 #1008: SUB(s0,10) ;test if value is in range 0 to 935997 // @195 #1009: JUMP(C,number_char)18007 // @196 #1010: ADD(s0,7) ;ASCII char A to F in range 41 to 46// @197 #1011: [number_char]1803a // @197 #1011: ADD(s0,58) ;ASCII char 0 to 9 in range 30 to 402a000 // @198 #1012: RETURN// #1013: ;// #1014: ;// #1015: ;Display the two character HEX value of the register contents 's0' on// #1016: ;the LCD display at the current cursor position.// #1017: ;// #1018: ;Registers used s0, s1, s2, s4, s5, s6// #1019: ;// @199 #1020: [disp_hex_byte]30188 // @199 #1020: CALL(hex_byte_to_ASCII)01610 // @19a #1021: LOAD(s6,s1) ;remember lower hex character01520 // @19b #1022: LOAD(s5,s2) ;display upper hex character301d1 // @19c #1023: CALL(LCD_write_data)01560 // @19d #1024: LOAD(s5,s6) ;display lower hex character301d1 // @19e #1025: CALL(LCD_write_data)2a000 // @19f #1026: RETURN// #1027: ;// #1028: ;// #1029: ;**************************************************************************************// #1030: ;Software delay routines// #1031: ;**************************************************************************************// #1032: ;// #1033: ;// #1034: ;// #1035: ;Delay of 1us.// #1036: ;// #1037: ;Constant value defines reflects the clock applied to KCPSM3. Every instruction// #1038: ;executes in 2 clock cycles making the calculation highly predictable. The '6' in// #1039: ;the following equation even allows for 'CALL delay_1us' instruction in the initiating code.// #1040: ;// #1041: ; delay_1us_constant =  (clock_rate - 6)/4       Where 'clock_rate' is in MHz// #1042: ;// #1043: ;Registers used s0// #1044: ;// @1a0 #1045: [delay_1us]0000b // @1a0 #1045: LOAD(s0,delay_1us_constant)// @1a1 #1046: [wait_1us]1c001 // @1a1 #1046: SUB(s0,1)355a1 // @1a2 #1047: JUMP(NZ,wait_1us)2a000 // @1a3 #1048: RETURN// #1049: ;// #1050: ;Delay of 40us.// #1051: ;// #1052: ;Registers used s0, s1// #1053: ;// @1a4 #1054: [delay_40us]00128 // @1a4 #1054: LOAD(s1,40) ;40 x 1us = 40us// @1a5 #1055: [wait_40us]301a0 // @1a5 #1055: CALL(delay_1us)1c101 // @1a6 #1056: SUB(s1,1)355a5 // @1a7 #1057: JUMP(NZ,wait_40us)2a000 // @1a8 #1058: RETURN// #1059: ;// #1060: ;// #1061: ;Delay of 1ms.// #1062: ;// #1063: ;Registers used s0, s1, s2// #1064: ;// @1a9 #1065: [delay_1ms]00219 // @1a9 #1065: LOAD(s2,25) ;25 x 40us = 1ms// @1aa #1066: [wait_1ms]301a4 // @1aa #1066: CALL(delay_40us)1c201 // @1ab #1067: SUB(s2,1)355aa // @1ac #1068: JUMP(NZ,wait_1ms)2a000 // @1ad #1069: RETURN// #1070: ;// #1071: ;Delay of 20ms.// #1072: ;// #1073: ;Delay of 20ms used during initialisation.// #1074: ;// #1075: ;Registers used s0, s1, s2, s3// #1076: ;// @1ae #1077: [delay_20ms]00314 // @1ae #1077: LOAD(s3,20) ;20 x 1ms = 20ms// @1af #1078: [wait_20ms]301a9 // @1af #1078: CALL(delay_1ms)1c301 // @1b0 #1079: SUB(s3,1)355af // @1b1 #1080: JUMP(NZ,wait_20ms)2a000 // @1b2 #1081: RETURN// #1082: ;// #1083: ;Delay of approximately 1 second.// #1084: ;// #1085: ;Registers used s0, s1, s2, s3, s4// #1086: ;// @1b3 #1087: [delay_1s]00432 // @1b3 #1087: LOAD(s4,50) ;50 x 20ms = 1000ms// @1b4 #1088: [wait_1s]301ae // @1b4 #1088: CALL(delay_20ms)1c401 // @1b5 #1089: SUB(s4,1)355b4 // @1b6 #1090: JUMP(NZ,wait_1s)2a000 // @1b7 #1091: RETURN// #1092: ;// #1093: ;// #1094: ;// #1095: ;**************************************************************************************// #1096: ;LCD Character Module Routines// #1097: ;**************************************************************************************// #1098: ;// #1099: ;LCD module is a 16 character by 2 line display but all displays are very similar// #1100: ;The 4-wire data interface will be used (DB4 to DB7).// #1101: ;// #1102: ;The LCD modules are relatively slow and software delay loops are used to slow down// #1103: ;KCPSM3 adequately for the LCD to communicate. The delay routines are provided in// #1104: ;a different section (see above in this case).// #1105: ;// #1106: ;// #1107: ;Pulse LCD enable signal 'E' high for greater than 230ns (1us is used).// #1108: ;// #1109: ;Register s4 should define the current state of the LCD output port.// #1110: ;// #1111: ;Registers used s0, s4// #1112: ;// @1b8 #1113: [LCD_pulse_E]0e401 // @1b8 #1113: XOR(s4,LCD_E) ;E=12c440 // @1b9 #1114: OUTPUT(s4,LCD_output_port)301a0 // @1ba #1115: CALL(delay_1us)0e401 // @1bb #1116: XOR(s4,LCD_E) ;E=02c440 // @1bc #1117: OUTPUT(s4,LCD_output_port)2a000 // @1bd #1118: RETURN// #1119: ;// #1120: ;Write 4-bit instruction to LCD display.// #1121: ;// #1122: ;The 4-bit instruction should be provided in the upper 4-bits of register s4.// #1123: ;Note that this routine does not release the master enable but as it is only// #1124: ;used during initialisation and as part of the 8-bit instruction write it// #1125: ;should be acceptable.// #1126: ;// #1127: ;Registers used s4// #1128: ;// @1be #1129: [LCD_write_inst4]0a4f8 // @1be #1129: AND(s4,F8) ;Enable=1 RS=0 Instruction, RW=0 Write, E=02c440 // @1bf #1130: OUTPUT(s4,LCD_output_port) ;set up RS and RW >40ns before enable pulse301b8 // @1c0 #1131: CALL(LCD_pulse_E)2a000 // @1c1 #1132: RETURN// #1133: ;// #1134: ;// #1135: ;Write 8-bit instruction to LCD display.// #1136: ;// #1137: ;The 8-bit instruction should be provided in register s5.// #1138: ;Instructions are written using the following sequence// #1139: ; Upper nibble// #1140: ; wait >1us// #1141: ; Lower nibble// #1142: ; wait >40us// #1143: ;// #1144: ;Registers used s0, s1, s4, s5// #1145: ;// @1c2 #1146: [LCD_write_inst8]01450 // @1c2 #1146: LOAD(s4,s5)0a4f0 // @1c3 #1147: AND(s4,F0) ;Enable=0 RS=0 Instruction, RW=0 Write, E=00c408 // @1c4 #1148: OR(s4,LCD_drive) ;Enable=1301be // @1c5 #1149: CALL(LCD_write_inst4) ;write upper nibble301a0 // @1c6 #1150: CALL(delay_1us) ;wait >1us01450 // @1c7 #1151: LOAD(s4,s5) ;select lower nibble with20407 // @1c8 #1152: SL1(s4) ;Enable=120406 // @1c9 #1153: SL0(s4) ;RS=0 Instruction20406 // @1ca #1154: SL0(s4) ;RW=0 Write20406 // @1cb #1155: SL0(s4) ;E=0301be // @1cc #1156: CALL(LCD_write_inst4) ;write lower nibble301a4 // @1cd #1157: CALL(delay_40us) ;wait >40us004f0 // @1ce #1158: LOAD(s4,F0) ;Enable=0 RS=0 Instruction, RW=0 Write, E=02c440 // @1cf #1159: OUTPUT(s4,LCD_output_port) ;Release master enable2a000 // @1d0 #1160: RETURN// #1161: ;// #1162: ;// #1163: ;// #1164: ;Write 8-bit data to LCD display.// #1165: ;// #1166: ;The 8-bit data should be provided in register s5.// #1167: ;Data bytes are written using the following sequence// #1168: ; Upper nibble// #1169: ; wait >1us// #1170: ; Lower nibble// #1171: ; wait >40us// #1172: ;// #1173: ;Registers used s0, s1, s4, s5// #1174: ;// @1d1 #1175: [LCD_write_data]01450 // @1d1 #1175: LOAD(s4,s5)0a4f0 // @1d2 #1176: AND(s4,F0) ;Enable=0 RS=0 Instruction, RW=0 Write, E=00c40c // @1d3 #1177: OR(s4,12) ;Enable=1 RS=1 Data, RW=0 Write, E=02c440 // @1d4 #1178: OUTPUT(s4,LCD_output_port) ;set up RS and RW >40ns before enable pulse301b8 // @1d5 #1179: CALL(LCD_pulse_E) ;write upper nibble301a0 // @1d6 #1180: CALL(delay_1us) ;wait >1us01450 // @1d7 #1181: LOAD(s4,s5) ;select lower nibble with20407 // @1d8 #1182: SL1(s4) ;Enable=120407 // @1d9 #1183: SL1(s4) ;RS=1 Data20406 // @1da #1184: SL0(s4) ;RW=0 Write20406 // @1db #1185: SL0(s4) ;E=02c440 // @1dc #1186: OUTPUT(s4,LCD_output_port) ;set up RS and RW >40ns before enable pulse301b8 // @1dd #1187: CALL(LCD_pulse_E) ;write lower nibble301a4 // @1de #1188: CALL(delay_40us) ;wait >40us004f0 // @1df #1189: LOAD(s4,F0) ;Enable=0 RS=0 Instruction, RW=0 Write, E=02c440 // @1e0 #1190: OUTPUT(s4,LCD_output_port) ;Release master enable2a000 // @1e1 #1191: RETURN// #1192: ;// #1193: ;// #1194: ;// #1195: ;// #1196: ;Read 8-bit data from LCD display.// #1197: ;// #1198: ;The 8-bit data will be read from the current LCD memory address// #1199: ;and will be returned in register s5.// #1200: ;It is advisable to set the LCD address (cursor position) before// #1201: ;using the data read for the first time otherwise the display may// #1202: ;generate invalid data on the first read.// #1203: ;// #1204: ;Data bytes are read using the following sequence// #1205: ; Upper nibble// #1206: ; wait >1us// #1207: ; Lower nibble// #1208: ; wait >40us// #1209: ;// #1210: ;Registers used s0, s1, s4, s5// #1211: ;// @1e2 #1212: [LCD_read_data8]0040e // @1e2 #1212: LOAD(s4,14) ;Enable=1 RS=1 Data, RW=1 Read, E=02c440 // @1e3 #1213: OUTPUT(s4,LCD_output_port) ;set up RS and RW >40ns before enable pulse0e401 // @1e4 #1214: XOR(s4,LCD_E) ;E=12c440 // @1e5 #1215: OUTPUT(s4,LCD_output_port)301a0 // @1e6 #1216: CALL(delay_1us) ;wait >260ns to access data04502 // @1e7 #1217: INPUT(s5,LCD_input_port) ;read upper nibble0e401 // @1e8 #1218: XOR(s4,LCD_E) ;E=02c440 // @1e9 #1219: OUTPUT(s4,LCD_output_port)301a0 // @1ea #1220: CALL(delay_1us) ;wait >1us0e401 // @1eb #1221: XOR(s4,LCD_E) ;E=12c440 // @1ec #1222: OUTPUT(s4,LCD_output_port)301a0 // @1ed #1223: CALL(delay_1us) ;wait >260ns to access data04002 // @1ee #1224: INPUT(s0,LCD_input_port) ;read lower nibble0e401 // @1ef #1225: XOR(s4,LCD_E) ;E=02c440 // @1f0 #1226: OUTPUT(s4,LCD_output_port)0a5f0 // @1f1 #1227: AND(s5,F0) ;merge upper and lower nibbles2000e // @1f2 #1228: SR0(s0)2000e // @1f3 #1229: SR0(s0)2000e // @1f4 #1230: SR0(s0)2000e // @1f5 #1231: SR0(s0)0d500 // @1f6 #1232: OR(s5,s0)00404 // @1f7 #1233: LOAD(s4,4) ;Enable=0 RS=1 Data, RW=0 Write, E=02c440 // @1f8 #1234: OUTPUT(s4,LCD_output_port) ;Stop reading 5V device and release master enable301a4 // @1f9 #1235: CALL(delay_40us) ;wait >40us2a000 // @1fa #1236: RETURN// #1237: ;// #1238: ;// #1239: ;Reset and initialise display to communicate using 4-bit data mode// #1240: ;Includes routine to clear the display.// #1241: ;// #1242: ;Requires the 4-bit instructions 3,3,3,2 to be sent with suitable delays// #1243: ;following by the 8-bit instructions to set up the display.// #1244: ;// #1245: ;  28 = '001' Function set, '0' 4-bit mode, '1' 2-line, '0' 5x7 dot matrix, 'xx'// #1246: ;  06 = '000001' Entry mode, '1' increment, '0' no display shift// #1247: ;  0C = '00001' Display control, '1' display on, '0' cursor off, '0' cursor blink off// #1248: ;  01 = '00000001' Display clear// #1249: ;// #1250: ;Registers used s0, s1, s2, s3, s4// #1251: ;// @1fb #1252: [LCD_reset]301ae // @1fb #1252: CALL(delay_20ms) ;wait more that 15ms for display to be ready00430 // @1fc #1253: LOAD(s4,48)301be // @1fd #1254: CALL(LCD_write_inst4) ;send '3'301ae // @1fe #1255: CALL(delay_20ms) ;wait >4.1ms301be // @1ff #1256: CALL(LCD_write_inst4) ;send '3'301a9 // @200 #1257: CALL(delay_1ms) ;wait >100us301be // @201 #1258: CALL(LCD_write_inst4) ;send '3'301a4 // @202 #1259: CALL(delay_40us) ;wait >40us00420 // @203 #1260: LOAD(s4,32)301be // @204 #1261: CALL(LCD_write_inst4) ;send '2'301a4 // @205 #1262: CALL(delay_40us) ;wait >40us00528 // @206 #1263: LOAD(s5,40) ;Function set301c2 // @207 #1264: CALL(LCD_write_inst8)00506 // @208 #1265: LOAD(s5,6) ;Entry mode301c2 // @209 #1266: CALL(LCD_write_inst8)0050c // @20a #1267: LOAD(s5,12) ;Display control301c2 // @20b #1268: CALL(LCD_write_inst8)// @20c #1269: [LCD_clear]00501 // @20c #1269: LOAD(s5,1) ;Display clear301c2 // @20d #1270: CALL(LCD_write_inst8)301a9 // @20e #1271: CALL(delay_1ms) ;wait >1.64ms for display to clear301a9 // @20f #1272: CALL(delay_1ms)2a000 // @210 #1273: RETURN// #1274: ;// #1275: ;Position the cursor ready for characters to be written.// #1276: ;The display is formed of 2 lines of 16 characters and each// #1277: ;position has a corresponding address as indicated below.// #1278: ;// #1279: ;                   Character position// #1280: ;           0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15// #1281: ;// #1282: ; Line 1 - 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F// #1283: ; Line 2 - C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF// #1284: ;// #1285: ;This routine will set the cursor position using the value provided// #1286: ;in register s5. The upper nibble will define the line and the lower// #1287: ;nibble the character position on the line.// #1288: ; Example s5 = 2B will position the cursor on line 2 position 11// #1289: ;// #1290: ;Registers used s0, s1, s2, s3, s4// #1291: ;// @211 #1292: [LCD_cursor]12510 // @211 #1292: TEST(s5,16) ;test for line 135217 // @212 #1293: JUMP(Z,set_line2)0a50f // @213 #1294: AND(s5,15) ;make address in range 80 to 8F for line 10c580 // @214 #1295: OR(s5,128)301c2 // @215 #1296: CALL(LCD_write_inst8) 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?