Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. // **************************************************************************
  2. //
  3. // Demo program for labs
  4. //
  5. // Subject: Computer Architectures and Parallel systems
  6. // Author: Petr Olivka, petr.olivka@vsb.cz, 08/2016
  7. // Organization: Department of Computer Science, FEECS,
  8. // VSB-Technical University of Ostrava, CZ
  9. //
  10. // File: Main program for LCD module
  11. //
  12. // **************************************************************************
  13.  
  14. #include "mbed.h"
  15. #include <string>
  16. Serial pc( USBTX, USBRX );
  17.  
  18. #include "lcd_lib.h"
  19.  
  20. // two dimensional array with fixed size font
  21. extern uint8_t font8x8[ 256 ][ 8 ];
  22.  
  23.  
  24. class point{
  25. private:
  26. int x;
  27. int y;
  28. int color;
  29.  
  30.  
  31. public :
  32. void setXY(int x, int y)
  33. {
  34. this->x = x;
  35. this->y = y;
  36. }
  37.  
  38. void setColor(uint8_t r,uint8_t g, uint8_t b)
  39. {
  40. r>>=3;
  41. g>>=2;
  42. b>>=3;
  43. color = 0x0;
  44. color +=r;
  45. color <<= 6;
  46. color+=g;
  47. color <<= 5;
  48. color+=b;
  49. }
  50.  
  51. virtual void view()
  52. {
  53. LCD_put_pixel(this->x,this->y,this->color);
  54. }
  55.  
  56. };
  57.  
  58. void print_char(int startX, int startY, char znak, int color)
  59. {
  60. for(int y = 0; y < 8; y++)
  61. {
  62. for(int x = 0; x < 8; x++)
  63. {
  64. if(font8x8[(int)znak][y] & (1<<x))
  65. {
  66. LCD_put_pixel(startX + x, startY + y, color);
  67. }
  68. }
  69. }
  70. }
  71.  
  72. void print_string(int startX, int startY,string retezec, int color)
  73. {
  74. for(unsigned int i = 0; i < retezec.length(); i++)
  75. {
  76. print_char(startX, startY, retezec[i], color);
  77. startX +=9;
  78. if(startX >= 320)
  79. {
  80. startX = 0;
  81. startY +=10;
  82. }
  83. }
  84. }
  85.  
  86. struct cas{
  87. int h;
  88. int m;
  89. int s;
  90.  
  91. };
  92.  
  93. void cas_init(cas *pcas)
  94. {
  95. pcas->h = 0;
  96. pcas->m = 0;
  97. pcas->s = 0;
  98. }
  99. void cas_inc(cas *pcas)
  100. {
  101. if(pcas->s < 59)
  102. pcas->s += 1;
  103. else
  104. {
  105. pcas->s = 0;
  106. if(pcas->m < 59)
  107. pcas->m += 1;
  108. else
  109. {
  110. pcas->m = 0;
  111. if(pcas->h < 23)
  112. pcas->h = 0;
  113. }
  114.  
  115. }
  116.  
  117. }
  118.  
  119. void cas2str(cas *pcas,char *str)
  120. {
  121. sprintf(str,"%02d:%02d:%02d",pcas->h,pcas->m,pcas->s);
  122.  
  123. }
  124.  
  125. int main()
  126. {
  127. LCD_init(); // LCD initialization
  128.  
  129. LCD_clear(); // LCD clear screen
  130.  
  131.  
  132. int color_red = 0xF800;
  133. int color_green = 0x07E0;
  134. int color_blue = 0x001F;
  135. int color_white = 0xFFFF;
  136. /*
  137. // simple animation display four color square using LCD_put_pixel function
  138. int limit = 200;
  139. for ( int ofs = 0; ofs < 20; ofs++ ) // square offset in x and y axis
  140. for ( int i = 0; i < limit; i++ )
  141. {
  142. LCD_put_pixel( ofs + i, ofs + 0, color_red );
  143. LCD_put_pixel( ofs + 0, ofs + i, color_green );
  144. LCD_put_pixel( ofs + i, ofs + limit, color_blue );
  145. LCD_put_pixel( ofs + limit, ofs + i, color_white );
  146. }
  147.  
  148. return 0;
  149.  
  150.  
  151.  
  152.  
  153. for(int i=0;i<240;i++)
  154. for(int j=0;j<320;j++)
  155. {
  156. point p;
  157. p.setXY(j,i);
  158.  
  159. if(j<100)
  160. p.setColor(255,0,0);
  161. if(j>100&&j<200)
  162. p.setColor(0,255,0);
  163. if(j>200)
  164. p.setColor(0,0,255);
  165. p.view();
  166. }
  167.  
  168. */
  169.  
  170. bool start = false;
  171. bool stop = false;
  172. bool stop2 = false;
  173.  
  174. DigitalIn but9( PTC9 );
  175. DigitalIn but10( PTC10 );
  176. DigitalIn but11( PTC11 );
  177. DigitalIn but12( PTC12 );
  178.  
  179. char pole[14];
  180. char pole2[14];
  181. cas casovac;
  182. cas casovac2;
  183. cas_init(&casovac);
  184. while(1)
  185. {
  186. if(start)
  187. {
  188. print_string(20,20,pole,0x0);
  189.  
  190. cas2str(&casovac,pole);
  191. cas_inc(&casovac);
  192. print_string(20,20,pole,color_white);
  193. wait_ms(1000);
  194.  
  195. }
  196.  
  197. if(!but12)
  198. {
  199. print_string(20,20,pole,0x0);
  200. cas_init(&casovac);
  201. cas2str(&casovac,pole);
  202. print_string(20,20,pole,color_white);
  203. wait_ms(100);
  204. }
  205. if(!but9)
  206. {
  207. start = true;
  208. stop=false;
  209. wait_ms(100);
  210.  
  211. }
  212. if(!but10)
  213. {
  214. stop = true;
  215. start=false;
  216. wait_ms(100);
  217.  
  218. }
  219.  
  220. }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement