Guest User

Untitled

a guest
Feb 19th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.21 KB | None | 0 0
  1.  
  2. /*
  3. Thermistor output to LCD
  4. */
  5.  
  6. #include <math.h>
  7. #include <LiquidCrystal.h>
  8.  
  9. // Arduino to LCD pin configuration
  10. #define PIN_SCE 7 //To LCD Pin 3
  11. #define PIN_RESET 6 //To LCD Pin 4
  12. #define PIN_DC 5 //To LCD Pin 5
  13. #define PIN_SDIN 4 //To LCD Pin 6
  14. #define PIN_SCLK 3 //To LCD Pin 7
  15.  
  16. // Configuration for the LCD
  17. #define LCD_C LOW
  18. #define LCD_D HIGH
  19. #define LCD_CMD 0
  20.  
  21. // Size of the LCD
  22. #define LCD_X 84
  23. #define LCD_Y 48
  24.  
  25.  
  26. int scrollPosition = -10;
  27.  
  28. static const byte ASCII[][5] =
  29. {
  30. {0x00, 0x00, 0x00, 0x00, 0x00} // 20
  31. ,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
  32. ,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
  33. ,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
  34. ,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
  35. ,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
  36. ,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
  37. ,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
  38. ,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
  39. ,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
  40. ,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
  41. ,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
  42. ,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
  43. ,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
  44. ,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
  45. ,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
  46. ,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
  47. ,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
  48. ,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
  49. ,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
  50. ,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
  51. ,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
  52. ,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
  53. ,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
  54. ,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
  55. ,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
  56. ,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
  57. ,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
  58. ,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
  59. ,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
  60. ,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
  61. ,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
  62. ,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
  63. ,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
  64. ,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
  65. ,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
  66. ,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
  67. ,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
  68. ,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
  69. ,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
  70. ,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
  71. ,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
  72. ,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
  73. ,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
  74. ,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
  75. ,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
  76. ,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
  77. ,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
  78. ,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
  79. ,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
  80. ,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
  81. ,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
  82. ,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
  83. ,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
  84. ,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
  85. ,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
  86. ,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
  87. ,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
  88. ,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
  89. ,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
  90. ,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c ¥
  91. ,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
  92. ,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
  93. ,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
  94. ,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
  95. ,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
  96. ,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
  97. ,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
  98. ,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
  99. ,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
  100. ,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
  101. ,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
  102. ,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
  103. ,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
  104. ,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
  105. ,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
  106. ,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
  107. ,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
  108. ,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
  109. ,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
  110. ,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
  111. ,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
  112. ,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
  113. ,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
  114. ,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
  115. ,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
  116. ,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
  117. ,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
  118. ,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
  119. ,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
  120. ,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
  121. ,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
  122. ,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
  123. ,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
  124. ,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ←
  125. ,{0x00, 0x06, 0x09, 0x09, 0x06} // 7f →
  126. };
  127.  
  128.  
  129. void LcdCharacter(char character)
  130. {
  131. LcdWrite(LCD_D, 0x00);
  132. for (int index = 0; index < 5; index++)
  133. {
  134. LcdWrite(LCD_D, ASCII[character - 0x20][index]);
  135. }
  136. LcdWrite(LCD_D, 0x00);
  137. }
  138.  
  139.  
  140. void LcdClear(void)
  141. {
  142. for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
  143. {
  144. LcdWrite(LCD_D, 0x00);
  145. }
  146. }
  147.  
  148. void LcdInitialise(void)
  149. {
  150. pinMode(PIN_SCE, OUTPUT);
  151. pinMode(PIN_RESET, OUTPUT);
  152. pinMode(PIN_DC, OUTPUT);
  153. pinMode(PIN_SDIN, OUTPUT);
  154. pinMode(PIN_SCLK, OUTPUT);
  155.  
  156. digitalWrite(PIN_RESET, LOW);
  157. digitalWrite(PIN_RESET, HIGH);
  158.  
  159. LcdWrite(LCD_CMD, 0x21); // LCD Extended Commands.
  160. LcdWrite(LCD_CMD, 0xBf); // Set LCD Vop (Contrast). //B1
  161. LcdWrite(LCD_CMD, 0x04); // Set Temp coefficent. //0x04
  162. LcdWrite(LCD_CMD, 0x14); // LCD bias mode 1:48. //0x13
  163. LcdWrite(LCD_CMD, 0x0C); // LCD in normal mode. 0x0d for inverse
  164. LcdWrite(LCD_C, 0x20);
  165. LcdWrite(LCD_C, 0x0C);
  166. }
  167.  
  168. void LcdString(char *characters)
  169. {
  170. while (*characters)
  171. {
  172. LcdCharacter(*characters++);
  173. }
  174. }
  175.  
  176. void LcdWrite(byte dc, byte data)
  177. {
  178. digitalWrite(PIN_DC, dc);
  179. digitalWrite(PIN_SCE, LOW);
  180. shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
  181. digitalWrite(PIN_SCE, HIGH);
  182. }
  183.  
  184. /**
  185. * gotoXY routine to position cursor
  186. * x - range: 0 to 84
  187. * y - range: 0 to 5
  188. */
  189. void gotoXY(int x, int y)
  190. {
  191. LcdWrite( 0, 0x80 | x); // Column.
  192. LcdWrite( 0, 0x40 | y); // Row.
  193. }
  194.  
  195. //Upper left hand box definition
  196. void drawBoxes(void)
  197. {
  198. int j;
  199. for(j = 0; j < 42; j++) // top
  200. {
  201. gotoXY(j, 0);
  202. LcdWrite(1, 0x01);
  203. }
  204.  
  205. for(j = 0; j < 42; j++) //Bottom
  206. {
  207. gotoXY(j, 2);
  208. LcdWrite(1, 0x80);
  209. }
  210.  
  211. for(j = 0; j < 3; j++) // Right
  212. {
  213. gotoXY(42, j);
  214. LcdWrite(1, 0xff);
  215. }
  216.  
  217. for(j = 0; j < 3; j++) // Left
  218. {
  219. gotoXY(0, j);
  220. LcdWrite(1, 0xff);
  221. }
  222.  
  223. for(j = 42; j < 84; j++) // top
  224. {
  225. gotoXY(j, 0);
  226. LcdWrite(1, 0x01);
  227. }
  228.  
  229. for(j = 42; j < 84; j++) //Bottom
  230. {
  231. gotoXY(j, 2);
  232. LcdWrite(1, 0x80);
  233. }
  234.  
  235. for(j = 0; j < 3; j++) // Right
  236. {
  237. gotoXY(83, j);
  238. LcdWrite(1, 0xff);
  239. }
  240.  
  241. for(j = 0; j < 3; j++) // Left
  242. {
  243. gotoXY(42, j);
  244. LcdWrite(1, 0xff);
  245. }
  246. for(j = 0; j < 83; j++) // top
  247. {
  248. gotoXY(j, 3);
  249. LcdWrite(1, 0x01);
  250. }
  251.  
  252. for(j = 0; j < 83; j++) //Bottom
  253. {
  254. gotoXY(j, 5);
  255. LcdWrite(1, 0x80);
  256. }
  257.  
  258. for(j = 0; j < 6; j++) // Right
  259. {
  260. gotoXY(0, j);
  261. LcdWrite(1, 0xff);
  262. }
  263.  
  264. for(j = 0; j < 6; j++) // Left
  265. {
  266. gotoXY(83, j);
  267. LcdWrite(1, 0xff);
  268. }
  269.  
  270. }
  271.  
  272.  
  273. void Scroll(String message)
  274. {
  275. for (int i = scrollPosition; i < scrollPosition + 11; i++)
  276. {
  277. if ((i >= message.length()) || (i < 0))
  278. {
  279. LcdCharacter(' ');
  280. }
  281. else
  282. {
  283. LcdCharacter(message.charAt(i));
  284. }
  285. }
  286. scrollPosition++;
  287. if ((scrollPosition >= message.length()) && (scrollPosition > 0))
  288. {
  289. scrollPosition = -10;
  290. }
  291. }
  292.  
  293. void setup(void)
  294. {
  295. Serial.begin(9600);
  296.  
  297. LcdInitialise();
  298. LcdClear();
  299. drawBoxes();
  300.  
  301. }
  302.  
  303. // Thermistor math to determine temperature
  304.  
  305. double Thermister(int RawADC) {
  306. double Temp;
  307. Temp = log(((10240000/RawADC) - 10000));
  308. Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
  309. Temp = Temp - 273.15; // Convert Kelvin to Celcius
  310. return Temp;
  311. char buffer[32];
  312. sprintf(buffer, "%.2f", 123.45);
  313. //LcdWrite(buffer);
  314. }
  315.  
  316.  
  317.  
  318. void loop(void)
  319. {
  320. gotoXY(1,1);
  321. gotoXY(1,4);
  322. LcdString(" Testing |");
  323. delay(100);
  324. gotoXY(1,4);
  325. LcdString(" Testing /");
  326. delay(100);
  327. gotoXY(1,4);
  328. LcdString(" Testing -");
  329. delay(100);
  330. gotoXY(1,4);
  331. LcdString(" Testing \\");
  332. delay(100);
  333. gotoXY(1,4);
  334. LcdString(" Testing |");
  335. delay(100);
  336. gotoXY(1,4);
  337.  
  338. }
Add Comment
Please, Sign In to add comment