Subversion Repositories HomeAutomation

Rev

Rev 358 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*********************************************************************
  2.  *
  3.  *                  Main application
  4.  *
  5.  *********************************************************************
  6.  * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canLCD/Source/Main.c $
  7.  * Last changed:    $LastChangedDate: 2007-03-04 15:13:16 +0100 (Sun, 04 Mar 2007) $
  8.  * By:              $LastChangedBy: johboh $
  9.  * Revision:        $Revision: 359 $
  10.  ********************************************************************/
  11.  
  12.  
  13. #include <compiler.h>
  14. #include <stackTasks.h>
  15. #include <Tick.h>
  16. #include <funcdefs.h>
  17. #include <CAN.h>
  18. #include "..\canBoot\Include\boot.h"
  19.  
  20. #ifdef USE_GLCD
  21.     #include "glcd.h"
  22. #endif
  23.  
  24. #ifdef USE_ADC
  25.     #include <adc.h>
  26. #endif
  27.  
  28. #ifdef USE_GLCD
  29.     const rom BYTE pic[]={
  30. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32. 0x00,0x00,0x00,0x60,0x90,0x90,0x10,0x30,
  33. 0x00,0x10,0xF0,0x80,0x80,0x00,0x00,0x00,
  34. 0x00,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
  35. 0x80,0x00,0x00,0x00,0x80,0x80,0x8C,0x80,
  36. 0x00,0x10,0xF0,0x80,0x80,0x00,0x00,0x00,
  37. 0x00,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
  38. 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  39. 0x00,0x30,0x10,0xF0,0x10,0x30,0x00,0xE0,
  40. 0x10,0x10,0x10,0xE0,0x00,0x10,0xF0,0x90,
  41. 0x90,0x60,0x00,0x70,0x80,0xF0,0x8C,0x70,
  42. 0x00,0x00,0x80,0x70,0xC0,0x00,0x00,0x10,
  43. 0x70,0x80,0x70,0x10,0x00,0x00,0x00,0x00,
  44. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  45. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  46. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  47. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  48. 0x00,0x00,0x00,0x0C,0x08,0x08,0x09,0x06,
  49. 0x00,0x08,0x0F,0x08,0x00,0x0F,0x08,0x00,
  50. 0x07,0x0A,0x0A,0x0B,0x00,0x08,0x0F,0x08,
  51. 0x00,0x0F,0x08,0x00,0x08,0x08,0x09,0x08,
  52. 0x00,0x08,0x0F,0x08,0x00,0x0F,0x08,0x00,
  53. 0x07,0x0A,0x0A,0x0B,0x00,0x08,0x0F,0x08,
  54. 0x00,0x0F,0x08,0x00,0x00,0x00,0x00,0x00,
  55. 0x00,0x00,0x08,0x0F,0x08,0x00,0x00,0x07,
  56. 0x08,0x08,0x08,0x07,0x00,0x08,0x0F,0x08,
  57. 0x00,0x00,0x00,0x00,0x0F,0x00,0x0F,0x00,
  58. 0x00,0x08,0x0F,0x02,0x03,0x0E,0x08,0x00,
  59. 0x08,0x0F,0x08,0x00,0x00,0x00,0x00,0x00,
  60. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  61. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  62. 0x00,0x03,0x81,0xFF,0x81,0x03,0x00,0x00,
  63. 0x70,0xA8,0xA8,0xB0,0x00,0x00,0x70,0x88,
  64. 0x88,0x98,0x00,0x81,0xFF,0x88,0x08,0xF0,
  65. 0x80,0x88,0xF8,0x88,0x08,0xF0,0x80,0x00,
  66. 0x70,0x88,0x88,0x70,0x00,0x81,0x81,0xFF,
  67. 0x80,0x80,0x00,0x00,0x70,0x88,0x88,0x70,
  68. 0x00,0x00,0xD0,0xA8,0xA8,0x98,0x08,0x08,
  69. 0x38,0xC8,0x60,0x18,0x08,0x00,0x00,0x00,
  70. 0x00,0x00,0x00,0x7E,0x81,0x81,0x81,0x43,
  71. 0x00,0x00,0x70,0x88,0x88,0x70,0x00,0x00,
  72. 0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x00,
  73. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74. 0x00,0x81,0xFF,0x81,0x80,0x80,0xC0,0x00,
  75. 0x08,0x7E,0x88,0x80,0x00,0x00,0x70,0x88,
  76. 0x89,0xFF,0x80,0x00,0x80,0x00,0x00,0x00,
  77. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  78. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  79. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  80. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  81. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  82. 0x00,0x00,0x01,0x02,0x02,0x01,0x00,0x00,
  83. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  84. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  85. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  86. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  87. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  88. 0x02,0x02,0x01,0x02,0x00,0x00,0x00,0x00,
  89. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  90. 0x00,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
  91. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  92. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  93. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  94. 0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,
  95. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  97. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  98. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  99. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  100. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  101. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  102. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  103. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81,
  104. 0xC0,0xFF,0x0F,0xF0,0x89,0x89,0x8B,0x70,
  105. 0x81,0x7E,0x00,0x42,0x00,0x76,0x89,0x89,
  106. 0xFF,0x89,0x89,0x76,0x00,0x00,0x00,0x00,
  107. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  108. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  109. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  110. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  111. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  112. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  113. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  114. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  115. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  116. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  117. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  118. 0xFF,0x81,0x80,0x80,0x0F,0xFF,0x00,0x81,
  119. 0x00,0x78,0x81,0x81,0x81,0x89,0x89,0x76,
  120. 0x89,0x76,0x00,0x81,0x00,0x00,0x00,0x00,
  121. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  122. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  123. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  124. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  125. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  126. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  127. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  128. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  129. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  130. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  131. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  132. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  133. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  134. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  135. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  136. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  137. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  138. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  139. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  140. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  141. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  142. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  143. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  144. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  145. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  146. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  147. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  148. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  149. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  150. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  151. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  152. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  153. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  154. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  155. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  156. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  157. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  158. };
  159.  
  160. const rom BYTE pic2[] = {
  161. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  162. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  163. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  164. 0x00,0x00,0x00,0x80,0x03,0x00,0x00,0x00,
  165. 0x00,0x00,0x00,0xc0,0x0f,0x00,0x00,0x00,
  166. 0x00,0x00,0x00,0xc0,0x3f,0x00,0x00,0x00,
  167. 0x00,0x00,0x00,0xe0,0xff,0x00,0x00,0x00,
  168. 0x00,0x00,0x00,0xe0,0xff,0x03,0x00,0x00,
  169. 0x00,0x00,0x00,0xe0,0xff,0xcf,0x03,0x00,
  170. 0x00,0x00,0x00,0x00,0xff,0xff,0x03,0x00,
  171. 0x00,0x00,0x00,0x00,0xfc,0xff,0x03,0x00,
  172. 0x00,0x00,0x00,0x00,0xf0,0xff,0x03,0x00,
  173. 0x00,0x00,0x00,0x00,0xc0,0xff,0x01,0x00,
  174. 0x00,0x00,0x00,0x00,0x00,0xfe,0x00,0x00,
  175. 0x00,0x00,0x00,0x80,0x1f,0x78,0x00,0x00,
  176. 0x00,0x00,0x00,0xe0,0xff,0x00,0x00,0x00,
  177. 0x00,0x00,0x00,0xe0,0xff,0x03,0x00,0x00,
  178. 0x00,0x00,0x00,0xf0,0xff,0x07,0x00,0x00,
  179. 0x00,0x00,0x00,0xf0,0xff,0x0f,0x00,0x00,
  180. 0x00,0x00,0x00,0xf0,0xfe,0x1f,0x00,0x00,
  181. 0x00,0x00,0x00,0xf0,0xf1,0x1f,0x00,0x00,
  182. 0x00,0x00,0x00,0xf0,0xc7,0x1f,0x00,0x00,
  183. 0x00,0x00,0x00,0xf0,0x3f,0x1f,0x00,0x00,
  184. 0x00,0x00,0x00,0xf0,0xff,0x0f,0x00,0x00,
  185. 0x00,0x00,0x00,0xf0,0xff,0x0f,0x00,0x00,
  186. 0x00,0x00,0x00,0xe0,0xff,0x0f,0x00,0x00,
  187. 0x00,0x00,0xc0,0x83,0xff,0x07,0x00,0x00,
  188. 0x00,0x00,0xc0,0x3f,0xfc,0x03,0x00,0x00,
  189. 0x00,0x00,0xc0,0xff,0x01,0x00,0x00,0x00,
  190. 0x00,0x00,0xc0,0xff,0x1f,0x00,0x00,0x00,
  191. 0x00,0x00,0xe0,0xff,0xff,0x01,0x00,0x00,
  192. 0x00,0x00,0xe0,0xff,0xff,0x03,0x00,0x00,
  193. 0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x00,
  194. 0x00,0x00,0x00,0xff,0xff,0x01,0x00,0x00,
  195. 0x00,0x00,0x00,0x0f,0xfe,0x01,0x00,0x00,
  196. 0x00,0x00,0x80,0x0f,0xe0,0x01,0x00,0x00,
  197. 0x00,0x00,0x80,0x7f,0x00,0x00,0x00,0x00,
  198. 0x00,0x00,0x80,0xff,0x0f,0x00,0x00,0x00,
  199. 0x00,0x00,0x80,0xff,0xff,0x00,0x00,0x00,
  200. 0x00,0x00,0x80,0xff,0xff,0x00,0x00,0x00,
  201. 0x00,0x00,0x00,0xff,0xff,0x00,0x00,0x00,
  202. 0x00,0x00,0x00,0xfe,0xff,0x00,0x00,0x00,
  203. 0x00,0x00,0x78,0x80,0x7f,0x00,0x00,0x00,
  204. 0x00,0x00,0xf8,0x1f,0x60,0x00,0x00,0x00,
  205. 0x00,0x00,0xf8,0xff,0x0f,0x00,0x00,0x00,
  206. 0x00,0x00,0xf8,0xff,0x7f,0x00,0x00,0x00,
  207. 0x00,0x00,0xfc,0xff,0x7f,0x00,0x00,0x00,
  208. 0x00,0x00,0xfc,0xff,0x7f,0x00,0x00,0x00,
  209. 0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
  210. 0x00,0x00,0xe0,0xc1,0x3f,0x00,0x00,0x00,
  211. 0x00,0x00,0xe0,0x07,0x1c,0x00,0x00,0x00,
  212. 0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
  213. 0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
  214. 0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
  215. 0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
  216. 0x00,0x00,0xc0,0xff,0x1f,0x00,0x00,0x00,
  217. 0x00,0x00,0x00,0xe0,0x0f,0x00,0x00,0x00,
  218. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  219. 0x00,0x00,0x80,0xff,0x07,0x00,0x00,0x00,
  220. 0x00,0x00,0xc0,0xff,0x0f,0x00,0x00,0x00,
  221. 0x00,0x00,0xe0,0xff,0x1f,0x00,0x00,0x00,
  222. 0x00,0x00,0xe0,0xff,0x1f,0x00,0x00,0x00,
  223. 0x00,0x00,0xe0,0xff,0x1f,0x00,0x00,0x00,
  224. 0x00,0x00,0xf0,0xff,0x1f,0x00,0x00,0x00,
  225. 0x00,0x00,0xf0,0x01,0x1e,0x00,0x00,0x00,
  226. 0x00,0x00,0xe0,0xff,0x1f,0x00,0x00,0x00,
  227. 0x00,0x00,0xe0,0xff,0x1f,0x00,0x00,0x00,
  228. 0x00,0x00,0xe0,0xff,0x1f,0x00,0x00,0x00,
  229. 0x00,0x00,0xc0,0xff,0x0f,0x00,0x00,0x00,
  230. 0x00,0x00,0xc0,0xff,0x07,0x00,0x00,0x00,
  231. 0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0x00,
  232. 0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,
  233. 0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
  234. 0x00,0x00,0xfc,0xff,0x3f,0x00,0x00,0x00,
  235. 0x00,0x00,0xfc,0xff,0x3f,0x00,0x00,0x00,
  236. 0x00,0x00,0xfc,0xff,0x3f,0x00,0x00,0x00,
  237. 0x00,0x00,0xfc,0xff,0x3f,0x00,0x00,0x00,
  238. 0x00,0x00,0xfc,0xff,0x00,0x00,0x00,0x00,
  239. 0x00,0x00,0xfc,0x03,0x00,0x00,0x00,0x00,
  240. 0x00,0x00,0xc0,0x03,0x7c,0x00,0x00,0x00,
  241. 0x00,0x00,0xc0,0xff,0x7f,0x00,0x00,0x00,
  242. 0x00,0x00,0xc0,0xff,0x7f,0x00,0x00,0x00,
  243. 0x00,0x00,0xc0,0xff,0x7f,0x00,0x00,0x00,
  244. 0x00,0x00,0xc0,0xff,0x7f,0x00,0x00,0x00,
  245. 0x00,0x00,0xc0,0xff,0x7f,0x00,0x00,0x00,
  246. 0x00,0x00,0x80,0xff,0x01,0x00,0x00,0x00,
  247. 0x00,0x00,0x00,0x06,0xf8,0x00,0x00,0x00,
  248. 0x00,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
  249. 0x00,0x00,0x00,0xfc,0xff,0x00,0x00,0x00,
  250. 0x00,0x00,0xf0,0xff,0xff,0x01,0x00,0x00,
  251. 0x00,0x00,0xf0,0xff,0xff,0x01,0x00,0x00,
  252. 0x00,0x00,0xf0,0xff,0x37,0x00,0x00,0x00,
  253. 0x00,0x00,0xe0,0xff,0x00,0x00,0x00,0x00,
  254. 0x00,0x00,0xe0,0x0f,0x00,0x00,0x00,0x00,
  255. 0x00,0x00,0xe0,0x01,0x00,0x00,0x00,0x00,
  256. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  257. 0x00,0x00,0x00,0x00,0x00,0x0e,0x00,0x00,
  258. 0x00,0x00,0x00,0x00,0xc0,0x0f,0x00,0x00,
  259. 0x00,0x00,0x00,0x00,0xc0,0x0f,0x00,0x00,
  260. 0x00,0x00,0x00,0x80,0xc7,0x0f,0x00,0x00,
  261. 0x00,0x00,0x00,0xc0,0xc7,0x0f,0x00,0x00,
  262. 0x00,0x00,0x00,0xc0,0x8f,0x07,0x00,0x00,
  263. 0x00,0x00,0x00,0xc0,0x8f,0x01,0x00,0x00,
  264. 0x00,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,
  265. 0x00,0x00,0x00,0x80,0x7f,0x00,0x00,0x00,
  266. 0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00,
  267. 0x00,0x00,0x00,0x00,0xf8,0x00,0x00,0x00,
  268. 0x00,0x00,0x00,0x00,0xf8,0x00,0x00,0x00,
  269. 0x00,0x00,0x00,0x00,0xf0,0x00,0x00,0x00,
  270. 0x00,0x00,0x00,0x00,0xf0,0x61,0x00,0x00,
  271. 0x00,0x00,0x00,0x00,0xf0,0xf1,0x00,0x00,
  272. 0x00,0x00,0x00,0x00,0xe0,0xf0,0x00,0x00,
  273. 0x00,0x00,0x00,0x00,0x00,0xf0,0x00,0x00,
  274. 0x00,0x00,0x00,0x00,0x00,0xfe,0x01,0x00,
  275. 0x00,0x00,0x00,0x00,0x80,0xff,0x01,0x00,
  276. 0x00,0x00,0x00,0x00,0xe0,0xff,0x01,0x00,
  277. 0x00,0x00,0x00,0xe0,0xf8,0xff,0x00,0x00,
  278. 0x00,0x00,0x00,0xe0,0xff,0x7f,0x00,0x00,
  279. 0x00,0x00,0x00,0xe0,0xff,0x1f,0x00,0x00,
  280. 0x00,0x00,0x00,0xe0,0xff,0x07,0x00,0x00,
  281. 0x00,0x00,0x00,0xc0,0xff,0x01,0x00,0x00,
  282. 0x00,0x00,0x00,0xc0,0x7f,0x00,0x00,0x00,
  283. 0x00,0x00,0x00,0x80,0x1f,0x00,0x00,0x00,
  284. 0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
  285. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  286. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  287. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  288. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  289. };
  290.  
  291. const rom BYTE pic3[] = {
  292. '\xff','\xff','\xff','\xff','\xff','\xff','\xff','\xff',
  293. '\xff','\xff','\xff','\xff','\xff','\xff','\xff','\xff',
  294. '\xff','\xff','\xff','\xff','\xff','\xff','\xff','\xff',
  295. '\xf9','\xff','\xff','\xff','\xff','\xff','\xff','\xff',
  296. '\xe1','\xff','\xff','\xff','\xff','\xff','\xff','\xff',
  297. '\xed','\xff','\xff','\xff','\xff','\xff','\xff','\xff',
  298. '\xdd','\xff','\xff','\xff','\xff','\xff','\xff','\xff',
  299. '\x9d','\xff','\xff','\xff','\xff','\xff','\xff','\xff',
  300. '\xb9','\xff','\xff','\xff','\xff','\xff','\xff','\xff',
  301. '\xbb','\xff','\xff','\x07','\xfc','\xff','\xff','\xff',
  302. '\x7b','\xfe','\xff','\xfb','\xfb','\xff','\xff','\xff',
  303. '\xfb','\xfe','\xff','\xf9','\xf3','\xff','\xff','\xff',
  304. '\xf3','\xfc','\xff','\xfd','\xe7','\xff','\xff','\xff',
  305. '\x07','\xfc','\xff','\xfc','\xef','\xff','\xff','\xff',
  306. '\xf7','\xfd','\x7f','\xfe','\xdf','\xff','\xff','\xff',
  307. '\xf7','\xfd','\x7f','\xff','\xdf','\xff','\xff','\xff',
  308. '\xf7','\xfd','\x7f','\xff','\xbf','\xff','\xff','\xff',
  309. '\xf7','\xfd','\x7f','\x1f','\x70','\xff','\xff','\xff',
  310. '\xf7','\x3d','\x00','\xe7','\x67','\xff','\xff','\xff',
  311. '\xf7','\xdd','\x7f','\xfb','\x6f','\xff','\xff','\xff',
  312. '\xf7','\xe5','\x7f','\xfb','\xef','\xfe','\xff','\xff',
  313. '\xf7','\xf9','\x7f','\xfb','\xef','\xfe','\xff','\xff',
  314. '\xf7','\xfa','\x7f','\xfb','\xef','\xfd','\xff','\xff',
  315. '\xf7','\xfc','\x7f','\xfb','\xef','\xfd','\xff','\xff',
  316. '\xf7','\xfc','\x7f','\xfb','\xef','\xfb','\xff','\xff',
  317. '\xf7','\xfc','\x7f','\xfb','\xef','\xfb','\xff','\xff',
  318. '\xf7','\xfe','\x7f','\xf9','\xef','\xfb','\xff','\xff',
  319. '\xf7','\xfe','\x7f','\xf9','\xef','\x87','\xff','\xff',
  320. '\xf7','\xfe','\x7f','\xf9','\xef','\xb7','\xff','\xff',
  321. '\xf7','\xfe','\x7f','\xf9','\xf7','\xb7','\xff','\xff',
  322. '\xf7','\xfc','\x7f','\xf3','\xf7','\xb7','\xff','\xff',
  323. '\xf7','\xfc','\x7f','\xe7','\xfb','\xb7','\xff','\xff',
  324. '\xf7','\xfa','\x7f','\x1f','\xfc','\xb7','\xff','\xff',
  325. '\xf7','\x7a','\x78','\xff','\xff','\xb7','\xff','\xff',
  326. '\xf7','\x36','\x70','\xff','\xff','\x37','\xff','\xff',
  327. '\xf7','\x36','\x70','\xff','\xff','\x77','\xff','\xff',
  328. '\xf7','\x4e','\x70','\xff','\xff','\x77','\xff','\xff',
  329. '\xf7','\x1e','\x00','\xff','\xff','\x77','\xff','\xff',
  330. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xff','\xff',
  331. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xff','\xff',
  332. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xff','\xff',
  333. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xff','\xff',
  334. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xff','\xff',
  335. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xff','\xff',
  336. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xfe','\xff',
  337. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xf0','\xff',
  338. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xe7','\xff',
  339. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xef','\xff',
  340. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xcf','\xff',
  341. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\x3f','\xff',
  342. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\x7f','\xf8',
  343. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xff','\xe7',
  344. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xff','\xef',
  345. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xff','\xef',
  346. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xff','\xe0',
  347. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xff','\xfe',
  348. '\xf7','\xfe','\x7f','\xff','\xff','\x77','\xc0','\xfe',
  349. '\xf7','\xfe','\x7f','\xff','\xff','\x7b','\xdf','\xc0',
  350. '\xf7','\xfe','\x7f','\xff','\xff','\x7b','\xdf','\x9f',
  351. '\xf7','\xfe','\x7f','\xff','\xff','\x7b','\xdf','\xbf',
  352. '\xf7','\xfc','\x7f','\xff','\xff','\x7b','\xdf','\xbf',
  353. '\xf7','\xfd','\x7f','\xff','\xff','\x7b','\xdf','\x81',
  354. '\xf7','\xfd','\x7f','\xff','\xff','\x7b','\xdf','\xfd',
  355. '\xf7','\xfd','\x7f','\xff','\xff','\x7b','\xdf','\xfd',
  356. '\xf7','\xfd','\x7f','\x3f','\xf8','\x3d','\xdf','\xfd',
  357. '\xf7','\x0d','\x00','\xcf','\xfb','\xbd','\xdf','\xfd',
  358. '\xf7','\x22','\x60','\xe7','\xf7','\x9d','\xdf','\xfd',
  359. '\xf7','\x38','\x70','\xf7','\xf7','\xdd','\xdf','\xfd',
  360. '\xf7','\xfc','\x7f','\xf3','\xf7','\xcd','\xdf','\xfd',
  361. '\xf7','\xfc','\x7f','\xfb','\xf7','\xe5','\xdf','\xfd',
  362. '\xf7','\xfe','\x7f','\xfb','\xf7','\xf8','\xdf','\xfd',
  363. '\xf7','\xfe','\x7f','\xfb','\xf7','\xfe','\xdf','\xfd',
  364. '\xf7','\xfe','\x7f','\xfb','\xf7','\xfe','\xdf','\xfd',
  365. '\xf7','\xfe','\x7f','\xfb','\xf7','\xfe','\xdf','\xfd',
  366. '\xf7','\xfc','\x7f','\xfb','\xf7','\xfe','\xdf','\xfd',
  367. '\xf7','\xfc','\x7f','\xf3','\xf7','\xfe','\xdf','\xfd',
  368. '\xf7','\xf8','\x7f','\xf3','\xf7','\xfe','\xdf','\xfd',
  369. '\xf3','\xf2','\x7f','\xf3','\xf7','\xfe','\xdf','\xfd',
  370. '\x03','\xe6','\x7f','\xf3','\xf8','\xfe','\xdf','\xfd',
  371. '\xfb','\xce','\x7f','\x03','\xfe','\xfe','\xdf','\xfd',
  372. '\xfb','\x1e','\x7f','\xfb','\xff','\xfe','\xdf','\xfd',
  373. '\xfb','\x7e','\x00','\xff','\xff','\xfe','\xdf','\xfd',
  374. '\xfb','\xfe','\x7f','\xff','\xff','\xfe','\xdf','\xfd',
  375. '\xf9','\xfe','\x7f','\xff','\x7f','\xfe','\xdf','\xfd',
  376. '\x7d','\xfe','\x7f','\xff','\x7f','\xff','\xdf','\xfd',
  377. '\x05','\xff','\x7f','\xff','\x7f','\xff','\xdf','\xfd',
  378. '\xf9','\xff','\x3f','\xff','\x3f','\xff','\xdf','\xfd',
  379. '\xff','\xff','\x7f','\xff','\xbf','\xff','\xdf','\xfd',
  380. '\xff','\xff','\x7f','\xfe','\xdf','\xff','\xdf','\xfd',
  381. '\xff','\xff','\xff','\xfe','\xcf','\xff','\xdf','\xfd',
  382. '\xff','\xff','\xff','\x00','\xe0','\xff','\xdf','\xfd',
  383. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xfd',
  384. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xfd',
  385. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xfd',
  386. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xfd',
  387. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xfd',
  388. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xfd',
  389. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xe1',
  390. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xdf',
  391. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xdf',
  392. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xbf',
  393. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\x81',
  394. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xfc',
  395. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xfe',
  396. '\xff','\xff','\xff','\xff','\xff','\xff','\xdf','\xfe',
  397. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xe0',
  398. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xdf',
  399. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xdf',
  400. '\xff','\xff','\xff','\xff','\xff','\xff','\x3f','\xdf',
  401. '\xff','\xff','\xff','\xff','\xff','\xff','\x3f','\xc0',
  402. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
  403. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
  404. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
  405. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
  406. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
  407. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
  408. '\xff','\xff','\xff','\xff','\xff','\xff','\x7f','\xff',
  409. '\xff','\xff','\xff','\xff','\xff','\xff','\x7f','\xff',
  410. '\xff','\xff','\xff','\xff','\xff','\xff','\x7f','\xff',
  411. '\xff','\xff','\xff','\xff','\xff','\xff','\x7f','\xce',
  412. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xc0',
  413. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xfd',
  414. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xfd',
  415. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xfb',
  416. '\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xf3',
  417. '\xff','\xff','\xff','\xff','\xff','\xff','\xff','\xf7',
  418. '\xff','\xff','\xff','\xff','\xff','\xff','\xff','\xff',
  419. '\xff','\xff','\xff','\xff','\xff','\xff','\xff','\xff'
  420. };
  421.  
  422.  
  423.  
  424.  
  425. rom BYTE str[] = "Johboh är bäst! ;)";
  426.  
  427. #endif
  428.  
  429. static void mainInit(void);
  430.  
  431.  
  432.  
  433.  
  434.  
  435. void main()
  436. {
  437.     // Inits
  438.     mainInit();
  439.     canInit();
  440.  
  441.  
  442.     #ifdef USE_GLCD
  443.         GLCD_CS_IO = 0;
  444.         glcdInit();
  445.         GLCD_CS_IO = 1;
  446.     #endif
  447.  
  448.     #ifdef USE_ADC
  449.         adcInit(TRUE,0b1011);
  450.     #endif
  451.  
  452.     while(1)
  453.     {
  454.         TICK currentTick = tickGet();
  455.         static TICK tick_led = 0;
  456.         static TICK tick_pic = 0;
  457.         static TICK tick_temperature = 0;
  458.         static TICK tick_door = 0;
  459.         static TICK bounce_door = 0;
  460.        
  461.         static BYTE lastDoorValue = DOOR_CLOSED;
  462.         static BOOL getNewTemperature = TRUE;
  463.  
  464.         static BYTE picCnt = 0;
  465.  
  466.         if ((currentTick-tick_led)>(1*TICK_1S))
  467.         {
  468.             LED0_IO=~LED0_IO;
  469.             tick_led = currentTick;
  470.         }
  471.  
  472.         #ifdef USE_GLCD
  473.         if ((currentTick-tick_pic)>(5*TICK_1S))
  474.         {
  475.             CAN_PACKET outCp;  
  476.  
  477.             GLCD_CS_IO = 0;
  478.             glcdSetStartLine(0x00);
  479.             glcdClearScr();
  480.             if (picCnt==0) glcdDisplayPic(0,0,pic);
  481.             else if (picCnt==1) glcdDisplayPic(0,0,pic2);
  482.             else if (picCnt==2) glcdPutrs(0,0,str);
  483.             else if (picCnt==3) glcdDisplayPic(0,0,pic3);
  484.             GLCD_CS_IO = 1;
  485.  
  486.             outCp.type      = ptPGM;
  487.             outCp.pgm.class = pcSENSOR;
  488.             outCp.pgm.id    = pstIR;
  489.             outCp.length    = 1;
  490.             outCp.data[0]   = picCnt;
  491.             while(!canSendMessage(outCp,PRIO_HIGH));
  492.  
  493.  
  494.             if (++picCnt>3) picCnt=0;
  495.  
  496.             tick_pic = currentTick;
  497.         }
  498.         #endif
  499.  
  500.         #ifdef USE_ADC
  501.         if ((currentTick-tick_temperature)>(2*TICK_1S) && getNewTemperature==TRUE) // Each 2 second, read temperature.
  502.         {
  503.             adcConvert(TEMPERATURE_OUTSIDE);
  504.             getNewTemperature=FALSE;
  505.             tick_temperature = currentTick;
  506.         }
  507.         #endif
  508.  
  509.         #ifdef USE_ADC
  510.         if (adcDone()) // Has temperature, send it to the bus
  511.         {
  512.             CAN_PACKET outCp;
  513.             BYTE decimal;
  514.             signed char tenth;
  515.  
  516.             temperatureRead(&tenth,&decimal);
  517.            
  518.             outCp.type=ptPGM;
  519.             outCp.pgm.class =pcSENSOR;
  520.             outCp.pgm.id    = pstTEMP_DOOR_OUTSIDE;
  521.             outCp.length    =2;
  522.             outCp.data[1]   = tenth; //  signed 10 an 1 decimal.
  523.             outCp.data[0]   = decimal; //  Decimal value, 0-9
  524.             while(!canSendMessage(outCp,PRIO_HIGH));
  525.  
  526.             getNewTemperature=TRUE;
  527.             tick_temperature = currentTick;
  528.         }
  529.         #endif
  530.  
  531.         #ifdef USE_DOOR_SW
  532.         if ((currentTick-bounce_door)>(3*TICK_100MS) && lastDoorValue != SW1_IO)
  533.         {
  534.             lastDoorValue = SW1_IO;
  535.             tick_door = 0;
  536.             bounce_door = currentTick;
  537.         }
  538.  
  539.         if ((currentTick-tick_door)>(3*TICK_1S))
  540.         {
  541.             CAN_PACKET outCp;  
  542.             outCp.type      = ptPGM;
  543.             outCp.pgm.class = pcSENSOR;
  544.             outCp.pgm.id    = pstDOOR_OUTSIDE;
  545.             outCp.length    = 1;
  546.             outCp.data[0]   = (SW1_IO==DOOR_CLOSED?0:1);
  547.             while(!canSendMessage(outCp,PRIO_HIGH));
  548.  
  549.             tick_door = currentTick;
  550.         }
  551.         #endif
  552.  
  553.  
  554.     }
  555. }
  556.  
  557.  
  558. #pragma interrupt high_isr
  559. void high_isr(void)
  560. {
  561.     canISR();
  562.  
  563.     #ifdef USE_ROTARY
  564.         if (INTCONbits.INT0IE == 1 && INTCONbits.INT0IF == 1)
  565.         {
  566.             // ROTARY_A_IO panel (nobuss)
  567.             // ROTARY_B_IO panel (nobuss)
  568.             static TICK tick_lastRotation = 0;
  569.  
  570.             if ((tickGet()-tick_lastRotation)>(5*TICK_100MS))
  571.             {  
  572.                  if (ROTARY_A_IO==1 && ROTARY_B_IO==0)
  573.                 {
  574.                     // action
  575.                     // left
  576.                 }
  577.                 else if (ROTARY_A_IO==0 && ROTARY_B_IO==1)
  578.                 {
  579.                     // action
  580.                     // Right
  581.                 }
  582.                 tick_lastRotation=tickGet();
  583.             }
  584.                
  585.             INTCONbits.INT0IF = 0;
  586.         }
  587.     #endif
  588.  
  589.     #ifdef USE_ADC
  590.         adcISR();
  591.     #endif
  592.  
  593. }
  594.  
  595.  
  596. #pragma interrupt low_isr
  597. void low_isr(void)
  598. {
  599.     #ifdef USE_PANEL_SW
  600.         if (INTCON3bits.INT1IE == 1 && INTCON3bits.INT1IF == 1)
  601.         {
  602.             // SW0_IO == panel (nobuss)
  603.             // ROTARY_SW_IO == panel (nobuss)
  604.  
  605.             TICK currentTick = tickGet();
  606.             static TICK tick_lastPanelSw = 0;
  607.             static TICK tick_lastRotSw   = 0;
  608.                
  609.             if (SW0_IO == 0 && (currentTick-tick_lastPanelSw)>(5*TICK_100MS))
  610.             {
  611.                 // action
  612.                 tick_lastPanelSw = currentTick;
  613.             }
  614.             else if (ROTARY_SW_IO == 0 && (currentTick-tick_lastRotSw)>(5*TICK_100MS))
  615.             {
  616.                 // action
  617.                 tick_lastRotSw = currentTick;
  618.             }
  619.  
  620.             INTCON3bits.INT1IF = 0;
  621.         }
  622.     #endif
  623. }
  624.  
  625.  
  626.  
  627. /*
  628. *   Function: mainInit
  629. *
  630. *   Input:  none
  631. *   Output: none
  632. *   Pre-conditions: none
  633. *   Affects: Se code
  634. *   Depends: none.
  635. */
  636. void mainInit()
  637. {
  638.     LED0_TRIS=0;   
  639.  
  640.     // Enable Interrupts
  641.     INTCONbits.GIEH = 1;
  642.     INTCONbits.GIEL = 1;
  643.  
  644.     // Enable interrupt prirority
  645.     RCONbits.IPEN=1;
  646.    
  647.     #ifdef USE_ROTARY
  648.         ROTARY_A_TRIS = 1;
  649.         ROTARY_B_TRIS = 1;
  650.         INTCONbits.INT0IF  = 0;
  651.         INTCONbits.INT0IE  = 1;
  652.         INTCON2bits.INTEDG0 = 1; // rising
  653.         // Always high prio
  654.     #endif
  655.  
  656.     #ifdef USE_PANEL_SW
  657.         ROTARY_SW_TRIS = 1;
  658.         SW0_TRIS = 1;
  659.         INTCON3bits.INT1IF = 0;
  660.         INTCON3bits.INT1IE = 1;
  661.         INTCON2bits.INTEDG1 = 0; // falling
  662.         INTCON3bits.INT1IP  = 0; // low
  663.     #endif
  664.  
  665.  
  666.     #ifdef USE_DOOR_SW
  667.         SW1_TRIS = 1;
  668.     #endif
  669.  
  670. }
  671.  
  672. /*
  673. *   Function: canParse
  674. *
  675. *   Input:  Received can message
  676. *   Output: none
  677. *   Pre-conditions: canInit and received packet.
  678. *   Affects: Sensors/actuators/etc. See code.
  679. *   Depends: none.
  680. */
  681. void canParse(CAN_PACKET cp)
  682. {
  683.  
  684. }
  685.  
  686.  
  687. // Below are mandantory when using bootloader
  688. // define DEBUG_MODE to use without bootloader.
  689.  
  690. #ifndef DEBUG_MODE
  691. extern void _startup (void);
  692. #pragma code _RESET_INTERRUPT_VECTOR = RM_RESET_VECTOR
  693. void _reset (void)
  694. {
  695.     _asm goto _startup _endasm
  696. }
  697. #pragma code
  698. #endif
  699.  
  700. #pragma code _HIGH_INTERRUPT_VECTOR = RM_HIGH_INTERRUPT_VECTOR
  701. void _high_ISR (void)
  702. {
  703.     _asm GOTO high_isr _endasm
  704. }
  705. #pragma code
  706.  
  707. #pragma code _LOW_INTERRUPT_VECTOR = RM_LOW_INTERRUPT_VECTOR
  708. void _low_ISR (void)
  709. {
  710.     _asm GOTO low_isr _endasm
  711. }
  712. #pragma code
  713.  
  714.  
  715.  
  716.