HT1632C

SureElectronics sells some low cost led dot matrix displays. The 32x16 bicolor(red, green) uses the new HT1632C and I couldn't find any code to arduino that works in this displays.

I put some schematic here using my Arduino Mega2560 a RTC DS1307 and two 3216 led matrix working together.

A video with this configuration running is available at youtube. http://www.youtube.com/watch?v=2ZPACHAZxWg

You can follow the development on this thread at Arduino Forum.

A reusable library is available here, on GitHub.

Even though the reusable library mentioned above is very powerful, it was originally not made for supporting the 32x16 bicolor(red, green) board type. So, changes have been made to adapt it and are posted here in this link, on GitHub.

Page constructed by Wagner Sartori Junior with help of florinc, Tim Gilmore and westfw on forum.

BUGS:

  • In this code, it lasts more than 1 second to refresh(loop). We can use shadowram on plot function to compare before send that is faster I think.

TODO:

  • A reusable library
  • Draw char(an easier and clever way)
  • Scrolling
  • Blink

Code: ht1632c.h

  1. /*
  2.  * ht1632.h
  3.  * defintions for Holtek ht1632 LED driver.
  4.  */
  5.  
  6.  
  7. #if !defined(DEBUGPRINT)
  8. #define DEBUGPRINT(fmt, args...)
  9. #endif
  10.  
  11. /*
  12.  * commands written to the chip consist of a 3 bit "ID", followed by
  13.  * either 9 bits of "Command code" or 7 bits of address + 4 bits of data.
  14.  */
  15. #define HT1632_ID_CMD 4         /* ID = 100 - Commands */
  16. #define HT1632_ID_RD  6         /* ID = 110 - Read RAM */
  17. #define HT1632_ID_WR  5         /* ID = 101 - Write RAM */
  18.  
  19. #define HT1632_CMD_SYSDIS 0x00  /* CMD= 0000-0000-x Turn off oscil */
  20. #define HT1632_CMD_SYSON  0x01  /* CMD= 0000-0001-x Enable system oscil */
  21. #define HT1632_CMD_LEDOFF 0x02  /* CMD= 0000-0010-x LED duty cycle gen off */
  22. #define HT1632_CMD_LEDON  0x03  /* CMD= 0000-0011-x LEDs ON */
  23. #define HT1632_CMD_BLOFF  0x08  /* CMD= 0000-1000-x Blink ON */
  24. #define HT1632_CMD_BLON   0x09  /* CMD= 0000-1001-x Blink Off */
  25. #define HT1632_CMD_SLVMD  0x10  /* CMD= 0001-0xxx-x Slave Mode */
  26. #define HT1632_CMD_MSTMD  0x18  /* CMD= 0001-10xx-x Use on-chip clock */
  27. #define HT1632_CMD_EXTCLK 0x1C  /* CMD= 0001-11xx-x Use external clock */
  28. #define HT1632_CMD_COMS00 0x20  /* CMD= 0010-ABxx-x commons options */
  29. #define HT1632_CMD_COMS01 0x24  /* CMD= 0010-ABxx-x commons options */
  30. #define HT1632_CMD_COMS10 0x28  /* CMD= 0010-ABxx-x commons options */
  31. #define HT1632_CMD_COMS11 0x2C  /* CMD= 0010-ABxx-x commons options */
  32. #define HT1632_CMD_PWM    0xA0  /* CMD= 101x-PPPP-x PWM duty cycle */

font1.h

  1. //Start the letter definition and put it in the FLASH memory
  2.  
  3. //Spc 20
  4. char CH200[] PROGMEM = "11111111";
  5. char CH201[] PROGMEM = "11111111";
  6. char CH202[] PROGMEM = "11111111";
  7. char CH203[] PROGMEM = "11111111";
  8. char CH204[] PROGMEM = "11111111";
  9. char CH205[] PROGMEM = "11111111";
  10. char CH206[] PROGMEM = "11111111";
  11. char CH207[] PROGMEM = "11111111";
  12. //! 21
  13. char CH210[] PROGMEM = "11110111";
  14. char CH211[] PROGMEM = "11100011";
  15. char CH212[] PROGMEM = "11100011";
  16. char CH213[] PROGMEM = "11100011";
  17. char CH214[] PROGMEM = "11110111";
  18. char CH215[] PROGMEM = "11111111";
  19. char CH216[] PROGMEM = "11110111";
  20. char CH217[] PROGMEM = "11111111";
  21. //qt 22
  22. char CH220[] PROGMEM = "11001100";
  23. char CH221[] PROGMEM = "11001100";
  24. char CH222[] PROGMEM = "11001100";
  25. char CH223[] PROGMEM = "11001100";
  26. char CH224[] PROGMEM = "11111111";
  27. char CH225[] PROGMEM = "11111111";
  28. char CH226[] PROGMEM = "11111111";
  29. char CH227[] PROGMEM = "11111111";
  30. //# 23
  31. char CH230[] PROGMEM = "11101101";
  32. char CH231[] PROGMEM = "11101101";
  33. char CH232[] PROGMEM = "11000000";
  34. char CH233[] PROGMEM = "11101101";
  35. char CH234[] PROGMEM = "11000000";
  36. char CH235[] PROGMEM = "11101101";
  37. char CH236[] PROGMEM = "11101101";
  38. char CH237[] PROGMEM = "11111111";
  39. //$ 24
  40. char CH240[] PROGMEM = "11110111";
  41. char CH241[] PROGMEM = "11000001";
  42. char CH242[] PROGMEM = "10110111";
  43. char CH243[] PROGMEM = "11000001";
  44. char CH244[] PROGMEM = "11110110";
  45. char CH245[] PROGMEM = "11000001";
  46. char CH246[] PROGMEM = "11110111";
  47. char CH247[] PROGMEM = "11111111";
  48. //% 25
  49. char CH250[] PROGMEM = "11011110";
  50. char CH251[] PROGMEM = "10101101";
  51. char CH252[] PROGMEM = "11011011";
  52. char CH253[] PROGMEM = "11110111";
  53. char CH254[] PROGMEM = "11101101";
  54. char CH255[] PROGMEM = "11011010";
  55. char CH256[] PROGMEM = "10111101";
  56. char CH257[] PROGMEM = "11111111";
  57. //& 26
  58. char CH260[] PROGMEM = "11100111";
  59. char CH261[] PROGMEM = "11011011";
  60. char CH262[] PROGMEM = "11010111";
  61. char CH263[] PROGMEM = "11101111";
  62. char CH264[] PROGMEM = "11010110";
  63. char CH265[] PROGMEM = "11011001";
  64. char CH266[] PROGMEM = "11100010";
  65. char CH267[] PROGMEM = "11111111";
  66. //' 27
  67. char CH270[] PROGMEM = "11111100";
  68. char CH271[] PROGMEM = "11111001";
  69. char CH272[] PROGMEM = "11110011";
  70. char CH273[] PROGMEM = "11100111";
  71. char CH274[] PROGMEM = "11001111";
  72. char CH275[] PROGMEM = "11111111";
  73. char CH276[] PROGMEM = "11111111";
  74. char CH277[] PROGMEM = "11111111";
  75. //( 28
  76. char CH280[] PROGMEM = "11100111";
  77. char CH281[] PROGMEM = "11011111";
  78. char CH282[] PROGMEM = "10111111";
  79. char CH283[] PROGMEM = "10111111";
  80. char CH284[] PROGMEM = "10111111";
  81. char CH285[] PROGMEM = "11011111";
  82. char CH286[] PROGMEM = "11100111";
  83. char CH287[] PROGMEM = "11111111";
  84. //) 29
  85. char CH290[] PROGMEM = "11110011";
  86. char CH291[] PROGMEM = "11111101";
  87. char CH292[] PROGMEM = "11111110";
  88. char CH293[] PROGMEM = "11111110";
  89. char CH294[] PROGMEM = "11111110";
  90. char CH295[] PROGMEM = "11111101";
  91. char CH296[] PROGMEM = "11110011";
  92. char CH297[] PROGMEM = "11111111";
  93. //* 2A
  94. char CH2A0[] PROGMEM = "10111110";
  95. char CH2A1[] PROGMEM = "11011101";
  96. char CH2A2[] PROGMEM = "11101011";
  97. char CH2A3[] PROGMEM = "10000000";
  98. char CH2A4[] PROGMEM = "11101011";
  99. char CH2A5[] PROGMEM = "11011101";
  100. char CH2A6[] PROGMEM = "10111110";
  101. char CH2A7[] PROGMEM = "11111111";
  102. //+ 2B
  103. char CH2B0[] PROGMEM = "11110111";
  104. char CH2B1[] PROGMEM = "11110111";
  105. char CH2B2[] PROGMEM = "11110111";
  106. char CH2B3[] PROGMEM = "10000000";
  107. char CH2B4[] PROGMEM = "11110111";
  108. char CH2B5[] PROGMEM = "11110111";
  109. char CH2B6[] PROGMEM = "11110111";
  110. char CH2B7[] PROGMEM = "11111111";
  111. //, 2C
  112. char CH2C0[] PROGMEM = "11111111";
  113. char CH2C1[] PROGMEM = "11111111";
  114. char CH2C2[] PROGMEM = "11111111";
  115. char CH2C3[] PROGMEM = "11100111";
  116. char CH2C4[] PROGMEM = "11000111";
  117. char CH2C5[] PROGMEM = "11000111";
  118. char CH2C6[] PROGMEM = "11011111";
  119. char CH2C7[] PROGMEM = "11111111";
  120. // 2D
  121. char CH2D0[] PROGMEM = "11111111";
  122. char CH2D1[] PROGMEM = "11111111";
  123. char CH2D2[] PROGMEM = "11111111";
  124. char CH2D3[] PROGMEM = "11000000";
  125. char CH2D4[] PROGMEM = "11000000";
  126. char CH2D5[] PROGMEM = "11111111";
  127. char CH2D6[] PROGMEM = "11111111";
  128. char CH2D7[] PROGMEM = "11111111";
  129. //. 2E
  130. char CH2E0[] PROGMEM = "11111111";
  131. char CH2E1[] PROGMEM = "11111111";
  132. char CH2E2[] PROGMEM = "11111111";
  133. char CH2E3[] PROGMEM = "11100011";
  134. char CH2E4[] PROGMEM = "11000001";
  135. char CH2E5[] PROGMEM = "11000001";
  136. char CH2E6[] PROGMEM = "11100011";
  137. char CH2E7[] PROGMEM = "11111111";
  138. /// 2F
  139. char CH2F0[] PROGMEM = "11111110";
  140. char CH2F1[] PROGMEM = "11111100";
  141. char CH2F2[] PROGMEM = "11111001";
  142. char CH2F3[] PROGMEM = "11110011";
  143. char CH2F4[] PROGMEM = "11100111";
  144. char CH2F5[] PROGMEM = "11001111";
  145. char CH2F6[] PROGMEM = "11011111";
  146. char CH2F7[] PROGMEM = "11111111";
  147. //0 30
  148. char CH300[] PROGMEM = "11100011";
  149. char CH301[] PROGMEM = "11011101";
  150. char CH302[] PROGMEM = "10111010";
  151. char CH303[] PROGMEM = "10110110";
  152. char CH304[] PROGMEM = "10101110";
  153. char CH305[] PROGMEM = "11011101";
  154. char CH306[] PROGMEM = "11100011";
  155. char CH307[] PROGMEM = "11111111";
  156. //1 31
  157. char CH310[] PROGMEM = "11110111";
  158. char CH311[] PROGMEM = "11100111";
  159. char CH312[] PROGMEM = "11010111";
  160. char CH313[] PROGMEM = "11110111";
  161. char CH314[] PROGMEM = "11110111";
  162. char CH315[] PROGMEM = "11110111";
  163. char CH316[] PROGMEM = "11000001";
  164. char CH317[] PROGMEM = "11111111";
  165. //2 32
  166. char CH320[] PROGMEM = "11100011";
  167. char CH321[] PROGMEM = "11011101";
  168. char CH322[] PROGMEM = "11111101";
  169. char CH323[] PROGMEM = "11111011";
  170. char CH324[] PROGMEM = "11110111";
  171. char CH325[] PROGMEM = "11101111";
  172. char CH326[] PROGMEM = "11000000";
  173. char CH327[] PROGMEM = "11111111";
  174. //3 33
  175. char CH330[] PROGMEM = "11000001";
  176. char CH331[] PROGMEM = "10111110";
  177. char CH332[] PROGMEM = "11111110";
  178. char CH333[] PROGMEM = "11110001";
  179. char CH334[] PROGMEM = "11111110";
  180. char CH335[] PROGMEM = "10111110";
  181. char CH336[] PROGMEM = "11000001";
  182. char CH337[] PROGMEM = "11111111";
  183. //4 34
  184. char CH340[] PROGMEM = "11110011";
  185. char CH341[] PROGMEM = "11101011";
  186. char CH342[] PROGMEM = "11011011";
  187. char CH343[] PROGMEM = "10000000";
  188. char CH344[] PROGMEM = "11111011";
  189. char CH345[] PROGMEM = "11111011";
  190. char CH346[] PROGMEM = "11100001";
  191. char CH347[] PROGMEM = "11111111";
  192. //5 35
  193. char CH350[] PROGMEM = "10000000";
  194. char CH351[] PROGMEM = "10111111";
  195. char CH352[] PROGMEM = "10100001";
  196. char CH353[] PROGMEM = "10011110";
  197. char CH354[] PROGMEM = "11111110";
  198. char CH355[] PROGMEM = "10111110";
  199. char CH356[] PROGMEM = "11000001";
  200. char CH357[] PROGMEM = "11111111";
  201. //6 36
  202. char CH360[] PROGMEM = "11100001";
  203. char CH361[] PROGMEM = "11011110";
  204. char CH362[] PROGMEM = "10111111";
  205. char CH363[] PROGMEM = "10100001";
  206. char CH364[] PROGMEM = "10011110";
  207. char CH365[] PROGMEM = "10111110";
  208. char CH366[] PROGMEM = "11000001";
  209. char CH367[] PROGMEM = "11111111";
  210. //7 37
  211. char CH370[] PROGMEM = "10000000";
  212. char CH371[] PROGMEM = "10111110";
  213. char CH372[] PROGMEM = "11111101";
  214. char CH373[] PROGMEM = "11111011";
  215. char CH374[] PROGMEM = "11110111";
  216. char CH375[] PROGMEM = "11110111";
  217. char CH376[] PROGMEM = "11110111";
  218. char CH377[] PROGMEM = "11111111";
  219. //8 38
  220. char CH380[] PROGMEM = "11000001";
  221. char CH381[] PROGMEM = "10111110";
  222. char CH382[] PROGMEM = "10111110";
  223. char CH383[] PROGMEM = "11000001";
  224. char CH384[] PROGMEM = "10111110";
  225. char CH385[] PROGMEM = "10111110";
  226. char CH386[] PROGMEM = "11000001";
  227. char CH387[] PROGMEM = "11111111";
  228. //9 39
  229. char CH390[] PROGMEM = "11000001";
  230. char CH391[] PROGMEM = "10111110";
  231. char CH392[] PROGMEM = "10111110";
  232. char CH393[] PROGMEM = "11000000";
  233. char CH394[] PROGMEM = "11111110";
  234. char CH395[] PROGMEM = "10111101";
  235. char CH396[] PROGMEM = "11000011";
  236. char CH397[] PROGMEM = "11111111";
  237. //: 3A
  238. char CH3A0[] PROGMEM = "11100011";
  239. char CH3A1[] PROGMEM = "11000001";
  240. char CH3A2[] PROGMEM = "11100011";
  241. char CH3A3[] PROGMEM = "11111111";
  242. char CH3A4[] PROGMEM = "11100011";
  243. char CH3A5[] PROGMEM = "11000001";
  244. char CH3A6[] PROGMEM = "11100011";
  245. char CH3A7[] PROGMEM = "11111111";
  246. //; 3B
  247. char CH3B0[] PROGMEM = "11100011";
  248. char CH3B1[] PROGMEM = "11100011";
  249. char CH3B2[] PROGMEM = "11100011";
  250. char CH3B3[] PROGMEM = "11111111";
  251. char CH3B4[] PROGMEM = "11100011";
  252. char CH3B5[] PROGMEM = "11100011";
  253. char CH3B6[] PROGMEM = "11101111";
  254. char CH3B7[] PROGMEM = "11111111";
  255. //< 3C
  256. char CH3C0[] PROGMEM = "11110011";
  257. char CH3C1[] PROGMEM = "11100111";
  258. char CH3C2[] PROGMEM = "11001111";
  259. char CH3C3[] PROGMEM = "10011111";
  260. char CH3C4[] PROGMEM = "11001111";
  261. char CH3C5[] PROGMEM = "11100111";
  262. char CH3C6[] PROGMEM = "11110011";
  263. char CH3C7[] PROGMEM = "11111111";
  264. //= 3D
  265. char CH3D0[] PROGMEM = "11111111";
  266. char CH3D1[] PROGMEM = "10000000";
  267. char CH3D2[] PROGMEM = "10000000";
  268. char CH3D3[] PROGMEM = "11111111";
  269. char CH3D4[] PROGMEM = "10000000";
  270. char CH3D5[] PROGMEM = "10000000";
  271. char CH3D6[] PROGMEM = "11111111";
  272. char CH3D7[] PROGMEM = "11111111";
  273. //> 3E
  274. char CH3E0[] PROGMEM = "11100111";
  275. char CH3E1[] PROGMEM = "11110011";
  276. char CH3E2[] PROGMEM = "11111001";
  277. char CH3E3[] PROGMEM = "11111100";
  278. char CH3E4[] PROGMEM = "11111001";
  279. char CH3E5[] PROGMEM = "11110011";
  280. char CH3E6[] PROGMEM = "11100111";
  281. char CH3E7[] PROGMEM = "11111111";
  282. //? 3F
  283. char CH3F0[] PROGMEM = "11000001";
  284. char CH3F1[] PROGMEM = "10111110";
  285. char CH3F2[] PROGMEM = "11111001";
  286. char CH3F3[] PROGMEM = "11110111";
  287. char CH3F4[] PROGMEM = "11110111";
  288. char CH3F5[] PROGMEM = "11111111";
  289. char CH3F6[] PROGMEM = "11110111";
  290. char CH3F7[] PROGMEM = "11111111";
  291. //@ 40
  292. char CH400[] PROGMEM = "11100001";
  293. char CH401[] PROGMEM = "11011110";
  294. char CH402[] PROGMEM = "10110010";
  295. char CH403[] PROGMEM = "10101010";
  296. char CH404[] PROGMEM = "10100001";
  297. char CH405[] PROGMEM = "10111111";
  298. char CH406[] PROGMEM = "11000001";
  299. char CH407[] PROGMEM = "11111111";
  300. //A 07
  301. char CH070[] PROGMEM = "11110011";
  302. char CH071[] PROGMEM = "11101101";
  303. char CH072[] PROGMEM = "11011110";
  304. char CH073[] PROGMEM = "11000000";
  305. char CH074[] PROGMEM = "11011110";
  306. char CH075[] PROGMEM = "11011110";
  307. char CH076[] PROGMEM = "11011110";
  308. char CH077[] PROGMEM = "11111111";
  309. //B 815
  310. char CH8150[] PROGMEM = "11000001";
  311. char CH8151[] PROGMEM = "11011110";
  312. char CH8152[] PROGMEM = "11011110";
  313. char CH8153[] PROGMEM = "11000001";
  314. char CH8154[] PROGMEM = "11011110";
  315. char CH8155[] PROGMEM = "11011110";
  316. char CH8156[] PROGMEM = "11000001";
  317. char CH8157[] PROGMEM = "11111111";
  318. //C 1623
  319. char CH16230[] PROGMEM = "11100001";
  320. char CH16231[] PROGMEM = "11011110";
  321. char CH16232[] PROGMEM = "11011111";
  322. char CH16233[] PROGMEM = "11011111";
  323. char CH16234[] PROGMEM = "11011111";
  324. char CH16235[] PROGMEM = "11011110";
  325. char CH16236[] PROGMEM = "11100001";
  326. char CH16237[] PROGMEM = "11111111";
  327. //D 2431
  328. char CH24310[] PROGMEM = "11000001";
  329. char CH24311[] PROGMEM = "11011110";
  330. char CH24312[] PROGMEM = "11011110";
  331. char CH24313[] PROGMEM = "11011110";
  332. char CH24314[] PROGMEM = "11011110";
  333. char CH24315[] PROGMEM = "11011110";
  334. char CH24316[] PROGMEM = "11000001";
  335. char CH24317[] PROGMEM = "11111111";
  336. //E 3138
  337. char CH31380[] PROGMEM = "11000000";
  338. char CH31381[] PROGMEM = "11011111";
  339. char CH31382[] PROGMEM = "11011111";
  340. char CH31383[] PROGMEM = "11000011";
  341. char CH31384[] PROGMEM = "11011111";
  342. char CH31385[] PROGMEM = "11011111";
  343. char CH31386[] PROGMEM = "11000000";
  344. char CH31387[] PROGMEM = "11111111";
  345. //F 3946
  346. char CH39460[] PROGMEM = "11000000";
  347. char CH39461[] PROGMEM = "11011111";
  348. char CH39462[] PROGMEM = "11011111";
  349. char CH39463[] PROGMEM = "11000011";
  350. char CH39464[] PROGMEM = "11011111";
  351. char CH39465[] PROGMEM = "11011111";
  352. char CH39466[] PROGMEM = "11011111";
  353. char CH39467[] PROGMEM = "11111111";
  354. //G 4754
  355. char CH47540[] PROGMEM = "11100001";
  356. char CH47541[] PROGMEM = "11011110";
  357. char CH47542[] PROGMEM = "11011111";
  358. char CH47543[] PROGMEM = "11011000";
  359. char CH47544[] PROGMEM = "11011110";
  360. char CH47545[] PROGMEM = "11011110";
  361. char CH47546[] PROGMEM = "11100000";
  362. char CH47547[] PROGMEM = "11111111";
  363. //H 5562
  364. char CH55620[] PROGMEM = "11011110";
  365. char CH55621[] PROGMEM = "11011110";
  366. char CH55622[] PROGMEM = "11011110";
  367. char CH55623[] PROGMEM = "11000000";
  368. char CH55624[] PROGMEM = "11011110";
  369. char CH55625[] PROGMEM = "11011110";
  370. char CH55626[] PROGMEM = "11011110";
  371. char CH55627[] PROGMEM = "11111111";
  372. //I 5663
  373. char CH0[] PROGMEM = "11000000";
  374. char CH1[] PROGMEM = "11110011";
  375. char CH2[] PROGMEM = "11110011";
  376. char CH3[] PROGMEM = "11110011";
  377. char CH4[] PROGMEM = "11110011";
  378. char CH5[] PROGMEM = "11110011";
  379. char CH6[] PROGMEM = "11000000";
  380. char CH7[] PROGMEM = "11111111";
  381. //J 6471
  382. char CH64710[] PROGMEM = "11000000";
  383. char CH64711[] PROGMEM = "11111110";
  384. char CH64712[] PROGMEM = "11111110";
  385. char CH64713[] PROGMEM = "11111110";
  386. char CH64714[] PROGMEM = "11011110";
  387. char CH64715[] PROGMEM = "11011110";
  388. char CH64716[] PROGMEM = "11100001";
  389. char CH64717[] PROGMEM = "11111111";
  390. //K 7279
  391. char CH72790[] PROGMEM = "11011110";
  392. char CH72791[] PROGMEM = "11011101";
  393. char CH72792[] PROGMEM = "11011011";
  394. char CH72793[] PROGMEM = "11000111";
  395. char CH72794[] PROGMEM = "11011011";
  396. char CH72795[] PROGMEM = "11011101";
  397. char CH72796[] PROGMEM = "11011110";
  398. char CH72797[] PROGMEM = "11111111";
  399. //L 8087
  400. char CH80870[] PROGMEM = "11011111";
  401. char CH80871[] PROGMEM = "11011111";
  402. char CH80872[] PROGMEM = "11011111";
  403. char CH80873[] PROGMEM = "11011111";
  404. char CH80874[] PROGMEM = "11011111";
  405. char CH80875[] PROGMEM = "11011111";
  406. char CH80876[] PROGMEM = "11000000";
  407. char CH80877[] PROGMEM = "11111111";
  408. //M 8895
  409. char CH88950[] PROGMEM = "11011110";
  410. char CH88951[] PROGMEM = "11001100";
  411. char CH88952[] PROGMEM = "11010010";
  412. char CH88953[] PROGMEM = "11011110";
  413. char CH88954[] PROGMEM = "11011110";
  414. char CH88955[] PROGMEM = "11011110";
  415. char CH88956[] PROGMEM = "11011110";
  416. char CH88957[] PROGMEM = "11111111";
  417. //N 96103
  418. char CH961030[] PROGMEM = "11011110";
  419. char CH961031[] PROGMEM = "11001110";
  420. char CH961032[] PROGMEM = "11000110";
  421. char CH961033[] PROGMEM = "11010010";
  422. char CH961034[] PROGMEM = "11011000";
  423. char CH961035[] PROGMEM = "11011100";
  424. char CH961036[] PROGMEM = "11011110";
  425. char CH961037[] PROGMEM = "11111111";
  426. //O 104111
  427. char CH1041110[] PROGMEM = "11000001";
  428. char CH1041111[] PROGMEM = "10111110";
  429. char CH1041112[] PROGMEM = "10111110";
  430. char CH1041113[] PROGMEM = "10111110";
  431. char CH1041114[] PROGMEM = "10111110";
  432. char CH1041115[] PROGMEM = "10111110";
  433. char CH1041116[] PROGMEM = "11000001";
  434. char CH1041117[] PROGMEM = "11111111";
  435. //P 112119
  436. char CH1121190[] PROGMEM = "11000001";
  437. char CH1121191[] PROGMEM = "11011110";
  438. char CH1121192[] PROGMEM = "11011110";
  439. char CH1121193[] PROGMEM = "11000001";
  440. char CH1121194[] PROGMEM = "11011111";
  441. char CH1121195[] PROGMEM = "11011111";
  442. char CH1121196[] PROGMEM = "11011111";
  443. char CH1121197[] PROGMEM = "11111111";
  444. //Q 120127
  445. char CH1201270[] PROGMEM = "11100001";
  446. char CH1201271[] PROGMEM = "11011110";
  447. char CH1201272[] PROGMEM = "11011110";
  448. char CH1201273[] PROGMEM = "11011110";
  449. char CH1201274[] PROGMEM = "11011010";
  450. char CH1201275[] PROGMEM = "11011100";
  451. char CH1201276[] PROGMEM = "11100000";
  452. char CH1201277[] PROGMEM = "11111111";
  453. //R 128135
  454. char CH1281350[] PROGMEM = "11000001";
  455. char CH1281351[] PROGMEM = "11011110";
  456. char CH1281352[] PROGMEM = "11011110";
  457. char CH1281353[] PROGMEM = "11000001";
  458. char CH1281354[] PROGMEM = "11011011";
  459. char CH1281355[] PROGMEM = "11011101";
  460. char CH1281356[] PROGMEM = "11011110";
  461. char CH1281357[] PROGMEM = "11111111";
  462. //S 136143
  463. char CH1361430[] PROGMEM = "11100001";
  464. char CH1361431[] PROGMEM = "11011110";
  465. char CH1361432[] PROGMEM = "11011111";
  466. char CH1361433[] PROGMEM = "11100001";
  467. char CH1361434[] PROGMEM = "11111110";
  468. char CH1361435[] PROGMEM = "11011110";
  469. char CH1361436[] PROGMEM = "11100001";
  470. char CH1361437[] PROGMEM = "11111111";
  471. //T 144151
  472. char CH1441510[] PROGMEM = "11000000";
  473. char CH1441511[] PROGMEM = "11110011";
  474. char CH1441512[] PROGMEM = "11110011";
  475. char CH1441513[] PROGMEM = "11110011";
  476. char CH1441514[] PROGMEM = "11110011";
  477. char CH1441515[] PROGMEM = "11110011";
  478. char CH1441516[] PROGMEM = "11110011";
  479. char CH1441517[] PROGMEM = "11111111";
  480. //U 152159
  481. char CH1521590[] PROGMEM = "11011110";
  482. char CH1521591[] PROGMEM = "11011110";
  483. char CH1521592[] PROGMEM = "11011110";
  484. char CH1521593[] PROGMEM = "11011110";
  485. char CH1521594[] PROGMEM = "11011110";
  486. char CH1521595[] PROGMEM = "11011110";
  487. char CH1521596[] PROGMEM = "11100001";
  488. char CH1521597[] PROGMEM = "11111111";
  489. //V 160167
  490. char CH1601670[] PROGMEM = "10111110";
  491. char CH1601671[] PROGMEM = "10111110";
  492. char CH1601672[] PROGMEM = "11011101";
  493. char CH1601673[] PROGMEM = "11011101";
  494. char CH1601674[] PROGMEM = "11101011";
  495. char CH1601675[] PROGMEM = "11101011";
  496. char CH1601676[] PROGMEM = "11110111";
  497. char CH1601677[] PROGMEM = "11111111";
  498. //W 168175
  499. char CH1681750[] PROGMEM = "10111110";
  500. char CH1681751[] PROGMEM = "10111110";
  501. char CH1681752[] PROGMEM = "10111110";
  502. char CH1681753[] PROGMEM = "10110110";
  503. char CH1681754[] PROGMEM = "10101010";
  504. char CH1681755[] PROGMEM = "10011100";
  505. char CH1681756[] PROGMEM = "10111110";
  506. char CH1681757[] PROGMEM = "11111111";
  507. //X 176183
  508. char CH1761830[] PROGMEM = "10111110";
  509. char CH1761831[] PROGMEM = "11011101";
  510. char CH1761832[] PROGMEM = "11101011";
  511. char CH1761833[] PROGMEM = "11110111";
  512. char CH1761834[] PROGMEM = "11101011";
  513. char CH1761835[] PROGMEM = "11011101";
  514. char CH1761836[] PROGMEM = "10111110";
  515. char CH1761837[] PROGMEM = "11111111";
  516. //Y 184191
  517. char CH1841910[] PROGMEM = "10111110";
  518. char CH1841911[] PROGMEM = "11011101";
  519. char CH1841912[] PROGMEM = "11101011";
  520. char CH1841913[] PROGMEM = "11110111";
  521. char CH1841914[] PROGMEM = "11110111";
  522. char CH1841915[] PROGMEM = "11110111";
  523. char CH1841916[] PROGMEM = "11110111";
  524. char CH1841917[] PROGMEM = "11111111";
  525. //Z 192199
  526. char CH1921990[] PROGMEM = "10000000";
  527. char CH1921991[] PROGMEM = "11111101";
  528. char CH1921992[] PROGMEM = "11111011";
  529. char CH1921993[] PROGMEM = "11110111";
  530. char CH1921994[] PROGMEM = "11101111";
  531. char CH1921995[] PROGMEM = "11011111";
  532. char CH1921996[] PROGMEM = "10000000";
  533. char CH1921997[] PROGMEM = "11111111";
  534.  
  535.  
  536. char chl[ ] = {' ','!','q','#','$','%','&','\'','(',')','*','+',',','-', '.','/',
  537.               '0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@',
  538.               'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  539.  
  540. PGM_P CHL[] PROGMEM= {
  541. CH200,CH201,CH202,CH203,CH204,CH205,CH206,CH207,
  542. CH210,CH211,CH212,CH213,CH214,CH215,CH216,CH217,
  543. CH220,CH221,CH222,CH223,CH224,CH225,CH226,CH227,
  544. CH230,CH231,CH232,CH233,CH234,CH235,CH236,CH237,
  545. CH240,CH241,CH242,CH243,CH244,CH245,CH246,CH247,
  546. CH250,CH251,CH252,CH253,CH254,CH255,CH256,CH257,
  547. CH260,CH261,CH262,CH263,CH264,CH265,CH266,CH267,
  548. CH270,CH271,CH272,CH273,CH274,CH275,CH276,CH277,
  549. CH280,CH281,CH282,CH283,CH284,CH285,CH286,CH287,
  550. CH290,CH291,CH292,CH293,CH294,CH295,CH296,CH297,
  551. CH2A0,CH2A1,CH2A2,CH2A3,CH2A4,CH2A5,CH2A6,CH2A7,
  552. CH2B0,CH2B1,CH2B2,CH2B3,CH2B4,CH2B5,CH2B6,CH2B7,
  553. CH2C0,CH2C1,CH2C2,CH2C3,CH2C4,CH2C5,CH2C6,CH2C7,
  554. CH2D0,CH2D1,CH2D2,CH2D3,CH2D4,CH2D5,CH2D6,CH2D7,
  555. CH2E0,CH2E1,CH2E2,CH2E3,CH2E4,CH2E5,CH2E6,CH2E7,
  556. CH2F0,CH2F1,CH2F2,CH2F3,CH2F4,CH2F5,CH2F6,CH2F7,
  557. CH300,CH301,CH302,CH303,CH304,CH305,CH306,CH307,
  558. CH310,CH311,CH312,CH313,CH314,CH315,CH316,CH317,
  559. CH320,CH321,CH322,CH323,CH324,CH325,CH326,CH327,
  560. CH330,CH331,CH332,CH333,CH334,CH335,CH336,CH337,
  561. CH340,CH341,CH342,CH343,CH344,CH345,CH346,CH347,
  562. CH350,CH351,CH352,CH353,CH354,CH355,CH356,CH357,
  563. CH360,CH361,CH362,CH363,CH364,CH365,CH366,CH367,
  564. CH370,CH371,CH372,CH373,CH374,CH375,CH376,CH377,
  565. CH380,CH381,CH382,CH383,CH384,CH385,CH386,CH387,
  566. CH390,CH391,CH392,CH393,CH394,CH395,CH396,CH397,
  567. CH3A0,CH3A1,CH3A2,CH3A3,CH3A4,CH3A5,CH3A6,CH3A7,
  568. CH3B0,CH3B1,CH3B2,CH3B3,CH3B4,CH3B5,CH3B6,CH3B7,
  569. CH3C0,CH3C1,CH3C2,CH3C3,CH3C4,CH3C5,CH3C6,CH3C7,
  570. CH3D0,CH3D1,CH3D2,CH3D3,CH3D4,CH3D5,CH3D6,CH3D7,
  571. CH3E0,CH3E1,CH3E2,CH3E3,CH3E4,CH3E5,CH3E6,CH3E7,
  572. CH3F0,CH3F1,CH3F2,CH3F3,CH3F4,CH3F5,CH3F6,CH3F7,
  573. CH400,CH401,CH402,CH403,CH404,CH405,CH406,CH407,
  574. CH070,CH071,CH072,CH073,CH074,CH075,CH076,CH077,
  575. CH8150,CH8151,CH8152,CH8153,CH8154,CH8155,CH8156,CH8157,
  576. CH16230,CH16231,CH16232,CH16233,CH16234,CH16235,CH16236,CH16237,
  577. CH24310,CH24311,CH24312,CH24313,CH24314,CH24315,CH24316,CH24317,
  578. CH31380,CH31381,CH31382,CH31383,CH31384,CH31385,CH31386,CH31387,
  579. CH39460,CH39461,CH39462,CH39463,CH39464,CH39465,CH39466,CH39467,
  580. CH47540,CH47541,CH47542,CH47543,CH47544,CH47545,CH47546,CH47547,
  581. CH55620,CH55621,CH55622,CH55623,CH55624,CH55625,CH55626,CH55627,
  582. CH0,CH1,CH2,CH3,CH4,CH5,CH6,CH7,
  583. CH64710,CH64711,CH64712,CH64713,CH64714,CH64715,CH64716,CH64717,
  584. CH72790,CH72791,CH72792,CH72793,CH72794,CH72795,CH72796,CH72797,
  585. CH80870,CH80871,CH80872,CH80873,CH80874,CH80875,CH80876,CH80877,
  586. CH88950,CH88951,CH88952,CH88953,CH88954,CH88955,CH88956,CH88957,
  587. CH961030,CH961031,CH961032,CH961033,CH961034,CH961035,CH961036,CH961037,
  588. CH1041110,CH1041111,CH1041112,CH1041113,CH1041114,CH1041115,CH1041116,CH1041117,
  589. CH1121190,CH1121191,CH1121192,CH1121193,CH1121194,CH1121195,CH1121196,CH1121197,
  590. CH1201270,CH1201271,CH1201272,CH1201273,CH1201274,CH1201275,CH1201276,CH1201277,
  591. CH1281350,CH1281351,CH1281352,CH1281353,CH1281354,CH1281355,CH1281356,CH1281357,
  592. CH1361430,CH1361431,CH1361432,CH1361433,CH1361434,CH1361435,CH1361436,CH1361437,
  593. CH1441510,CH1441511,CH1441512,CH1441513,CH1441514,CH1441515,CH1441516,CH1441517,
  594. CH1521590,CH1521591,CH1521592,CH1521593,CH1521594,CH1521595,CH1521596,CH1521597,
  595. CH1601670,CH1601671,CH1601672,CH1601673,CH1601674,CH1601675,CH1601676,CH1601677,
  596. CH1681750,CH1681751,CH1681752,CH1681753,CH1681754,CH1681755,CH1681756,CH1681757,
  597. CH1761830,CH1761831,CH1761832,CH1761833,CH1761834,CH1761835,CH1761836,CH1761837,
  598. CH1841910,CH1841911,CH1841912,CH1841913,CH1841914,CH1841915,CH1841916,CH1841917,
  599. CH1921990,CH1921991,CH1921992,CH1921993,CH1921994,CH1921995,CH1921996,CH1921997};
  600.  
  601. //END letter def

trunetclock.cpp

  1. #include <Wire.h>
  2. #include <avr/pgmspace.h>
  3.  
  4. #include "ht1632c.h"
  5. #include "font1.h"
  6.  
  7. #define DS1307_I2C_ADDRESS 0x68
  8.  
  9. // Dual 3216 LED Matrix
  10. // If you have only one set these to:
  11. // X_MAX=31
  12. // Y_MAX=15
  13. // CHIP_MAX=4
  14. #define X_MAX 63 // 0 based X
  15. #define Y_MAX 15 // 0 based Y
  16. #define CHIP_MAX 4*2 // Number of HT1632C Chips
  17.                      // 4 each board * 2 boards
  18.  
  19. // possible values for a pixel;
  20. #define BLACK  0
  21. #define GREEN  1
  22. #define RED    2
  23. #define ORANGE 3
  24.  
  25. #define ASSERT(condition) //nothing
  26.  
  27. /*
  28.  * Set these constants to the values of the pins connected to the SureElectronics Module
  29.  */
  30. static const byte ht1632_data = 53;  // Data pin (pin 7)
  31. static const byte ht1632_clk = 52;  // Data pin (pin 2)
  32. static const byte ht1632_wrclk = 51; // Write clock pin (pin 5)
  33. static const byte ht1632_cs = 50;    // Chip Select (pin 1)
  34. // The should also be a common GND (pins .
  35. // The module with all LEDs like draws about 200mA,
  36. //  which makes it PROBABLY powerable via Arduino +5V
  37.  
  38. /*
  39.  * we keep a copy of the display controller contents so that we can
  40.  * know which bits are on without having to (slowly) read the device.
  41.  * Note that we only use the low four bits of the shadow ram, since
  42.  * we're shadowing 4-bit memory.  This makes things faster, but we
  43.  * COULD do something with the other half of our bytes !
  44.  */
  45. byte ht1632_shadowram[64][CHIP_MAX] = {0};
  46. /*
  47.  * we use buffer to put the char fonts
  48.  */
  49. char buffer[8][8];
  50.  
  51. //**************************************************************************************************
  52. //Function Name: decToBcd
  53. //Function Feature: Convert normal decimal numbers to binary coded decimal
  54. //Input Argument: void
  55. //Output Argument: void
  56. //**************************************************************************************************
  57. byte decToBcd(byte val)
  58. {
  59.   return ( (val/10*16) + (val%10) );
  60. }
  61.  
  62. //**************************************************************************************************
  63. //Function Name: bcdToDec
  64. //Function Feature: Convert binary coded decimal to normal decimal numbers
  65. //Input Argument: void
  66. //Output Argument: void
  67. //**************************************************************************************************
  68. byte bcdToDec(byte val)
  69. {
  70.   return ( (val/16*10) + (val%16) );
  71. }
  72.  
  73. //**************************************************************************************************
  74. //Function Name: setDateDs1307
  75. //Function Feature: set date/time to DS1307 IC
  76. //Input Argument: void
  77. //Output Argument: void
  78. //**************************************************************************************************
  79. void setDateDs1307(byte second,        // 0-59
  80.                    byte minute,        // 0-59
  81.                    byte hour,          // 1-23
  82.                    byte dayOfWeek,     // 1-7
  83.                    byte dayOfMonth,    // 1-28/29/30/31
  84.                    byte month,         // 1-12
  85.                    byte year)          // 0-99
  86. {
  87.    Wire.beginTransmission(DS1307_I2C_ADDRESS);
  88.    Wire.send(0);
  89.    Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock
  90.    Wire.send(decToBcd(minute));
  91.    Wire.send(decToBcd(hour));      // If you want 12 hour am/pm you need to set
  92.                                    // bit 6 (also need to change readDateDs1307)
  93.    Wire.send(decToBcd(dayOfWeek));
  94.    Wire.send(decToBcd(dayOfMonth));
  95.    Wire.send(decToBcd(month));
  96.    Wire.send(decToBcd(year));
  97.    Wire.endTransmission();
  98. }
  99.  
  100. //**************************************************************************************************
  101. //Function Name: getDateDs1307
  102. //Function Feature: get date/time from DS1307 IC
  103. //Input Argument: void
  104. //Output Argument: void
  105. //**************************************************************************************************
  106. void getDateDs1307(byte *second,
  107.           byte *minute,
  108.           byte *hour,
  109.           byte *dayOfWeek,
  110.           byte *dayOfMonth,
  111.           byte *month,
  112.           byte *year)
  113. {
  114.   // Reset the register pointer
  115.   Wire.beginTransmission(DS1307_I2C_ADDRESS);
  116.   Wire.send(0);
  117.   Wire.endTransmission();
  118.  
  119.   Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
  120.  
  121.   // A few of these need masks because certain bits are control bits
  122.   *second     = bcdToDec(Wire.receive() & 0x7f);
  123.   *minute     = bcdToDec(Wire.receive());
  124.   *hour       = bcdToDec(Wire.receive() & 0x3f);  // Need to change this if 12 hour am/pm
  125.   *dayOfWeek  = bcdToDec(Wire.receive());
  126.   *dayOfMonth = bcdToDec(Wire.receive());
  127.   *month      = bcdToDec(Wire.receive());
  128.   *year       = bcdToDec(Wire.receive());
  129. }
  130.  
  131. //**************************************************************************************************
  132. //Function Name: ds1307_initialize
  133. //Function Feature: initialize DS1307 IC
  134. //Input Argument: void
  135. //Output Argument: void
  136. //**************************************************************************************************
  137. void ds1307_initialize()
  138. {
  139.   Wire.begin();
  140.   Serial.begin(9600);
  141. }
  142.  
  143. //**************************************************************************************************
  144. //Function Name: OutputCLK_Pulse
  145. //Function Feature: enable CLK_74164 pin to output a clock pulse
  146. //Input Argument: void
  147. //Output Argument: void
  148. //**************************************************************************************************
  149. void OutputCLK_Pulse(void)      //Output a clock pulse
  150. {
  151.   digitalWrite(ht1632_clk, HIGH);
  152.   digitalWrite(ht1632_clk, LOW);
  153. }
  154.  
  155. //**************************************************************************************************
  156. //Function Name: ht1632_chipselect
  157. //Function Feature: enable HT1632C
  158. //Input Argument: select: HT1632C to be selected
  159. //      If select=0, select none.
  160. //      If s<0, select all.
  161. //Output Argument: void
  162. //**************************************************************************************************
  163. void ht1632_chipselect(int select)
  164. {
  165.   unsigned char tmp = 0;
  166.   if (select < 0) { // Enable all HT1632C
  167.     digitalWrite(ht1632_cs, LOW);
  168.     for (tmp=0; tmp<CHIP_MAX; tmp++) {
  169.       OutputCLK_Pulse();
  170.     }
  171.   } else if(select==0) { //Disable all HT1632Cs
  172.     digitalWrite(ht1632_cs, HIGH);
  173.     for(tmp=0; tmp<CHIP_MAX; tmp++) {
  174.       OutputCLK_Pulse();
  175.     }
  176.   } else {
  177.     digitalWrite(ht1632_cs, HIGH);
  178.     for(tmp=0; tmp<CHIP_MAX; tmp++) {
  179.       OutputCLK_Pulse();
  180.     }
  181.     digitalWrite(ht1632_cs, LOW);
  182.     OutputCLK_Pulse();
  183.     digitalWrite(ht1632_cs, HIGH);
  184.     tmp = 1;
  185.     for( ; tmp<select; tmp++) {
  186.       OutputCLK_Pulse();
  187.     }
  188.   }
  189. }
  190.  
  191. //**************************************************************************************************
  192. //Function Name: ht1632_writebits
  193. //Function Feature: Write bits (up to 8) to h1632 on pins ht1632_data, ht1632_wrclk
  194. //                  Chip is assumed to already be chip-selected
  195. //                  Bits are shifted out from MSB to LSB, with the first bit sent
  196. //                  being (bits & firstbit), shifted till firsbit is zero.
  197. //Input Argument: bits: bits to send
  198. //            firstbit: the first bit to send
  199. //Output Argument: void
  200. //**************************************************************************************************
  201. void ht1632_writebits (byte bits, byte firstbit)
  202. {
  203.   DEBUGPRINT(" ");
  204.   while (firstbit) {
  205.     DEBUGPRINT((bits&firstbit ? "1" : "0"));
  206.     digitalWrite(ht1632_wrclk, LOW);
  207.     if (bits & firstbit) {
  208.         digitalWrite(ht1632_data, HIGH);
  209.     }
  210.     else {
  211.         digitalWrite(ht1632_data, LOW);
  212.     }
  213.     digitalWrite(ht1632_wrclk, HIGH);
  214.     firstbit >>= 1;
  215.   }
  216. }
  217.  
  218. //**************************************************************************************************
  219. //Function Name: ht1632_sendcmd
  220. //Function Feature: Send a command to the ht1632 chip.
  221. //                  Select 1 0 0 c7 c6 c5 c4 c3 c2 c1 c0 xx Free
  222. //Input Argument: chipNo: the chip you want to send data
  223. //               command: consists of a 3-bit "CMD" ID, an 8bit command, and
  224. //                        one "don't care bit".
  225. //Output Argument: void
  226. //**************************************************************************************************
  227. static void ht1632_sendcmd (byte chipNo, byte command)
  228. {
  229.   ht1632_chipselect(chipNo);
  230.   ht1632_writebits(HT1632_ID_CMD, 1<<2);  // send 3 bits of id: COMMMAND
  231.   ht1632_writebits(command, 1<<7);  // send the actual command
  232.   ht1632_writebits(0, 1);       /* one extra dont-care bit in commands. */
  233.   ht1632_chipselect(0);
  234. }
  235.  
  236. //**************************************************************************************************
  237. //Function Name: ht1632_senddata
  238. //Function Feature: send a nibble (4 bits) of data to a particular memory location of the
  239. //                  ht1632.  The command has 3 bit ID, 7 bits of address, and 4 bits of data.
  240. //                  Select 1 0 1 A6 A5 A4 A3 A2 A1 A0 D0 D1 D2 D3 Free
  241. //                  Note that the address is sent MSB first, while the data is sent LSB first!
  242. //                  This means that somewhere a bit reversal will have to be done to get
  243. //                  zero-based addressing of words and dots within words.
  244. //Input Argument: chipNo: the chip you want to send data
  245. //               address: chip address to write
  246. //                  data: data to write to chip memory
  247. //Output Argument: void
  248. //**************************************************************************************************
  249. static void ht1632_senddata (byte chipNo, byte address, byte data)
  250. {
  251.   ht1632_chipselect(chipNo);
  252.   ht1632_writebits(HT1632_ID_WR, 1<<2);  // send ID: WRITE to RAM
  253.   ht1632_writebits(address, 1<<6); // Send address
  254.   ht1632_writebits(data, 1<<3); // send 4 bits of data
  255.   ht1632_chipselect(0);
  256. }
  257.  
  258. //**************************************************************************************************
  259. //Function Name: ht1632_clear
  260. //Function Feature: clear display
  261. //Input Argument: void
  262. //Output Argument: void
  263. //**************************************************************************************************
  264. void ht1632_clear()
  265. {
  266.   char i;
  267.  
  268.   for (int j=1;j<=CHIP_MAX;j++) {
  269.     ht1632_chipselect(j);
  270.     ht1632_writebits(HT1632_ID_WR, 1<<2);  // send ID: WRITE to RAM
  271.     ht1632_writebits(0, 1<<6); // Send address
  272.     for (i=0; i<64/2; i++) // Clear entire display
  273.       ht1632_writebits(0, 1<<7); // send 8 bits of data
  274.     ht1632_chipselect(0);
  275.     for (i=0; i<64; i++)
  276.       ht1632_shadowram[i][j-1] = 0;
  277.   }
  278. }
  279.  
  280. //**************************************************************************************************
  281. //Function Name: xyToIndex
  282. //Function Feature: get the value of x,y
  283. //Input Argument: x: X coordinate
  284. //                y: Y coordinate
  285. //Output Argument: address of xy
  286. //**************************************************************************************************
  287. byte xyToIndex(byte x, byte y)
  288. {
  289.   byte nChip, addr;
  290.  
  291.   if (x>=32) {
  292.     nChip = 3 + x/16 + (y>7?2:0);
  293.   } else {
  294.     nChip = 1 + x/16 + (y>7?2:0);
  295.   }
  296.  
  297.   x = x % 16;
  298.   y = y % 8;
  299.   addr = (x<<1) + (y>>2);
  300.  
  301.   return addr;
  302. }
  303.  
  304. //**************************************************************************************************
  305. //Function Name: calcBit
  306. //Function Feature: calculate the bitval of y
  307. //Input Argument: y: Y coordinate
  308. //Output Argument: bitval
  309. //**************************************************************************************************
  310. #define calcBit(y) (8>>(y&3))
  311.  
  312. //**************************************************************************************************
  313. //Function Name: get_pixel
  314. //Function Feature: get the value of x,y
  315. //Input Argument: x: X coordinate
  316. //                y: Y coordinate
  317. //Output Argument: color setted on x,y coordinates
  318. //**************************************************************************************************
  319. int get_pixel(byte x, byte y) {
  320.   byte addr, bitval, nChip;
  321.  
  322.   if (x>=32) {
  323.     nChip = 3 + x/16 + (y>7?2:0);
  324.   } else {
  325.     nChip = 1 + x/16 + (y>7?2:0);
  326.   }
  327.  
  328.   addr = xyToIndex(x,y);
  329.   bitval = calcBit(y);
  330.  
  331.   if ((ht1632_shadowram[addr][nChip-1] & bitval) && (ht1632_shadowram[addr+32][nChip-1] & bitval)) {
  332.     return ORANGE;
  333.   } else if (ht1632_shadowram[addr][nChip-1] & bitval) {
  334.     return GREEN;
  335.   } else if (ht1632_shadowram[addr+32][nChip-1] & bitval) {
  336.     return RED;
  337.   } else {
  338.     return 0;
  339.   }
  340. }
  341.  
  342. //**************************************************************************************************
  343. //Function Name: ht1632_plot
  344. //Function Feature: plot a dot on x,y
  345. //Input Argument: x: X coordinate
  346. //                y: Y coordinate
  347. //            color: BLACK(clean), GREEN, RED, ORANGE
  348. //Output Argument: void
  349. //**************************************************************************************************
  350. void ht1632_plot (byte x, byte y, byte color)
  351. {
  352.   byte nChip, addr, bitval;
  353.  
  354.   if (x<0 || x>X_MAX || y<0 || y>Y_MAX)
  355.     return;
  356.  
  357.   if (color != BLACK && color != GREEN && color != RED && color != ORANGE)
  358.     return;
  359.  
  360.   if (x>=32) {
  361.     nChip = 3 + x/16 + (y>7?2:0);
  362.   } else {
  363.     nChip = 1 + x/16 + (y>7?2:0);
  364.   }
  365.  
  366.   addr = xyToIndex(x,y);
  367.   bitval = calcBit(y);
  368.  
  369.   switch (color)
  370.   {
  371.     case BLACK:
  372.       if (get_pixel(x,y) != BLACK) { // compare with memory to only set if pixel is other color
  373.         // clear the bit in both planes;
  374.         ht1632_shadowram[addr][nChip-1] &= ~bitval;
  375.         ht1632_senddata(nChip, addr, ht1632_shadowram[addr][nChip-1]);
  376.         addr = addr + 32;
  377.         ht1632_shadowram[addr][nChip-1] &= ~bitval;
  378.         ht1632_senddata(nChip, addr, ht1632_shadowram[addr][nChip-1]);
  379.       }
  380.       break;
  381.     case GREEN:
  382.       if (get_pixel(x,y) != GREEN) { // compare with memory to only set if pixel is other color
  383.         // set the bit in the green plane and clear the bit in the red plane;
  384.         ht1632_shadowram[addr][nChip-1] |= bitval;
  385.         ht1632_senddata(nChip, addr, ht1632_shadowram[addr][nChip-1]);
  386.         addr = addr + 32;
  387.         ht1632_shadowram[addr][nChip-1] &= ~bitval;
  388.         ht1632_senddata(nChip, addr, ht1632_shadowram[addr][nChip-1]);
  389.       }
  390.       break;
  391.     case RED:
  392.       if (get_pixel(x,y) != RED) { // compare with memory to only set if pixel is other color
  393.         // clear the bit in green plane and set the bit in the red plane;
  394.         ht1632_shadowram[addr][nChip-1] &= ~bitval;
  395.         ht1632_senddata(nChip, addr, ht1632_shadowram[addr][nChip-1]);
  396.         addr = addr + 32;
  397.         ht1632_shadowram[addr][nChip-1] |= bitval;
  398.         ht1632_senddata(nChip, addr, ht1632_shadowram[addr][nChip-1]);
  399.       }
  400.       break;
  401.     case ORANGE:
  402.       if (get_pixel(x,y) != ORANGE) { // compare with memory to only set if pixel is other color
  403.         // set the bit in both the green and red planes;
  404.         ht1632_shadowram[addr][nChip-1] |= bitval;
  405.         ht1632_senddata(nChip, addr, ht1632_shadowram[addr][nChip-1]);
  406.         addr = addr + 32;
  407.         ht1632_shadowram[addr][nChip-1] |= bitval;
  408.         ht1632_senddata(nChip, addr, ht1632_shadowram[addr][nChip-1]);
  409.       }
  410.       break;
  411.   }
  412. }
  413.  
  414. //**************************************************************************************************
  415. //Function Name: set_buffer
  416. //Function Feature: set buffer variable to char
  417. //Input Argument: chr: char to set on buffer
  418. //Output Argument: void
  419. //**************************************************************************************************
  420. void set_buffer(char chr){
  421.   for(int i=0; i<sizeof(chl); i++){
  422.     if(chl[i] == chr){
  423.       int pos = i*8;
  424.       for(int j=0;j<8;j++){
  425.         memcpy_P(buffer[j], (PGM_P)pgm_read_word(&(CHL[j+pos])), 8);
  426.       }
  427.     }
  428.   }
  429. }
  430.  
  431. //**************************************************************************************************
  432. //Function Name: null_buffer
  433. //Function Feature: null entire buffer
  434. //Input Argument: void
  435. //Output Argument: void
  436. //**************************************************************************************************
  437. void null_buffer(){
  438.   for(int i=0;i<8;i++)
  439.     for(int j=0; j<8;j++)
  440.       buffer[i][j] = 0;
  441. }
  442.  
  443. //**************************************************************************************************
  444. //Function Name: ht1632_initialize
  445. //Function Feature: initialize the display
  446. //Input Argument: void
  447. //Output Argument: void
  448. //**************************************************************************************************
  449. static void ht1632_initialize()
  450. {
  451.   pinMode(ht1632_cs, OUTPUT);
  452.   digitalWrite(ht1632_cs, HIGH);
  453.   pinMode(ht1632_wrclk, OUTPUT);
  454.   pinMode(ht1632_data, OUTPUT);
  455.   pinMode(ht1632_clk, OUTPUT);
  456.   for (int i=1; i<=CHIP_MAX; i++) {
  457.     ht1632_sendcmd(i, HT1632_CMD_SYSDIS); // Disable system
  458.     ht1632_sendcmd(i, HT1632_CMD_COMS00); // 16*32, PMOS drivers
  459.     ht1632_sendcmd(i, HT1632_CMD_MSTMD);  // MASTER MODE
  460.     ht1632_sendcmd(i, HT1632_CMD_SYSON);  // System on
  461.     ht1632_sendcmd(i, HT1632_CMD_LEDON);  // LEDs on
  462.   }
  463.   ht1632_clear(); // Clear the display
  464. }
  465.  
  466. void setup()
  467. {
  468.   ht1632_initialize();
  469.   ds1307_initialize();
  470.  
  471.   // Change these values to what you want to set your clock to.
  472.   // You probably only want to set your clock once and then
  473.   // remove/comment the setDateDs1307 call.
  474.   /*
  475.   byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  476.   second = 30;
  477.   minute = 11;
  478.   hour = 14;
  479.   dayOfWeek = 2;
  480.   dayOfMonth = 21;
  481.   month = 12;
  482.   year = 10;
  483.   setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
  484.   */
  485. }
  486.  
  487. void loop ()
  488. {
  489.   byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  490.   getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  491.  
  492.   char STRING1[ ]="        ";
  493.   char STRING2[ ]="        ";
  494.   sprintf(STRING1, "%02d/%02d/%02d", dayOfMonth, month, year);
  495.   sprintf(STRING2, "%02d:%02d:%02d", hour, minute, second);
  496.  
  497.   int x,i,j;
  498.   for(x=1;x<sizeof(STRING1);x++) {
  499.     null_buffer();
  500.     for(i=0;i<8;i++){
  501.       for(j=0;j<8;j++){
  502.         set_buffer(STRING1[x-1]);
  503.         if (buffer[i][j] & (1<<0)) {
  504.           ht1632_plot(j+(8*(x-1)),i,BLACK);
  505.         } else {
  506.           ht1632_plot(j+(8*(x-1)),i,RED);
  507.         }
  508.       }
  509.     }
  510.   }
  511.   for(x=1;x<sizeof(STRING2);x++) {
  512.     null_buffer();
  513.     for(i=0;i<8;i++){
  514.       for(j=0;j<8;j++){
  515.         set_buffer(STRING2[x-1]);
  516.         if (buffer[i][j] & (1<<0)) {
  517.           ht1632_plot(j+(8*(x-1)),i+8,BLACK);
  518.         } else {
  519.           ht1632_plot(j+(8*(x-1)),i+8,GREEN);
  520.         }
  521.       }
  522.     }
  523.   }
  524.   delay(200);
  525. }

Share