📄 control.rmh
字号:
// #905: ;Delay of 8us is equivalent to 200 instructions at 50MHz.// #906: ;This delay loop is formed of 27 instructions requiring 8 repetitions.00108 // @177 #907: LOAD(s1,8) ;8 (08 hex)// @178 #908: [whs_wait_8us]3019a // @178 #908: CALL(delay_1us) ;25 instructions including CALL1c101 // @179 #909: SUB(s1,1) ;decrement delay counter35578 // @17a #910: JUMP(NZ,whs_wait_8us) ;repeat until zero00001 // @17b #911: LOAD(s0,1) ;end of Low pulse2c008 // @17c #912: OUTPUT(s0,DS_wire_out_port)// #913: ;Delay of 72us is equivalent to 1800 instructions at 50MHz.// #914: ;This delay loop is formed of 27 instructions requiring 67 repetitions.00143 // @17d #915: LOAD(s1,67) ;67 (43 hex)// @17e #916: [whs_wait_72us]3019a // @17e #916: CALL(delay_1us) ;25 instructions including CALL1c101 // @17f #917: SUB(s1,1) ;decrement delay counter3557e // @180 #918: JUMP(NZ,whs_wait_72us) ;repeat until zero2a000 // @181 #919: RETURN// #920: ;// #921: ;// #922: ;// #923: ;**************************************************************************************// #924: ; Read a byte from DS2432 in regular speed mode.// #925: ;**************************************************************************************// #926: ;// #927: ; Bytes are read from the DS2432 with LSB first.// #928: ;// #929: ; The byte read will be returned in register 's3'.// #930: ;// #931: ; Registers used s0,s1,s2,s3// #932: ;// @182 #933: [read_byte_slow]00208 // @182 #933: LOAD(s2,8) ;8 bits to receive// @183 #934: [rbs_loop]30187 // @183 #934: CALL(read_bit_slow) ;read next bit LSB first1c201 // @184 #935: SUB(s2,1) ;count bits35583 // @185 #936: JUMP(NZ,rbs_loop) ;repeat until 8-bits received2a000 // @186 #937: RETURN// #938: ;// #939: ;// #940: ;// #941: ;// #942: ;**************************************************************************************// #943: ; Read a data bit sent from the DS2432 in regular speed mode.// #944: ;**************************************************************************************// #945: ;// #946: ; To read a bit, PicoBlaze must initiate the processed with an active Low pulse of// #947: ; 1 to 15us. This design generates a 4us active Low pulse for this purpose.// #948: ;// #949: ; Then DS2432 responds to the Low pulse by diving DS_wire in two differet ways// #950: ; depending on the logic level it is trying to send back.// #951: ;// #952: ; For a logic '0' the DS2432 will drive the DS-wire Low for up to 15us after// #953: ; the start of the instigating pulse. Therefore PicoBlaze must read the DS-wire// #954: ; before this time has elapsed but only after it has itself released the wire.// #955: ;// #956: ; For a logic '1' the DS2432 will do nothing and hence the DS-wire will be pulled// #957: ; High by the external resistor after PicoBlaze has released the wire. PicoBlaze// #958: ; will sample the wire and detect the High level.// #959: ;// #960: ; In this design, PicoBlaze needs to detect the logic state of the wire after// #961: ; releasing the wire at 4us. Sampling the wire too quickly would not provide// #962: ; adequate time for a High signal to be formed by the pull up resistor. However, it// #963: ; must sample the wire before 15us have elapsed and any potential Low is removed.// #964: ; This design samples the wire at 12us which is 8us after the initiation pulse ends.// #965: ;// #966: ; A further delay of 68us is then allowed for the DS2432 to stop transmitting and// #967: ; to recover. This also mean that the entire read process (slot time) is 80us.// #968: ;// #969: ; The received data bit is SHIFTED into the MSB of register 's3'. In this way// #970: ; the reception of 8-bits will shift the first bit into the LSB position of 's3'.// #971: ;// #972: ; Registers used s0,s1,s3// #973: ;// @187 #974: [read_bit_slow]00000 // @187 #974: LOAD(s0,0) ;transmit Low pulse2c008 // @188 #975: OUTPUT(s0,DS_wire_out_port)// #976: ;Delay of 4us is equivalent to 100 instructions at 50MHz.// #977: ;This delay loop is formed of 27 instructions requiring 4 repetitions.00104 // @189 #978: LOAD(s1,4) ;4 (04 hex)// @18a #979: [rbs_wait_4us]3019a // @18a #979: CALL(delay_1us) ;25 instructions including CALL1c101 // @18b #980: SUB(s1,1) ;decrement delay counter3558a // @18c #981: JUMP(NZ,rbs_wait_4us) ;repeat until zero00001 // @18d #982: LOAD(s0,1) ;end of Low pulse2c008 // @18e #983: OUTPUT(s0,DS_wire_out_port)// #984: ;Delay of 8us is equivalent to 200 instructions at 50MHz.// #985: ;This delay loop is formed of 27 instructions requiring 8 repetitions.00108 // @18f #986: LOAD(s1,8) ;8 (08 hex)// @190 #987: [rbs_wait_8us]3019a // @190 #987: CALL(delay_1us) ;25 instructions including CALL1c101 // @191 #988: SUB(s1,1) ;decrement delay counter35590 // @192 #989: JUMP(NZ,rbs_wait_8us) ;repeat until zero3015d // @193 #990: CALL(read_DS_wire) ;sample wire (carry = state)20308 // @194 #991: SRA(s3) ;shift received bit into MSB of s3// #992: ;Delay of 68us is equivalent to 1700 instructions at 50MHz.// #993: ;This delay loop is formed of 27 instructions requiring 63 repetitions.0013f // @195 #994: LOAD(s1,63) ;63 (3F hex)// @196 #995: [rbs_wait_68us]3019a // @196 #995: CALL(delay_1us) ;25 instructions including CALL1c101 // @197 #996: SUB(s1,1) ;decrement delay counter35596 // @198 #997: JUMP(NZ,rbs_wait_68us) ;repeat until zero2a000 // @199 #998: RETURN// #999: ;// #1000: ;// #1001: ;**************************************************************************************// #1002: ; Software delay routines// #1003: ;**************************************************************************************// #1004: ;// #1005: ; Delay of 1us.// #1006: ;// #1007: ; Constant value defines reflects the clock applied to KCPSM3. Every instruction// #1008: ; executes in 2 clock cycles making the calculation highly predictable. The '6' in// #1009: ; the following equation even allows for 'CALL delay_1us' instruction in the initiating code.// #1010: ;// #1011: ; delay_1us_constant = (clock_rate - 6)/4 Where 'clock_rate' is in MHz// #1012: ;// #1013: ; Register used s0// #1014: ;// @19a #1015: [delay_1us]0000b // @19a #1015: LOAD(s0,delay_1us_constant)// @19b #1016: [wait_1us]1c001 // @19b #1016: SUB(s0,1)3559b // @19c #1017: JUMP(NZ,wait_1us)2a000 // @19d #1018: RETURN// #1019: ;// #1020: ; Delay of 40us.// #1021: ;// #1022: ; Registers used s0, s1// #1023: ;// @19e #1024: [delay_40us]00128 // @19e #1024: LOAD(s1,40) ;40 x 1us = 40us// @19f #1025: [wait_40us]3019a // @19f #1025: CALL(delay_1us)1c101 // @1a0 #1026: SUB(s1,1)3559f // @1a1 #1027: JUMP(NZ,wait_40us)2a000 // @1a2 #1028: RETURN// #1029: ;// #1030: ;// #1031: ; Delay of 1ms.// #1032: ;// #1033: ; Registers used s0, s1, s2// #1034: ;// @1a3 #1035: [delay_1ms]00219 // @1a3 #1035: LOAD(s2,25) ;25 x 40us = 1ms// @1a4 #1036: [wait_1ms]3019e // @1a4 #1036: CALL(delay_40us)1c201 // @1a5 #1037: SUB(s2,1)355a4 // @1a6 #1038: JUMP(NZ,wait_1ms)2a000 // @1a7 #1039: RETURN// #1040: ;// #1041: ; Delay of 20ms.// #1042: ;// #1043: ; Registers used s0, s1, s2, s3// #1044: ;// @1a8 #1045: [delay_20ms]00314 // @1a8 #1045: LOAD(s3,20) ;20 x 1ms = 20ms// @1a9 #1046: [wait_20ms]301a3 // @1a9 #1046: CALL(delay_1ms)1c301 // @1aa #1047: SUB(s3,1)355a9 // @1ab #1048: JUMP(NZ,wait_20ms)2a000 // @1ac #1049: RETURN// #1050: ;// #1051: ; Delay of approximately 1 second.// #1052: ;// #1053: ; Registers used s0, s1, s2, s3, s4// #1054: ;// @1ad #1055: [delay_1s]00414 // @1ad #1055: LOAD(s4,20) ;50 x 20ms = 1000ms// @1ae #1056: [wait_1s]301a8 // @1ae #1056: CALL(delay_20ms)1c401 // @1af #1057: SUB(s4,1)355ae // @1b0 #1058: JUMP(NZ,wait_1s)2a000 // @1b1 #1059: RETURN// #1060: ;// #1061: ;// #1062: ;**************************************************************************************// #1063: ; UART communication routines// #1064: ;**************************************************************************************// #1065: ;// #1066: ; Read one character from the UART// #1067: ;// #1068: ; Character read will be returned in a register called 'UART_data'.// #1069: ;// #1070: ; The routine first tests the receiver FIFO buffer to see if data is present.// #1071: ; If the FIFO is empty, the routine waits until there is a character to read.// #1072: ; As this could take any amount of time the wait loop could include a call to a// #1073: ; subroutine which performs a useful function.// #1074: ;// #1075: ;// #1076: ; Registers used s0 and UART_data// #1077: ;// @1b2 #1078: [read_from_UART]04000 // @1b2 #1078: INPUT(s0,status_port) ;test Rx_FIFO buffer12004 // @1b3 #1079: TEST(s0,rx_data_present) ;wait if empty355b6 // @1b4 #1080: JUMP(NZ,read_character)341b2 // @1b5 #1081: JUMP(read_from_UART)// @1b6 #1082: [read_character]04f01 // @1b6 #1082: INPUT(UART_data,UART_read_port) ;read from FIFO2a000 // @1b7 #1083: RETURN// #1084: ;// #1085: ;// #1086: ;// #1087: ; Transmit one character to the UART// #1088: ;// #1089: ; Character supplied in register called 'UART_data'.// #1090: ;// #1091: ; The routine first tests the transmit FIFO buffer to see if it is full.// #1092: ; If the FIFO is full, then the routine waits until it there is space.// #1093: ;// #1094: ; Registers used s0// #1095: ;// @1b8 #1096: [send_to_UART]04000 // @1b8 #1096: INPUT(s0,status_port) ;test Tx_FIFO buffer12002 // @1b9 #1097: TEST(s0,tx_full) ;wait if full351bc // @1ba #1098: JUMP(Z,UART_write)341b8 // @1bb #1099: JUMP(send_to_UART)// @1bc #1100: [UART_write]2cf04 // @1bc #1100: OUTPUT(UART_data,UART_write_port)2a000 // @1bd #1101: RETURN// #1102: ;// #1103: ;// #1104: ;**************************************************************************************// #1105: ; Useful ASCII conversion and handling routines// #1106: ;**************************************************************************************// #1107: ;// #1108: ; Convert value provided in register s0 into ASCII characters// #1109: ;// #1110: ; The value provided must in the range 0 to 99 and will be converted into// #1111: ; two ASCII characters.// #1112: ; The number of 'tens' will be represented by an ASCII character returned in register s1.// #1113: ; The number of 'units' will be represented by an ASCII character returned in register s0.// #1114: ;// #1115: ; The ASCII representations of '0' to '9' are 30 to 39 hexadecimal which is simply 30 hex added to// #1116: ; the actual decimal value.// #1117: ;// #1118: ; Registers used s0 and s1.// #1119: ;// @1be #1120: [decimal_to_ASCII]00130 // @1be #1120: LOAD(s1,48) ;load 'tens' counter with ASCII for '0'// @1bf #1121: [test_for_ten]18101 // @1bf #1121: ADD(s1,1) ;increment 'tens' value1c00a // @1c0 #1122: SUB(s0,10) ;try to subtract 10 from the supplied value35dbf // @1c1 #1123: JUMP(NC,test_for_ten) ;repeat if subtraction was possible without underflow.1c101 // @1c2 #1124: SUB(s1,1) ;'tens' value one less ten due to underflow1803a // @1c3 #1125: ADD(s0,58) ;restore units value (the remainder) and convert to ASCII2a000 // @1c4 #1126: RETURN// #1127: ;// #1128: ;// #1129: ;// #1130: ; Convert character to upper case// #1131: ;// #1132: ; The character supplied in register s0.// #1133: ; If the character is in the range 'a' to 'z', it is converted// #1134: ; to the equivalent upper case character in the range 'A' to 'Z'.// #1135: ; All other characters remain unchanged.// #1136: ;// #1137: ; Registers used s0.// #1138: ;// @1c5 #1139: [upper_case]14061 // @1c5 #1139: COMPARE(s0,97) ;eliminate character codes below 'a' (61 hex)2b800 // @1c6 #1140: RETURN(C)1407b // @1c7 #1141: COMPARE(s0,123) ;eliminate character codes above 'z' (7A hex)2bc00 // @1c8 #1142: RETURN(NC)0a0df // @1c9 #1143: AND(s0,DF) ;mask bit5 to convert to upper case2a000 // @1ca #1144: RETURN// #1145: ;// #1146: ;// #1147: ; Convert character '0' to '9' to numerical value in range 0 to 9// #1148: ;// #1149: ; The character supplied in register s0. If the character is in the// #1150: ; range '0' to '9', it is converted to the equivalent decimal value.// #1151: ; Characters not in the range '0' to '9' are signified by the return// #1152: ; with the CARRY flag set.// #1153: ;// #1154: ; Registers used s0.// #1155: ;// @1cb #1156: [onechar_to_value]180c6 // @1cb #1156: ADD(s0,C6) ;reject character codes above '9' (39 hex)2b800 // @1cc #1157: RETURN(C) ;carry flag is set1c0f6 // @1cd #1158: SUB(s0,F6) ;reject character codes below '0' (30 hex)2a000 // @1ce #1159: RETURN ;carry is set if value not in range// #1160: ;// #1161: ;// #1162: ; Determine the numerical value of a two character decimal string held in// #1163: ; scratch pad memory such the result is in the range 0 to 99 (00 to 63 hex).// #1164: ;// #1165: ; The string must be stored in two consecutive memory locations and the// #1166: ; location of the first (tens) character supplied in the s1 register.// #1167: ; The result is provided in register s2. Strings not using characters in the// #1168: ; range '0' to '9' are signified by the return with the CARRY flag set.// #1169: ;// #1170: ; Registers used s0, s1 and s2.// #1171: ;// @1cf #1172: [twochar_to_value]07010 // @1cf #1172: FETCH(s0,s1) ;read 'tens' character301cb // @1d0 #1173: CALL(onechar_to_value) ;convert to numerical value2b800 // @1d1 #1174: RE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -