18b20.ls 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. 1 ; C Compiler for STM8 (COSMIC Software)
  2. 2 ; Parser V4.8.32 - 23 Mar 2010
  3. 3 ; Generator V4.3.4 - 23 Mar 2010
  4. 2483 ; 49 void DS18B20_Init(void)
  5. 2483 ; 50 {
  6. 2485 switch .text
  7. 2486 0000 _DS18B20_Init:
  8. 2490 ; 51 DS18B20_DQ_OUT;
  9. 2492 0000 721c5011 bset _B20_OUT_DDR
  10. 2493 ; 52 DS18B20_DQ_PUSH_PULL;
  11. 2495 0004 721c5012 bset _B20_OUT_CR1
  12. 2496 ; 53 DS18B20_DQ_HIGH;
  13. 2498 0008 721c500f bset _B20_OUT_ODR
  14. 2499 ; 54 _delay_us(10);
  15. 2501 000c ae000a ldw x,#10
  16. 2502 000f cd0000 call __delay_us
  17. 2504 ; 55 DS18B20_DQ_LOW;
  18. 2506 0012 721d500f bres _B20_OUT_ODR
  19. 2507 ; 56 _delay_us(600); //¸´Î»Âö³å
  20. 2509 0016 ae0258 ldw x,#600
  21. 2510 0019 cd0000 call __delay_us
  22. 2512 ; 58 DS18B20_DQ_IN;
  23. 2514 001c 721d5011 bres _B20_OUT_DDR
  24. 2515 ; 59 DS18B20_DQ_PULL_UP;
  25. 2517 0020 721c5012 bset _B20_OUT_CR1
  26. 2518 ; 60 _delay_us(100);
  27. 2520 0024 ae0064 ldw x,#100
  28. 2521 0027 cd0000 call __delay_us
  29. 2523 ; 63 _delay_us(400);
  30. 2525 002a ae0190 ldw x,#400
  31. 2526 002d cd0000 call __delay_us
  32. 2528 ; 64 }
  33. 2531 0030 81 ret
  34. 2577 ; 66 void DS18B20_WriteByte(unsigned char _data)
  35. 2577 ; 67 {
  36. 2578 switch .text
  37. 2579 0031 _DS18B20_WriteByte:
  38. 2581 0031 88 push a
  39. 2582 0032 88 push a
  40. 2583 00000001 OFST: set 1
  41. 2586 ; 68 unsigned char i = 0;
  42. 2588 ; 70 DS18B20_DQ_OUT;
  43. 2590 0033 721c5011 bset _B20_OUT_DDR
  44. 2591 ; 71 for (i = 0; i < 8; i++)
  45. 2593 0037 0f01 clr (OFST+0,sp)
  46. 2594 0039 L3261:
  47. 2595 ; 73 DS18B20_DQ_LOW;
  48. 2597 0039 721d500f bres _B20_OUT_ODR
  49. 2598 ; 74 _delay_us(2);
  50. 2600 003d ae0002 ldw x,#2
  51. 2601 0040 cd0000 call __delay_us
  52. 2603 ; 75 if (_data & 0x01)
  53. 2605 0043 7b02 ld a,(OFST+1,sp)
  54. 2606 0045 a501 bcp a,#1
  55. 2607 0047 2704 jreq L1361
  56. 2608 ; 77 DS18B20_DQ_HIGH;
  57. 2610 0049 721c500f bset _B20_OUT_ODR
  58. 2611 004d L1361:
  59. 2612 ; 79 _data >>= 1;
  60. 2614 004d 0402 srl (OFST+1,sp)
  61. 2615 ; 80 _delay_us(60);
  62. 2617 004f ae003c ldw x,#60
  63. 2618 0052 cd0000 call __delay_us
  64. 2620 ; 81 DS18B20_DQ_HIGH;
  65. 2622 0055 721c500f bset _B20_OUT_ODR
  66. 2623 ; 71 for (i = 0; i < 8; i++)
  67. 2625 0059 0c01 inc (OFST+0,sp)
  68. 2628 005b 7b01 ld a,(OFST+0,sp)
  69. 2629 005d a108 cp a,#8
  70. 2630 005f 25d8 jrult L3261
  71. 2631 ; 83 }
  72. 2634 0061 85 popw x
  73. 2635 0062 81 ret
  74. 2682 ; 85 unsigned char DS18B20_ReadByte(void)
  75. 2682 ; 86 {
  76. 2683 switch .text
  77. 2684 0063 _DS18B20_ReadByte:
  78. 2686 0063 89 pushw x
  79. 2687 00000002 OFST: set 2
  80. 2690 ; 87 unsigned char i = 0, _data = 0;
  81. 2694 0064 0f02 clr (OFST+0,sp)
  82. 2695 ; 89 for (i = 0; i < 8; i++)
  83. 2697 0066 0f01 clr (OFST-1,sp)
  84. 2698 0068 L5561:
  85. 2699 ; 91 DS18B20_DQ_OUT;
  86. 2701 0068 721c5011 bset _B20_OUT_DDR
  87. 2702 ; 92 DS18B20_DQ_LOW;
  88. 2704 006c 721d500f bres _B20_OUT_ODR
  89. 2705 ; 93 _delay_us(5);
  90. 2707 0070 ae0005 ldw x,#5
  91. 2708 0073 cd0000 call __delay_us
  92. 2710 ; 94 _data >>= 1;
  93. 2712 0076 0402 srl (OFST+0,sp)
  94. 2713 ; 95 DS18B20_DQ_HIGH;
  95. 2715 0078 721c500f bset _B20_OUT_ODR
  96. 2716 ; 96 DS18B20_DQ_IN;
  97. 2718 007c 721d5011 bres _B20_OUT_DDR
  98. 2719 ; 97 if (DS18B20_DQ_VALUE)
  99. 2721 btst _B20_IN_IDR
  100. 2722 0085 2406 jruge L3661
  101. 2723 ; 99 _data |= 0x80;
  102. 2725 0087 7b02 ld a,(OFST+0,sp)
  103. 2726 0089 aa80 or a,#128
  104. 2727 008b 6b02 ld (OFST+0,sp),a
  105. 2728 008d L3661:
  106. 2729 ; 101 DS18B20_DQ_OUT;
  107. 2731 008d 721c5011 bset _B20_OUT_DDR
  108. 2732 ; 102 DS18B20_DQ_HIGH;
  109. 2734 0091 721c500f bset _B20_OUT_ODR
  110. 2735 ; 103 _delay_us(60);
  111. 2737 0095 ae003c ldw x,#60
  112. 2738 0098 cd0000 call __delay_us
  113. 2740 ; 89 for (i = 0; i < 8; i++)
  114. 2742 009b 0c01 inc (OFST-1,sp)
  115. 2745 009d 7b01 ld a,(OFST-1,sp)
  116. 2746 009f a108 cp a,#8
  117. 2747 00a1 25c5 jrult L5561
  118. 2748 ; 106 return _data;
  119. 2750 00a3 7b02 ld a,(OFST+0,sp)
  120. 2753 00a5 85 popw x
  121. 2754 00a6 81 ret
  122. 2801 ; 109 float DS18B20_ReadTemperature(void)
  123. 2801 ; 110 {
  124. 2802 switch .text
  125. 2803 00a7 _DS18B20_ReadTemperature:
  126. 2805 00a7 5209 subw sp,#9
  127. 2806 00000009 OFST: set 9
  128. 2809 ; 111 unsigned char temp = 0;
  129. 2811 ; 112 float t = 0;
  130. 2813 ; 114 DS18B20_Init();
  131. 2815 00a9 cd0000 call _DS18B20_Init
  132. 2817 ; 115 DS18B20_WriteByte(0xcc);
  133. 2819 00ac a6cc ld a,#204
  134. 2820 00ae ad81 call _DS18B20_WriteByte
  135. 2822 ; 116 DS18B20_WriteByte(0x44);
  136. 2824 00b0 a644 ld a,#68
  137. 2825 00b2 cd0031 call _DS18B20_WriteByte
  138. 2827 ; 118 DS18B20_Init();
  139. 2829 00b5 cd0000 call _DS18B20_Init
  140. 2831 ; 119 DS18B20_WriteByte(0xcc);
  141. 2833 00b8 a6cc ld a,#204
  142. 2834 00ba cd0031 call _DS18B20_WriteByte
  143. 2836 ; 120 DS18B20_WriteByte(0xbe);
  144. 2838 00bd a6be ld a,#190
  145. 2839 00bf cd0031 call _DS18B20_WriteByte
  146. 2841 ; 122 temp = DS18B20_ReadByte();
  147. 2843 00c2 ad9f call _DS18B20_ReadByte
  148. 2845 00c4 6b09 ld (OFST+0,sp),a
  149. 2846 ; 123 t = (((temp & 0xf0) >> 4) + (temp & 0x07) * 0.125);
  150. 2848 00c6 7b09 ld a,(OFST+0,sp)
  151. 2849 00c8 a407 and a,#7
  152. 2850 00ca 5f clrw x
  153. 2851 00cb 97 ld xl,a
  154. 2852 00cc cd0000 call c_itof
  155. 2854 00cf ae0000 ldw x,#L3171
  156. 2855 00d2 cd0000 call c_fmul
  157. 2857 00d5 96 ldw x,sp
  158. 2858 00d6 1c0001 addw x,#OFST-8
  159. 2859 00d9 cd0000 call c_rtol
  160. 2861 00dc 7b09 ld a,(OFST+0,sp)
  161. 2862 00de a4f0 and a,#240
  162. 2863 00e0 4e swap a
  163. 2864 00e1 a40f and a,#15
  164. 2865 00e3 5f clrw x
  165. 2866 00e4 02 rlwa x,a
  166. 2867 00e5 cd0000 call c_itof
  167. 2869 00e8 96 ldw x,sp
  168. 2870 00e9 1c0001 addw x,#OFST-8
  169. 2871 00ec cd0000 call c_fadd
  170. 2873 00ef 96 ldw x,sp
  171. 2874 00f0 1c0005 addw x,#OFST-4
  172. 2875 00f3 cd0000 call c_rtol
  173. 2877 ; 124 temp = DS18B20_ReadByte();
  174. 2879 00f6 cd0063 call _DS18B20_ReadByte
  175. 2881 00f9 6b09 ld (OFST+0,sp),a
  176. 2882 ; 125 t += ((temp & 0x0f) << 4);
  177. 2884 00fb 7b09 ld a,(OFST+0,sp)
  178. 2885 00fd a40f and a,#15
  179. 2886 00ff 97 ld xl,a
  180. 2887 0100 a610 ld a,#16
  181. 2888 0102 42 mul x,a
  182. 2889 0103 cd0000 call c_itof
  183. 2891 0106 96 ldw x,sp
  184. 2892 0107 1c0005 addw x,#OFST-4
  185. 2893 010a cd0000 call c_fgadd
  186. 2895 ; 127 return t;
  187. 2897 010d 96 ldw x,sp
  188. 2898 010e 1c0005 addw x,#OFST-4
  189. 2899 0111 cd0000 call c_ltor
  190. 2903 0114 5b09 addw sp,#9
  191. 2904 0116 81 ret
  192. 2969 xdef _DS18B20_ReadByte
  193. 2970 xdef _DS18B20_WriteByte
  194. 2971 xdef _DS18B20_Init
  195. 2972 xdef _DS18B20_ReadTemperature
  196. 2973 xref __delay_us
  197. 2974 .const: section .text
  198. 2975 0000 L3171:
  199. 2976 0000 3e000000 dc.w 15872,0
  200. 2977 xref.b c_x
  201. 2997 xref c_ltor
  202. 2998 xref c_fgadd
  203. 2999 xref c_fadd
  204. 3000 xref c_rtol
  205. 3001 xref c_fmul
  206. 3002 xref c_itof
  207. 3003 end