Advertisement
Guest User

Untitled

a guest
Jan 9th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.28 KB | None | 0 0
  1. // include the library code:
  2. #include <LiquidCrystal.h>
  3.  
  4. // these constants won't change. But you can change the size of
  5. // your LCD using them:
  6. const int numRows = 2;
  7. const int numCols = 16;
  8.  
  9. // initialize the library with the numbers of the interface pins
  10. LiquidCrystal lcd(12,11,10,5,4,3,2);
  11. // RS, RW, Enable, 4,5,6,7 (Refer to the back of your LCD for details)
  12.  
  13.  
  14. void setup() {
  15. Serial.begin(9600);
  16. // set up the LCD's number of rows and columns:
  17. lcd.begin(numRows, numCols);
  18. lcd.clear();
  19. lcd.setCursor(0,0);
  20. lcd.print("**LCD SMARTIE**");
  21. lcd.setCursor(0,1);
  22. lcd.print("on Arduino");
  23. }
  24.  
  25. byte serial_getch(){
  26.  
  27. int incoming;
  28. while (Serial.available()==0){}
  29. // read the incoming byte:
  30. incoming = Serial.read();
  31.  
  32. return (byte) (incoming &0xff);
  33. }
  34.  
  35. void loop(){
  36.  
  37. byte rxbyte;
  38. byte temp;
  39.  
  40. rxbyte = serial_getch();
  41.  
  42. if (rxbyte == 254) //Matrix Orbital uses 254 prefix for commands
  43. {
  44. switch (serial_getch())
  45. {
  46. case 66: //backlight on (at previously set brightness)
  47. // not implemented
  48.  
  49. break;
  50. case 70: //backlight off
  51. // not implemented
  52. break;
  53. case 71: //set cursor position
  54. temp = (serial_getch() - 1); //get column byte
  55. switch (serial_getch()) //get row byte
  56. {
  57. //line 1 is already set up
  58. case 2:
  59. temp += 0x40;
  60. break;
  61. case 3:
  62. temp += 0x14;
  63. break;
  64. case 4:
  65. temp += 0x54;
  66. break;
  67. default:
  68. break;
  69. }
  70. lcd.command(0b10000000 + temp);
  71. break;
  72. case 72: //cursor home (reset display position)
  73. lcd.command(2);
  74. break;
  75. case 74: //show underline cursor
  76. lcd.command(0b00001110);
  77. break;
  78. case 75: //underline cursor off
  79. case 84: //block cursor off
  80. lcd.command(0b00001100);
  81. break;
  82. case 76: //move cursor left
  83. lcd.command(16);
  84. break;
  85. case 77: //move cursor right
  86. lcd.command(20);
  87. break;
  88. case 78: //define custom char
  89. lcd.command(64 + (serial_getch() * 8)); //get+set char address
  90. for (temp = 7; temp != 0; temp--)
  91. {
  92. lcd.print(serial_getch()); //get each pattern byte
  93. }
  94. break;
  95. case 83: //show blinking block cursor
  96. lcd.command(0b00001111);
  97. break;
  98. case 86: //GPO OFF
  99. //implement later
  100. break;
  101. case 87: //GPO ON
  102. /*temp = serial_getch();
  103. if (temp == 1)
  104. {
  105. GPO1 = GPO_ON;
  106. }*/
  107. break;
  108. case 88: //clear display, cursor home
  109. lcd.command(1);
  110. break;
  111. case 152: //set and remember (doesn't save value, though)
  112. case 153: //set backlight brightness
  113. //not implemented
  114. break;
  115.  
  116. //these commands ignored (no parameters)
  117. case 35: //read serial number
  118. case 36: //read version number
  119. case 55: //read module type
  120. case 59: //exit flow-control mode
  121. case 65: //auto transmit keypresses
  122. case 96: //auto-repeat mode off (keypad)
  123. case 67: //auto line-wrap on
  124. case 68: //auto line-wrap off
  125. case 81: //auto scroll on
  126. case 82: //auto scroll off
  127. case 104: //init horiz bar graph
  128. case 109: //init med size digits
  129. case 115: //init narrow vert bar graph
  130. case 118: //init wide vert bar graph
  131. break;
  132. default:
  133. //all other commands ignored and parameter byte discarded
  134. temp = serial_getch(); //dump the command code
  135. break;
  136. }
  137. return;
  138. } //END OF COMMAND HANDLER
  139.  
  140. //change accented char to plain, detect and change descenders
  141. //NB descenders only work on 5x10 displays. This lookup table works
  142. // with my DEM-20845 (Display Elektronik GmbH) LCD using KS0066 chip.
  143. switch (rxbyte)
  144. {
  145. //chars that have direct equivalent in LCD charmap
  146. /* case 0x67: //g
  147. rxbyte = 0xE7;
  148. break;
  149. case 0x6A: //j
  150. rxbyte = 0xEA;
  151. break;
  152. case 0x70: //p
  153. rxbyte = 0xF0;
  154. break;
  155. case 0x71: //q
  156. rxbyte = 0xF1;
  157. break;
  158. case 0x79: //y
  159. rxbyte = 0xF9;
  160. break;
  161. */ case 0xE4: //ASCII "a" umlaut
  162. rxbyte = 0xE1;
  163. break;
  164. case 0xF1: //ASCII "n" tilde
  165. rxbyte = 0xEE;
  166. break;
  167. case 0xF6: //ASCII "o" umlaut
  168. rxbyte = 0xEF; //was wrong in v0.86
  169. break;
  170. case 0xFC: //ASCII "u" umlaut
  171. rxbyte = 0xF5;
  172. break;
  173.  
  174. //accented -> plain equivalent
  175. //and misc symbol translation
  176. case 0xA3: //sterling (pounds)
  177. rxbyte = 0xED;
  178. break;
  179. /* case 0xB0: //degrees symbol
  180. rxbyte = 0xDF;
  181. break;
  182. */ case 0xB5: //mu
  183. rxbyte = 0xE4;
  184. break;
  185. case 0xC0: //"A" variants
  186. case 0xC1:
  187. case 0xC2:
  188. case 0xC3:
  189. case 0xC4:
  190. case 0xC5:
  191. rxbyte = 0x41;
  192. break;
  193. case 0xC8: //"E" variants
  194. case 0xC9:
  195. case 0xCA:
  196. case 0xCB:
  197. rxbyte = 0x45;
  198. break;
  199. case 0xCC: //"I" variants
  200. case 0xCD:
  201. case 0xCE:
  202. case 0xCF:
  203. rxbyte = 0x49;
  204. break;
  205. case 0xD1: //"N" tilde -> plain "N"
  206. rxbyte = 0x43;
  207. break;
  208. case 0xD2: //"O" variants
  209. case 0xD3:
  210. case 0xD4:
  211. case 0xD5:
  212. case 0xD6:
  213. case 0xD8:
  214. rxbyte = 0x4F;
  215. break;
  216. case 0xD9: //"U" variants
  217. case 0xDA:
  218. case 0xDB:
  219. case 0xDC:
  220. rxbyte = 0x55;
  221. break;
  222. case 0xDD: //"Y" acute -> "Y"
  223. rxbyte = 0x59;
  224. break;
  225. /* case 0xDF: //beta //mucks up LCDSmartie's degree symbol??
  226. rxbyte = 0xE2;
  227. break;
  228. */ case 0xE0: //"a" variants except umlaut
  229. case 0xE1:
  230. case 0xE2:
  231. case 0xE3:
  232. case 0xE5:
  233. rxbyte = 0x61;
  234. break;
  235. case 0xE7: //"c" cedilla -> "c"
  236. rxbyte = 0x63;
  237. break;
  238. case 0xE8: //"e" variants
  239. case 0xE9:
  240. case 0xEA:
  241. case 0xEB:
  242. rxbyte = 0x65;
  243. break;
  244. case 0xEC: //"i" variants
  245. case 0xED:
  246. case 0xEE:
  247. case 0xEF:
  248. rxbyte = 0x69;
  249. break;
  250. case 0xF2: //"o" variants except umlaut
  251. case 0xF3:
  252. case 0xF4:
  253. case 0xF5:
  254. case 0xF8:
  255. rxbyte = 0x6F;
  256. break;
  257. case 0xF7: //division symbol
  258. rxbyte = 0xFD;
  259. break;
  260. case 0xF9: //"u" variants except umlaut
  261. case 0xFA:
  262. case 0xFB:
  263. rxbyte = 0x75;
  264. break;
  265. default:
  266. break;
  267. }
  268.  
  269. lcd.print(rxbyte); //otherwise a plain char so we print it to lcd
  270. return;
  271.  
  272.  
  273. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement