You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

349 lines
11 KiB

5 years ago
  1. /* --COPYRIGHT--,BSD
  2. * Copyright (c) 2013, Texas Instruments Incorporated
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of Texas Instruments Incorporated nor the names of
  17. * its contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. * --/COPYRIGHT--*/
  32. #include "msp430g2553.h"
  33. #include "grlib.h"
  34. #include "Sharp96x96.h"
  35. #include "HAL_MSP-EXP430G2_Sharp96x96.h"
  36. // Function Prototypes
  37. void clockInit(void);
  38. void boardInit(void);
  39. void timerInit(void);
  40. void flashInit(void);
  41. void timerInit(void);
  42. void Delay_long(void);
  43. void Delay_short(void);
  44. // Global variables
  45. tContext g_sContext;
  46. tRectangle g_sRect;
  47. const tRectangle myRectangle1 = { 5, 15, 65, 45};
  48. const tRectangle myRectangle2 = { 10, 40, 90, 90};
  49. const tRectangle myRectangleOption1 = { 5, 15, 11, 21};
  50. const tRectangle myRectangleOption2 = { 5, 25, 11, 31};
  51. const tRectangle myRectangleOption3 = { 5, 35, 11, 41};
  52. const tRectangle myRectangleOption4 = { 5, 45, 11, 51};
  53. const tRectangle myRectangleOption5 = { 5, 55, 11, 61};
  54. const tRectangle myRectangleFrame = { 10, 40, 90, 60};
  55. tRectangle myRectangleProgress = { 10, 40, 30, 60};
  56. void main(void)
  57. {
  58. // Stop WDT
  59. WDTCTL = WDTPW + WDTHOLD;
  60. // Initialize the boards
  61. boardInit();
  62. clockInit();
  63. timerInit();
  64. flashInit();
  65. __bis_SR_register(GIE);
  66. // Set up the LCD
  67. LCDInit();
  68. GrContextInit(&g_sContext, &g_sharp96x96LCD);
  69. GrContextForegroundSet(&g_sContext, ClrBlack);
  70. GrContextBackgroundSet(&g_sContext, ClrWhite);
  71. GrContextFontSet(&g_sContext, &g_sFontFixed6x8);
  72. GrClearDisplay(&g_sContext);
  73. GrFlush(&g_sContext);
  74. // Intro Screen
  75. GrStringDrawCentered(&g_sContext,
  76. "How to use",
  77. AUTO_STRING_LENGTH,
  78. 48,
  79. 15,
  80. TRANSPARENT_TEXT);
  81. GrStringDrawCentered(&g_sContext,
  82. "the MSP430",
  83. AUTO_STRING_LENGTH,
  84. 48,
  85. 35,
  86. TRANSPARENT_TEXT);
  87. GrStringDraw(&g_sContext,
  88. "Graphics Library",
  89. AUTO_STRING_LENGTH,
  90. 1,
  91. 51,
  92. TRANSPARENT_TEXT);
  93. GrStringDrawCentered(&g_sContext,
  94. "Primitives",
  95. AUTO_STRING_LENGTH,
  96. 48,
  97. 75,
  98. TRANSPARENT_TEXT);
  99. GrFlush(&g_sContext);
  100. Delay_long();
  101. GrClearDisplay(&g_sContext);
  102. // Draw pixels and lines on the display
  103. GrStringDrawCentered(&g_sContext,
  104. "Draw Pixels",
  105. AUTO_STRING_LENGTH,
  106. 48,
  107. 5,
  108. TRANSPARENT_TEXT);
  109. GrStringDrawCentered(&g_sContext,
  110. "& Lines",
  111. AUTO_STRING_LENGTH,
  112. 48,
  113. 15,
  114. TRANSPARENT_TEXT);
  115. GrPixelDraw(&g_sContext, 30, 30);
  116. GrPixelDraw(&g_sContext, 30, 32);
  117. GrPixelDraw(&g_sContext, 32, 32);
  118. GrPixelDraw(&g_sContext, 32, 30);
  119. GrLineDraw(&g_sContext, 35, 35, 90, 90);
  120. GrLineDraw(&g_sContext, 5, 80, 80, 20);
  121. GrLineDraw(&g_sContext,
  122. 0,
  123. GrContextDpyHeightGet(&g_sContext) - 1,
  124. GrContextDpyWidthGet(&g_sContext) - 1,
  125. GrContextDpyHeightGet(&g_sContext) - 1);
  126. GrFlush(&g_sContext);
  127. Delay_long();
  128. GrClearDisplay(&g_sContext);
  129. // Draw circles on the display
  130. GrStringDraw(&g_sContext,
  131. "Draw Circles",
  132. AUTO_STRING_LENGTH,
  133. 10,
  134. 5,
  135. TRANSPARENT_TEXT);
  136. GrCircleDraw(&g_sContext, 30, 70, 20);
  137. GrCircleFill(&g_sContext, 60, 50, 30);
  138. GrFlush(&g_sContext);
  139. Delay_long();
  140. GrClearDisplay(&g_sContext);
  141. // Draw rectangles on the display
  142. GrStringDrawCentered(&g_sContext,
  143. "Draw Rectangles",
  144. AUTO_STRING_LENGTH,
  145. 48,
  146. 5,
  147. TRANSPARENT_TEXT);
  148. GrRectDraw(&g_sContext, &myRectangle1);
  149. GrRectFill(&g_sContext, &myRectangle2);
  150. GrFlush(&g_sContext);
  151. Delay_long();
  152. GrClearDisplay(&g_sContext);
  153. // Combining Primitive screen
  154. GrStringDrawCentered(&g_sContext,
  155. "Combining",
  156. AUTO_STRING_LENGTH,
  157. 48,
  158. 15,
  159. TRANSPARENT_TEXT);
  160. GrStringDrawCentered(&g_sContext,
  161. "Primitives to",
  162. AUTO_STRING_LENGTH,
  163. 48,
  164. 35,
  165. TRANSPARENT_TEXT);
  166. GrStringDrawCentered(&g_sContext,
  167. "create menus",
  168. AUTO_STRING_LENGTH,
  169. 48,
  170. 51,
  171. TRANSPARENT_TEXT);
  172. GrStringDrawCentered(&g_sContext,
  173. "and animations",
  174. AUTO_STRING_LENGTH,
  175. 48,
  176. 75,
  177. TRANSPARENT_TEXT);
  178. GrFlush(&g_sContext);
  179. Delay_long();
  180. GrClearDisplay(&g_sContext);
  181. // Draw a Menu screen
  182. GrStringDrawCentered(&g_sContext,
  183. "Create a Menu",
  184. AUTO_STRING_LENGTH,
  185. 48,
  186. 5,
  187. TRANSPARENT_TEXT);
  188. GrRectDraw(&g_sContext, &myRectangleOption1);
  189. GrStringDraw(&g_sContext,"Option #1", 10,15,15,TRANSPARENT_TEXT);
  190. GrRectFill(&g_sContext, &myRectangleOption2);
  191. GrStringDraw(&g_sContext,"Option #2", 10,15,25,TRANSPARENT_TEXT);
  192. GrRectDraw(&g_sContext, &myRectangleOption3);
  193. GrStringDraw(&g_sContext,"Option #3", 10,15,35,TRANSPARENT_TEXT);
  194. GrRectDraw(&g_sContext, &myRectangleOption4);
  195. GrStringDraw(&g_sContext,"Option #4", 10,15,45,TRANSPARENT_TEXT);
  196. GrRectDraw(&g_sContext, &myRectangleOption5);
  197. GrStringDraw(&g_sContext,"Option #5", 10,15,55,TRANSPARENT_TEXT);
  198. GrFlush(&g_sContext);
  199. Delay_long();
  200. GrClearDisplay(&g_sContext);
  201. // Show progress bar screen
  202. // The following animation consist on displaying a progress bar and
  203. // updating the progress bar in increments of 25%.
  204. GrStringDrawCentered(&g_sContext,
  205. "Show progress",
  206. AUTO_STRING_LENGTH,
  207. 48,
  208. 5,
  209. TRANSPARENT_TEXT);
  210. GrRectDraw(&g_sContext, &myRectangleFrame);
  211. GrStringDrawCentered(&g_sContext,
  212. "Processing...",
  213. AUTO_STRING_LENGTH,
  214. 48,
  215. 75,
  216. TRANSPARENT_TEXT);
  217. GrFlush(&g_sContext);
  218. Delay_short();
  219. // Update display with 25 %. Initial value of "myRectangleProgress" are set
  220. // to update bar with a 25 % increment.
  221. GrRectFill(&g_sContext, &myRectangleProgress);
  222. GrFlush(&g_sContext);
  223. Delay_short();
  224. // Set myRectangleProgress values to update progress bar with 50 %
  225. myRectangleProgress.sXMin = 30;
  226. myRectangleProgress.sYMin = 40;
  227. myRectangleProgress.sXMax = 50;
  228. myRectangleProgress.sYMax = 60;
  229. GrRectFill(&g_sContext, &myRectangleProgress);
  230. GrFlush(&g_sContext);
  231. Delay_short();
  232. // Set myRectangleProgress values to update progress bar with 75 %
  233. myRectangleProgress.sXMin = 50;
  234. myRectangleProgress.sYMin = 40;
  235. myRectangleProgress.sXMax = 70;
  236. myRectangleProgress.sYMax = 60;
  237. GrRectFill(&g_sContext, &myRectangleProgress);
  238. GrFlush(&g_sContext);
  239. Delay_short();
  240. // Set myRectangleProgress values to update progress bar with 100 %
  241. myRectangleProgress.sXMin = 70;
  242. myRectangleProgress.sYMin = 40;
  243. myRectangleProgress.sXMax = 90;
  244. myRectangleProgress.sYMax = 60;
  245. GrRectFill(&g_sContext, &myRectangleProgress);
  246. GrStringDrawCentered(&g_sContext,
  247. "DONE!",
  248. AUTO_STRING_LENGTH,
  249. 48,
  250. 85,
  251. TRANSPARENT_TEXT);
  252. GrFlush(&g_sContext);
  253. Delay_long();
  254. while(1);
  255. }
  256. void clockInit(void)
  257. {
  258. // Set DCO frequency at 8MHz
  259. // ACLK = VLO/1
  260. // SMCLK= DCO/1
  261. // MCLK = DCO/1
  262. // If calibration constant erased
  263. if (CALBC1_8MHZ==0xFF)
  264. {
  265. // do not load, trap CPU!!
  266. while(1);
  267. }
  268. DCOCTL = 0;
  269. BCSCTL1 = CALBC1_8MHZ;
  270. DCOCTL = CALDCO_8MHZ;
  271. BCSCTL3 |= LFXT1S_2;
  272. }
  273. void boardInit()
  274. {
  275. // Set all port as outputs and drive pins low
  276. P1OUT = 0;
  277. P2OUT = 0;
  278. P1DIR = 0xFF;
  279. P2DIR = 0xFF;
  280. }
  281. void flashInit()
  282. {
  283. // Configure flash memory timing
  284. // MCLK/18 for Flash Timing Generator
  285. // 8MHz/(16+1+1) = 444.44 KHz
  286. FCTL2 = FWKEY + FSSEL0 + FN4 + FN0;
  287. }
  288. void timerInit()
  289. {
  290. TA0CTL = TASSEL_2 +ID_3+ MC_1+ TAIE +TACLR;
  291. TA0CCTL0 |= CCIE;
  292. TA0CCR0 = 32000-1;
  293. }
  294. void Delay_long()
  295. {
  296. __delay_cycles(SYSTEM_CLOCK_SPEED * 4);
  297. }
  298. void Delay_short()
  299. {
  300. __delay_cycles(SYSTEM_CLOCK_SPEED * 0.25);
  301. }
  302. #pragma vector=TIMER0_A0_VECTOR
  303. __interrupt void TIMER0_A0_ISR(void)
  304. {
  305. Sharp96x96_SendToggleVCOMCommand();
  306. TA0CCR0 += 32000-1;
  307. TA0CTL &= ~TAIFG;
  308. }