Advertisement
kabanosiek

Untitled

Nov 17th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.70 KB | None | 0 0
  1. #include "msp430x14x.h"
  2. #include "lcd.h"
  3. #include "portyLcd.h"
  4.  
  5.  
  6. //---------------- zmienne globalne -------------
  7. unsigned int i=0;
  8. unsigned int sekundy=0;
  9. unsigned int licznik=0;
  10. int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
  11. typedef struct
  12. {
  13. int year;
  14. int day;
  15. int month;
  16. int hour;
  17. int minutes;
  18. int second;
  19. int milisecond;
  20. }time;
  21.  
  22.  
  23. time Clock(time czas);
  24. void InitSpecial()
  25. {
  26. SEND_CMD(CG_RAM_ADDR);
  27. int spec[6][8] = {{2,4,15,2,4,8,15,0}, //ź 8
  28. {2,4,14,17,17,17,17,0}} ;
  29. int i,j;
  30. for(i = 0; i < 2; i++)
  31. {
  32. for(j = 0; j < 8; j++)
  33. {
  34. SEND_CHAR(spec[i][j]);
  35. }
  36. }
  37. }
  38.  
  39. void printmonth(int month)
  40. {
  41. switch(month)
  42. {
  43. case 1:
  44. SEND_CHAR('S');
  45. SEND_CHAR('t');
  46. SEND_CHAR('y');
  47. SEND_CHAR('c');
  48. SEND_CHAR('z');
  49. SEND_CHAR('e');
  50. SEND_CHAR(9);
  51. break;
  52. case 2:
  53. SEND_CHAR('L');
  54. SEND_CHAR('u');
  55. SEND_CHAR('t');
  56. SEND_CHAR('y');
  57. break;
  58. case 3:
  59. SEND_CHAR('M');
  60. SEND_CHAR('a');
  61. SEND_CHAR('r');
  62. SEND_CHAR('z');
  63. SEND_CHAR('e');
  64. SEND_CHAR('c');
  65. break;
  66. case 4:
  67. SEND_CHAR('K');
  68. SEND_CHAR('w');
  69. SEND_CHAR('i');
  70. SEND_CHAR('e');
  71. SEND_CHAR('c');
  72. SEND_CHAR('i');
  73. SEND_CHAR('e');
  74. SEND_CHAR(9);
  75. break;
  76. case 5:
  77. SEND_CHAR('M');
  78. SEND_CHAR('a');
  79. SEND_CHAR('j');
  80. break;
  81. case 6:
  82. SEND_CHAR('C');
  83. SEND_CHAR('z');
  84. SEND_CHAR('e');
  85. SEND_CHAR('r');
  86. SEND_CHAR('w');
  87. SEND_CHAR('i');
  88. SEND_CHAR('e');
  89. SEND_CHAR('c');
  90. break;
  91. case 7:
  92. SEND_CHAR('L');
  93. SEND_CHAR('i');
  94. SEND_CHAR('p');
  95. SEND_CHAR('i');
  96. SEND_CHAR('e');
  97. SEND_CHAR('c');
  98. break;
  99. case 8:
  100. SEND_CHAR('S');
  101. SEND_CHAR('i');
  102. SEND_CHAR('e');
  103. SEND_CHAR('r');
  104. SEND_CHAR('p');
  105. SEND_CHAR('i');
  106. SEND_CHAR('e');
  107. SEND_CHAR(9);
  108. break;
  109. case 9:
  110. SEND_CHAR('W');
  111. SEND_CHAR('r');
  112. SEND_CHAR('z');
  113. SEND_CHAR('e');
  114. SEND_CHAR('s');
  115. SEND_CHAR('i');
  116. SEND_CHAR('e');
  117. SEND_CHAR(9);
  118. break;
  119. case 10:
  120. SEND_CHAR('P');
  121. SEND_CHAR('a');
  122. SEND_CHAR(8);
  123. SEND_CHAR('d');
  124. SEND_CHAR('z');
  125. SEND_CHAR('i');
  126. SEND_CHAR('e');
  127. SEND_CHAR('r');
  128. SEND_CHAR('n');
  129. SEND_CHAR('i');
  130. SEND_CHAR('k');
  131. break;
  132. case 11:
  133. SEND_CHAR('L');
  134. SEND_CHAR('i');
  135. SEND_CHAR('s');
  136. SEND_CHAR('t');
  137. SEND_CHAR('o');
  138. SEND_CHAR('p');
  139. SEND_CHAR('a');
  140. SEND_CHAR('d');
  141. break;
  142. case 12:
  143. SEND_CHAR('G');
  144. SEND_CHAR('r');
  145. SEND_CHAR('u');
  146. SEND_CHAR('d');
  147. SEND_CHAR('z');
  148. SEND_CHAR('i');
  149. SEND_CHAR('e');
  150. SEND_CHAR(9);
  151. break;
  152.  
  153. }
  154. }
  155. time updatemonth(time t)
  156. {
  157. if(t.month<12)
  158. {t.month++;}
  159. else
  160. {
  161. t.month=1;
  162. t.year++;
  163. if(t.year==3000)
  164. t.year=1900;
  165. }
  166. return t;
  167. }
  168. time updateday(time t)
  169. {
  170. if((t.year%4==0 && t.year%100!=0 ) || t.year%400==0)
  171. days[1]=29;
  172. else
  173. days[1]=28;
  174. if(t.day<days[t.month-1])
  175. {
  176. t.day++;
  177. }
  178. else
  179. {
  180. t.day=1;
  181. t=updatemonth(t);
  182. }
  183. return t;
  184. }
  185.  
  186. time updatehour(time t)
  187. {
  188. if(t.hour<23)
  189. { t.hour++;}
  190. else
  191. {
  192. t.hour=0;
  193. t=updateday(t);
  194. }
  195.  
  196. return t;
  197. }
  198.  
  199. time updateminutes(time t)
  200. {
  201. if(t.minutes<59)
  202. {t.minutes++;}
  203. else
  204. {
  205. t.minutes=0;
  206. t=updatehour(t);
  207. }
  208. return t;
  209. }
  210. time updatesecond(time t)
  211. {
  212. if(t.second<59)
  213. {
  214. t.second++;
  215. }
  216. else
  217. {
  218. t.second=0;
  219. t=updateminutes(t);
  220. }
  221. return t;
  222. }
  223. time updatemilisecond(time t)
  224. {
  225. if(t.milisecond<9)
  226. {
  227. t.milisecond++;
  228. }
  229. else
  230. {
  231. t.milisecond=0;
  232. t=updatesecond(t);
  233. }
  234. return t;
  235. }
  236. //----------------- main program -------------------
  237. void main( void )
  238. {
  239. time czas;
  240. czas.day=29;
  241. czas.month=2;
  242. czas.hour=23;
  243. czas.minutes=59;
  244. czas.second=58;
  245. czas.milisecond=0;
  246. czas.year=2004;
  247. if(czas.year<1900)//anti-debilizm
  248. czas.year=1900;
  249. P2DIR |= BIT1 ; // STATUS LED
  250.  
  251. WDTCTL=WDTPW + WDTHOLD; // Wyłączenie WDT
  252.  
  253. InitPortsLcd(); // inicjalizacja portów LCD
  254. InitLCD(); // inicjalizacja LCD
  255. clearDisplay(); // czyszczenie wyświetlacza
  256.  
  257. // Basic Clock Module ustawiamy na ACLK(zegar 8 MHz ) i dzielimy częstotliwość przez 2 (4 MHz)
  258. BCSCTL1 |= XTS; // ACLK = LFXT1 = HF XTAL 8MHz
  259.  
  260. do
  261. {
  262. IFG1 &= ~OFIFG; // Czyszczenie flgi OSCFault
  263. for (i = 0xFF; i > 0; i--); // odczekanie
  264. }
  265. while ((IFG1 & OFIFG) == OFIFG); // dopóki OSCFault jest ciągle ustawiona
  266.  
  267. BCSCTL1 |= DIVA_1; // ACLK=8 MHz/2=4 MHz
  268. BCSCTL2 |= SELM0 | SELM1; // MCLK= LFTX1 =ACLK
  269.  
  270. // Timer_A ustawiamy na 500 kHz
  271. // a przerwanie generujemy co 100 ms
  272. TACTL = TASSEL_1 + MC_1 +ID_3; // Wybieram ACLK, ACLK/8=500kHz,tryb Up
  273. CCTL0 = CCIE; // włączenie przerwań od CCR0
  274. CCR0=50000; // podzielnik 50000: przerwanie co 100 ms
  275.  
  276. _EINT(); // włączenie przerwań
  277.  
  278. for (;;)
  279. {
  280. _BIS_SR(LPM3_bits); // przejscie do trybu LPM3
  281. czas=Clock(czas);
  282. }
  283. }
  284.  
  285. time Clock(time czas)
  286. {
  287.  
  288. //if (licznik %10 ==0) // gdy mineła sekunda (10 * 100 milisekund)
  289. //{
  290. SEND_CMD(DD_RAM_ADDR);
  291. licznik=0;
  292. P2OUT ^=BIT1; //zapal diodę
  293. czas=updatemilisecond(czas);
  294. /*if(czas.hour==0 && czas.minutes==0 && czas.second==0)
  295. {
  296. czas=updateday(czas);
  297. }*/
  298. printDecDigit(czas.day/10);
  299. printDecDigit(czas.day%10);
  300. SEND_CHAR(' ');
  301. printmonth(czas.month);
  302. SEND_CMD(DD_RAM_ADDR2);
  303. printDecDigit(czas.hour/10);
  304. printDecDigit(czas.hour%10);
  305. SEND_CHAR(':');
  306. printDecDigit(czas.minutes/10);
  307. printDecDigit(czas.minutes%10);
  308. SEND_CHAR(':');
  309. printDecDigit(czas.second/10);
  310. printDecDigit(czas.second%10);
  311. SEND_CHAR(':');
  312. printDecDigit(czas.milisecond);
  313. SEND_CHAR(' ');
  314. printDecDigit(czas.year/1000);
  315. printDecDigit((czas.year/100)-(czas.year/1000)*10);
  316. printDecDigit((czas.year%100)/10);
  317. printDecDigit(czas.year%10);
  318. SEND_CMD(DD_RAM_ADDR);
  319. int j;
  320. for(j=0;j<9;j++)
  321. {
  322. SEND_CMD(CUR_SHIFT_LEFT);// wróć kursorem na początek
  323. }
  324. return czas;
  325. //}
  326. //return czas;
  327. }
  328.  
  329. // procedura obsługi przerwania od TimerA
  330.  
  331. #pragma vector=TIMERA0_VECTOR
  332. __interrupt void Timer_A (void)
  333. {
  334. ++licznik;
  335. _BIC_SR_IRQ(LPM3_bits); // wyjście z trybu LPM3
  336. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement