uclock.rmh
来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 1,263 行 · 第 1/4 页
RMH
1,263 行
// #711: ; The number of 'tens' will be representd by an ASCII character returned in register s1.// #712: ; The number of 'units' will be representd by an ASCII character returned in register s0.// #713: ;// #714: ;The ASCII representations of '0' to '9' are 30 to 39 hexadecimal which is simply 30 hex added to// #715: ;the actual decimal value.// #716: ;// #717: ;Registers used s0 and s1.// #718: ;// @17e #719: [decimal_to_ASCII]00130 // @17e #719: load(s1,48) ;load 'tens' counter with ASCII for '0'// @17f #720: [test_for_ten]18101 // @17f #720: add(s1,1) ;increment 'tens' value1c00a // @180 #721: sub(s0,10) ;try to subtract 10 from the supplied value35d7f // @181 #722: jump(nc,test_for_ten) ;repeat if subtraction was possible without underflow.1c101 // @182 #723: sub(s1,1) ;'tens' value one less ten due to underflow1803a // @183 #724: add(s0,58) ;restore units value (the remainder) and convert to ASCII2a000 // @184 #725: return// #726: ;// #727: ;// #728: ;// #729: ;// #730: ;Real Time Clock// #731: ;// #732: ;Uses the 1us interrupt counter [int_counter_msb,int_counter_lsb] to determine how many// #733: ;micro-seconds have elapsed since the last update. This allows for just over 65ms between// #734: ;updates. Complete multiples of 1000us are used to update a 16-bit milli-second counter held// #735: ;in scratch pad memory locations [ms_time_stamp_msb,ms_time_stamp_msb] which in turn// #736: ;is used to update the real time hours, minutes and seconds clock held in scratch pad// #737: ;memory locations 'real_time_hours', 'real_time_minutes' and 'real_time_seconds'.// #738: ;// #739: ;The routine uses default register names s0,s1,s2,s3,s4,s5. These are preserved in scratch pad// #740: ;memory during the routine and restored before returning.// #741: ;// #742: ;Useful constants for real time clock operations// #743: ;// #744: constant(count_1000_lsb,232) ;lower 8-bits of 1000 count value// #745: constant(count_1000_msb,3) ;upper 8-bits of 1000 count value// #746: constant(hours_in_a_day,24) ;24 hours in a day// #747: constant(minutes_in_an_hour,60) ;60 minutes in an hour// #748: constant(seconds_in_a_minute,60) ;60 seconds in a minute// #749: ;// @185 #750: [update_time]2e010 // @185 #750: store(s0,time_preserve0) ;preserve contents of registers used during routine2e111 // @186 #751: store(s1,time_preserve1)2e212 // @187 #752: store(s2,time_preserve2)2e313 // @188 #753: store(s3,time_preserve3)2e414 // @189 #754: store(s4,time_preserve4)2e515 // @18a #755: store(s5,time_preserve5)// #756: ;06200 // @18b #757: fetch(s2,us_time_stamp_lsb) ;read the previous 'us' time stamp into [s3,s2]06301 // @18c #758: fetch(s3,us_time_stamp_msb)3c000 // @18d #759: interrupt(disable) ;Read and store current 'us' time stamp provided by the interrupt2ed00 // @18e #760: store(int_counter_lsb,us_time_stamp_lsb) ;counter. Interrupts are disabled to ensure that both bytes relate2ec01 // @18f #761: store(int_counter_msb,us_time_stamp_msb) ;to the same count value.3c001 // @190 #762: interrupt(enable)06400 // @191 #763: fetch(s4,us_time_stamp_lsb) ;read the new 'us' time stamp in [s5,s4]06501 // @192 #764: fetch(s5,us_time_stamp_msb) ;1d420 // @193 #765: sub(s4,s2) ;calculate 'us' time difference [s5,s4] = [s5,s4] - [s3,s2]1f530 // @194 #766: subcy(s5,s3) ; (This works correctly even if counter has rolled over)06202 // @195 #767: fetch(s2,us_time_lsb) ;read current 'us' time into [s3,s2]06303 // @196 #768: fetch(s3,us_time_msb)19240 // @197 #769: add(s2,s4) ;add on the elapsed 'us' value [s3,s2] = [s3,s2] + [s5,s4]1b350 // @198 #770: addcy(s3,s5)// #771: ;determine how many 1000us (1ms) units there are (if any) in current 'us' time00000 // @199 #772: load(s0,0) ;reset 'ms' counter// @19a #773: [test_1000us]1c2e8 // @19a #773: sub(s2,count_1000_lsb) ;subtract 1000 from [s3,s2]1e303 // @19b #774: subcy(s3,count_1000_msb)3599f // @19c #775: jump(c,store_us_time) ;Carry indicates [s3,s2] was less than 1000us18001 // @19d #776: add(s0,1) ;increment 'ms' elapsed because [s3,s2] was more or equal to 1000us3419a // @19e #777: jump(test_1000us) ;repeat to see if more than 1ms has elapsed// @19f #778: [store_us_time]182e8 // @19f #778: add(s2,count_1000_lsb) ;add 1000 to restore 'us' value1a303 // @1a0 #779: addcy(s3,count_1000_msb)2e202 // @1a1 #780: store(s2,us_time_lsb) ;store the current value of 'us'2e303 // @1a2 #781: store(s3,us_time_msb)// #782: ;s0 holds the number of 'ms' elapsed since last update (if any).06204 // @1a3 #783: fetch(s2,ms_time_lsb) ;read current 'ms' time into [s3,s2]06305 // @1a4 #784: fetch(s3,ms_time_msb)19200 // @1a5 #785: add(s2,s0) ;add on the elapsed 'ms' value [s3,s2] = [s3,s2] + s01a300 // @1a6 #786: addcy(s3,0)// #787: ;determine if there are now more than 1000ms to form 1 second.00000 // @1a7 #788: load(s0,0) ;reset 'second' counter1c2e8 // @1a8 #789: sub(s2,count_1000_lsb) ;subtract 1000 from [s3,s2]1e303 // @1a9 #790: subcy(s3,count_1000_msb)359ad // @1aa #791: jump(c,restore_ms_time) ;Carry indicates [s3,s2] was less than 1000ms18001 // @1ab #792: add(s0,1) ;increment 'second' elapsed because [s3,s2] was more or equal to 1000ms341af // @1ac #793: jump(store_ms_time) ;new value of 'ms' is remainder of subtraction// @1ad #794: [restore_ms_time]182e8 // @1ad #794: add(s2,count_1000_lsb) ;add 1000 to restore 'ms' value1a303 // @1ae #795: addcy(s3,count_1000_msb)// @1af #796: [store_ms_time]2e204 // @1af #796: store(s2,ms_time_lsb) ;store the current value of 'ms'2e305 // @1b0 #797: store(s3,ms_time_msb)// #798: ;s0 currently determines if one second needs to be added to the hh:mm:ss clock time06108 // @1b1 #799: fetch(s1,real_time_seconds) ;read seconds19100 // @1b2 #800: add(s1,s0) ;add one second if required by s01413c // @1b3 #801: compare(s1,seconds_in_a_minute) ;test for 1 minute351b7 // @1b4 #802: jump(z,inc_minutes)2e108 // @1b5 #803: store(s1,real_time_seconds) ;store updated seconds341c9 // @1b6 #804: jump(time_update_complete)// @1b7 #805: [inc_minutes]00100 // @1b7 #805: load(s1,0) ;seconds become zero2e108 // @1b8 #806: store(s1,real_time_seconds)06107 // @1b9 #807: fetch(s1,real_time_minutes) ;read minutes18101 // @1ba #808: add(s1,1) ;increment minutes1413c // @1bb #809: compare(s1,minutes_in_an_hour) ;test for 1 hour351bf // @1bc #810: jump(z,inc_hours)2e107 // @1bd #811: store(s1,real_time_minutes) ;store updated minutes341c9 // @1be #812: jump(time_update_complete)// @1bf #813: [inc_hours]00100 // @1bf #813: load(s1,0) ;minutes become zero2e107 // @1c0 #814: store(s1,real_time_minutes)06106 // @1c1 #815: fetch(s1,real_time_hours) ;read hours18101 // @1c2 #816: add(s1,1) ;increment hours14118 // @1c3 #817: compare(s1,hours_in_a_day) ;test for 24 hours351c7 // @1c4 #818: jump(z,reset_hours)2e106 // @1c5 #819: store(s1,real_time_hours) ;store updated hours341c9 // @1c6 #820: jump(time_update_complete)// @1c7 #821: [reset_hours]00100 // @1c7 #821: load(s1,0) ;hours become zero2e106 // @1c8 #822: store(s1,real_time_hours)// #823: ;// #824: ;With the time updated, there is then a test for time=alarm time// #825: ;// @1c9 #826: [time_update_complete]06006 // @1c9 #826: fetch(s0,real_time_hours)06109 // @1ca #827: fetch(s1,alarm_time_hours) ;compare hours15010 // @1cb #828: compare(s0,s1)355db // @1cc #829: jump(nz,finish_update)06007 // @1cd #830: fetch(s0,real_time_minutes) ;compare minutes0610a // @1ce #831: fetch(s1,alarm_time_minutes)15010 // @1cf #832: compare(s0,s1)355db // @1d0 #833: jump(nz,finish_update)06008 // @1d1 #834: fetch(s0,real_time_seconds) ;compare seconds0610b // @1d2 #835: fetch(s1,alarm_time_seconds)15010 // @1d3 #836: compare(s0,s1)355db // @1d4 #837: jump(nz,finish_update)0600c // @1d5 #838: fetch(s0,alarm_status) ;test if alarm is turned on12002 // @1d6 #839: test(s0,alarm_armed)351db // @1d7 #840: jump(z,finish_update) ;alarm was off0c001 // @1d8 #841: or(s0,alarm_active) ;activate alarm2e00c // @1d9 #842: store(s0,alarm_status)300a4 // @1da #843: call(alarm_drive)// @1db #844: [finish_update]06010 // @1db #844: fetch(s0,time_preserve0) ;restore the register contents06111 // @1dc #845: fetch(s1,time_preserve1)06212 // @1dd #846: fetch(s2,time_preserve2)06313 // @1de #847: fetch(s3,time_preserve3)06414 // @1df #848: fetch(s4,time_preserve4)06515 // @1e0 #849: fetch(s5,time_preserve5)2a000 // @1e1 #850: return// #851: ;// #852: ;Convert character to upper case// #853: ;// #854: ;The character supplied in register s0.// #855: ;If the character is in the range 'a' to 'z', it is converted// #856: ;to the equivalent upper case character in the range 'A' to 'Z'.// #857: ;All other characters remain unchanged.// #858: ;// #859: ;Registers used s0.// #860: ;// @1e2 #861: [upper_case]14061 // @1e2 #861: compare(s0,97) ;eliminate character codes below 'a' (61 hex)2b800 // @1e3 #862: return(c)1407b // @1e4 #863: compare(s0,123) ;eliminate character codes above 'z' (7A hex)2bc00 // @1e5 #864: return(nc)0a0df // @1e6 #865: and(s0,223) ;mask bit5 to convert to upper case2a000 // @1e7 #866: return// #867: ;// #868: ;// #869: ;Convert character '0' to '9' to numerical value in range 0 to 9// #870: ;// #871: ;The character supplied in register s0. If the character is in the// #872: ;range '0' to '9', it is converted to the equivalent decimal value.// #873: ;Characters not in the range '0' to '9' are signified by the return// #874: ;with the CARRY flag set.// #875: ;// #876: ;Registers used s0.// #877: ;// @1e8 #878: [_1char_to_value]180c6 // @1e8 #878: add(s0,198) ;reject character codes above '9' (39 hex)2b800 // @1e9 #879: return(c) ;carry flag is set1c0f6 // @1ea #880: sub(s0,246) ;reject character codes below '0' (30 hex)2a000 // @1eb #881: return ;carry is set if value not in range// #882: ;// #883: ;// #884: ;Determine the numerical value of a two character decimal string held in// #885: ;scratch pad memory such the result is in the range 0 to 99 (00 to 63 hex).// #886: ;// #887: ;The string must be stored as in two consecutive memory locations and the// #888: ;location of the first (tens) character supplied in the s1 register.// #889: ;The result is provided in register s2. Strings not using characters in the// #890: ;range '0' to '9' are signified by the return with the CARRY flag set.// #891: ;// #892: ;Registers used s0, s1 and s2.// #893: ;// @1ec #894: [_2char_to_value]07010 // @1ec #894: fetch(s0,s1) ;read 'tens' character301e8 // @1ed #895: call(_1char_to_value) ;convert to numerical value2b800 // @1ee #896: return(c) ;bad character - CARRY set01200 // @1ef #897: load(s2,s0)20206 // @1f0 #898: sl0(s2) ;multiply 'tens' value by 10 (0A hex)20206 // @1f1 #899: sl0(s2)19200 // @1f2 #900: add(s2,s0)20206 // @1f3 #901: sl0(s2)18101 // @1f4 #902: add(s1,1) ;read 'units' character07010 // @1f5 #903: fetch(s0,s1)301e8 // @1f6 #904: call(_1char_to_value) ;convert to numerical value2b800 // @1f7 #905: return(c) ;bad character - CARRY set19200 // @1f8 #906: add(s2,s0) ;add units to result and clear CARRY flag2a000 // @1f9 #907: return// #908: ;// #909: ;// #910: ;Interrupt service routine (ISR)// #911: ;// #912: ;The interrupt is used to increment a 16-bit counter formed with two registers// #913: ;called [int_counter_msb,int_counter_lsb]. This provides a count of the number// #914: ;of micro-seconds elapsed. The counter is 'free running' in that it will count// #915: ;up to 65,535 and then roll over to zero. The count value is then used in other// #916: ;parts of the program as required and where it is less time critical.// #917: ;// #918: ;The ISR only uses the specified counter registers// #919: ;@3fc // #920: address(1020)// @3fc #921: [ISR]18d01 // @3fc #921: add(int_counter_lsb,1) ;add 1us to 16-bit counter1ac00 // @3fd #922: addcy(int_counter_msb,0)38001 // @3fe #923: returni(enable)// #924: ;// #925: ;Interrupt vector// #926: ;@3ff // #927: address(1023)343fc // @3ff #928: jump(ISR)// #929: ;// #930: ;// #931: ;Useful constants// #932: ;// #933: ;// #934: ;ASCII table// #935: ;// #936: constant(character_a,97)// #937: constant(character_b,98)// #938: constant(character_c,99)// #939: constant(character_d,100)// #940: constant(character_e,101)// #941: constant(character_f,102)// #942: constant(character_g,103)// #943: constant(character_h,104)// #944: constant(character_i,105)// #945: constant(character_j,106)// #946: constant(character_k,107)// #947: constant(character_l,108)// #948: constant(character_m,109)// #949: constant(character_n,110)// #950: constant(character_o,111)// #951: constant(character_p,112)// #952: constant(character_q,113)// #953: constant(character_r,114)// #954: constant(character_s,115)// #955: constant(character_t,116)// #956: constant(character_u,117)// #957: constant(character_v,118)// #958: constant(character_w,119)// #959: constant(character_x,120)// #960: constant(character_y,121)// #961: constant(character_z,122)// #962: constant(character_A,65)// #963: constant(character_B,66)// #964: constant(character_C,67)// #965: constant(character_D,68)// #966: constant(character_E,69)// #967: constant(character_F,70)// #968: constant(character_G,71)// #969: constant(character_H,72)// #970: constant(character_I,73)// #971: constant(character_J,74)// #972: constant(character_K,75)// #973: constant(character_L,76)// #974: constant(character_M,77)// #975: constant(character_N,78)// #976: constant(character_O,79)// #977: constant(character_P,80)// #978: constant(character_Q,81)// #979: constant(character_R,82)// #980: constant(character_S,83)// #981: constant(character_T,84)// #982: constant(character_U,85)// #983: constant(character_V,86)// #984: constant(character_W,87)// #985: constant(character_X,88)// #986: constant(character_Y,89)// #987: constant(character_Z,90)// #988: constant(character_0,48)// #989: constant(character_1,49)// #990: constant(character_2,50)// #991: constant(character_3,51)// #992: constant(character_4,52)// #993: constant(character_5,53)// #994: constant(character_6,54)// #995: constant(character_7,55)// #996: constant(character_8,56)// #997: constant(character_9,57)// #998: constant(character_colon,58)// #999: constant(character_semi_colon,59)// #1000: constant(character_less_than,60)// #1001: constant(character_greater_than,62)// #1002: constant(character_equals,61)// #1003: constant(character_space,32)// #1004: constant(character_CR,13) ;carriage return// #1005: constant(character_question,63) ;'?'// #1006: constant(character_dollar,36)// #1007: constant(character_BS,8) ;Back Space command character// #1008: ;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?