Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.86 KB | None | 0 0
  1. #include <msp430x14x.h>
  2.  
  3. #include "uart.h"
  4. #include "portyLcd.h"
  5. #include "lcd.h"
  6. #include "portyUart.h"
  7.  
  8. struct Note
  9. {
  10.      
  11.   int comboValue;
  12.   int frequency;
  13.   int delay;
  14.   int length;
  15.  
  16.   Note(int combo, int Freq, int Delay, int Length)
  17.   {
  18.       comboValue = combo;
  19.       frequency = Freq;
  20.       delay = Delay;
  21.       length = Length;
  22.   }
  23.  
  24.   Note()
  25.   {
  26.     comboValue = 0;
  27.     frequency = 0;
  28.     delay = 1;
  29.     length = 1;
  30.   }
  31. };
  32.  
  33.  
  34. int zeroFrequencesInProgram = 1;
  35.  
  36. char Bufor[30];                         // bufor odczytywanych danych
  37. int low=0;                              // znacznik począteku danych w buforze
  38. int high=0;                             // zmacznik końca danych w buforze
  39.  
  40. Note cycleValues[16];
  41. int cycleCurrentIndex= 0;
  42. int cycleBuforLength = 16;
  43. int cycleTemp[16];
  44.  
  45. int currScore = 0;
  46. int maxScore = 0;
  47.  
  48. int Button1Pressed;
  49. int Button2Pressed;
  50. int Button3Pressed;
  51. int Button4Pressed;
  52.  
  53. const int songLength = 50;
  54. int Mario_bf [songLength]; //bf/10
  55. int Mario_lg [songLength]; //lg/10
  56. int Mario_del [songLength]; //del
  57. int mario_key[songLength];
  58.  
  59. int* songLengths;
  60. int* songNotesFrequences;
  61. int* songNotesDelays;
  62. int* answerKeys;
  63.  
  64. int keyboardPressed = 0;
  65.  
  66. int notePlay = 1;
  67.  
  68. int isPlaying = 0;
  69. int demoLength = 7;
  70.  
  71.  
  72.  
  73. void ShowScreen(int values[]);
  74. Note songNotes[songLength];
  75.  
  76. void MakeSound(long freq, long czasBuzzowania);
  77.  
  78. void AddScore()
  79. {
  80.     currScore += 1;
  81. }
  82.  
  83. int GetScore()
  84. {
  85.     return currScore;
  86. }
  87.  
  88.  
  89. // To jest wciskanie buttonow na msp, tego nie uzywamy - kolo ratunkowe
  90. void ButtonPress()
  91. {
  92.     if(!(P4IN & BIT4)) {
  93.       Bufor[high] = 'q';
  94.       high = (++high) % 30;  
  95.     }
  96.     if(!(P4IN & BIT5)) {
  97.       Bufor[high] = 'w';
  98.       high = (++high) % 30;  
  99.     }
  100.     if(!(P4IN & BIT6)) {
  101.       Bufor[high] = 'e';
  102.       high = (++high) % 30;  
  103.     }
  104.     if(!(P4IN & BIT7)) {
  105.       Bufor[high] = 'r';
  106.       high = (++high) % 30;  
  107.     }
  108. }
  109.  
  110. void ShowEndScreen()
  111. {
  112.       clearDisplay();
  113.      
  114.       char endDisplay[16] = { 'S', 'c', 'o', 'r','e', ':'};
  115.       endDisplay[7] = currScore/100 + 48;
  116.       currScore %= 100;
  117.        endDisplay[8] = currScore/10 + 48;
  118.       currScore %= 10;
  119.       endDisplay[9] = currScore + 48;
  120.       endDisplay[10] = '/';
  121.       endDisplay[11] = maxScore/100 + 48;
  122.       maxScore %= 100;
  123.       endDisplay[12] = maxScore/10 + 48;
  124.       maxScore %= 10;
  125.       endDisplay[13] = maxScore + 48;
  126.      
  127.       SEND_STRING(1, 16, endDisplay);
  128.       MakeSound(100, 5000);
  129. }
  130.    
  131. void CreateSong()
  132. {
  133.    answerKeys = mario_key;
  134.    
  135.    songLengths = Mario_lg;
  136.    songNotesFrequences  = Mario_bf;
  137.    songNotesDelays = Mario_del;
  138.    
  139.    for(int i = 0; i < songLength; i++)
  140.    {
  141.       songNotes[i] = Note(answerKeys[i], songNotesFrequences[i], songNotesDelays[i], songLengths[i]);
  142.    }
  143. }
  144.  
  145. void Update()
  146. {
  147.   if(keyboardPressed>0)
  148.   {
  149.     low=high;
  150.     keyboardPressed--;
  151.   }
  152.   ButtonPress();
  153.   Button1Pressed = false;
  154.   Button2Pressed = false;
  155.   Button3Pressed = false;
  156.   Button4Pressed = false;
  157.   while(high != low)                  // gdy odebrano dane
  158.   {
  159.     if(Bufor[low] == 'q')
  160.             Button1Pressed = true;
  161.     if(Bufor[low] == 'w')
  162.             Button2Pressed = true;
  163.     if(Bufor[low] == 'e')
  164.             Button3Pressed = true;
  165.     if(Bufor[low] == 'r')
  166.             Button4Pressed = true;
  167.     low = (low+1)%30;
  168.   }
  169. }
  170.  
  171. void MakeSound(long freq, long czasBuzzowania)
  172. {
  173.   if(freq != 0)
  174.   {
  175.    
  176.     freq = 750000/freq;
  177.    
  178.    
  179.     czasBuzzowania = (long)(czasBuzzowania * (100 / (float)freq));
  180.   //czasBuzzowania /= 4;
  181.     for(long i = 0; i < czasBuzzowania; i++)
  182.     {
  183.       P4OUT &= ~BIT2;
  184.       P4OUT |= BIT3;
  185.       for(long int j = 0; j < 1 * freq; j++) { }
  186.  
  187.       P4OUT |= BIT2;
  188.       P4OUT &= ~BIT3;
  189.       for(long int j = 0; j < 1 * freq; j++) { }
  190.     }
  191.   }
  192.   else
  193.   {
  194.     int bcaa = 0;
  195.     for(long x = 0; x < czasBuzzowania; x++)
  196.     {
  197.       for(long u = 0; u < 600; u++)
  198.       {
  199.         for(long f = 0; f < 600; f++)
  200.         {
  201.           bcaa += 1;  // dodatkowe obliczenia
  202.           bcaa %= 100;// ktore daja pewniejsze opoznienie
  203.         }
  204.       }
  205.     }
  206.   }
  207. }
  208.  
  209. bool TakeInput(int playerControllerInput, Note note)
  210. {
  211.   if(note . comboValue == playerControllerInput && note.comboValue != 0)
  212.   {
  213.       AddScore();
  214.       return true;
  215.   }
  216.   else
  217.   {
  218.       return false;
  219.   }
  220. }
  221.  
  222. void Push(Note value)
  223. {
  224.    cycleValues[cycleCurrentIndex] = value;
  225.    cycleCurrentIndex = (cycleCurrentIndex+1) % 16;    
  226. }
  227.  
  228. int* GetValues()
  229. {
  230.    int index = 0;
  231.    
  232.    for(int i = cycleCurrentIndex - 1; i >=0; i--)
  233.    {
  234.      cycleTemp[index++] = cycleValues[i] . comboValue;
  235.    }
  236.    
  237.    for(int i = cycleBuforLength-1; i >= cycleCurrentIndex; i--)
  238.    {
  239.         cycleTemp[index++] = cycleValues[i] . comboValue;
  240.    }
  241.    
  242.    return cycleTemp;
  243. }
  244.  
  245. int GetCurrentClickedKeys()
  246. {
  247.   int value  = 0;
  248.   if(Button1Pressed)
  249.     value+=1;
  250.   if(Button2Pressed)
  251.     value+=2;
  252.   if(Button3Pressed)
  253.     value+=4;
  254.   if(Button4Pressed)
  255.     value+=8;
  256.  
  257.   return value;
  258. }
  259.  
  260. Note GetLastCheckNote()
  261. {
  262.   return cycleValues[(cycleCurrentIndex)%16];
  263. }
  264.  
  265. void PushNote(Note note)
  266. {
  267.     Push(note);
  268.   if(isPlaying == 1)
  269.   {  
  270.     ShowScreen(GetValues());
  271.   }
  272.    Note comboValueNeeded = GetLastCheckNote();
  273.   MakeSound(comboValueNeeded . frequency, 200);
  274.   if(isPlaying == 1)
  275.   {
  276.     Update();
  277.     TakeInput(GetCurrentClickedKeys(), comboValueNeeded);
  278.   }
  279. }
  280.  
  281. void FillMarioSong()
  282. { Mario_bf[0]=660; Mario_lg[0]=1;
  283.     Mario_del[0]= 2; mario_key[0] = 12;
  284.     Mario_bf[1]=660; Mario_lg[1]=1;
  285.     Mario_del[1]= 3; mario_key[1] = 8;
  286.     Mario_bf[2]=660; Mario_lg[2]=1;
  287.     Mario_del[2]= 3; mario_key[2] = 2;
  288.     Mario_bf[3]=510; Mario_lg[3]=1;
  289.     Mario_del[3]= 1; mario_key[3] = 10;
  290.     Mario_bf[4]=660; Mario_lg[4]=1;
  291.     Mario_del[4]= 3; mario_key[4] = 4;
  292.     Mario_bf[5]=770; Mario_lg[5]=1;
  293.     Mario_del[5]= 6; mario_key[5] = 3;
  294.     Mario_bf[6]=380; Mario_lg[6]=1;
  295.     Mario_del[6]= 6; mario_key[6] = 7;
  296.  
  297.     Mario_bf[7]=510; Mario_lg[7]=1;
  298.     Mario_del[7]= 5; mario_key[7] = 7;
  299.     Mario_bf[8]=380; Mario_lg[8]=1;
  300.     Mario_del[8]= 4; mario_key[8] = 11;
  301.     Mario_bf[9]=320; Mario_lg[9]=1;
  302.     Mario_del[9]= 5; mario_key[9] = 2;
  303.     Mario_bf[10]=440; Mario_lg[10]=1;
  304.     Mario_del[10]= 3; mario_key[10] = 1;
  305.     Mario_bf[11]=480; Mario_lg[11]=1;
  306.     Mario_del[11]= 3; mario_key[11] = 11;
  307.     Mario_bf[12]=450; Mario_lg[12]=1;
  308.     Mario_del[12]= 2; mario_key[12] = 10;
  309.     Mario_bf[13]=430; Mario_lg[13]=1;
  310.     Mario_del[13]= 3; mario_key[13] = 15;
  311.     Mario_bf[14]=380; Mario_lg[14]=1;
  312.     Mario_del[14]= 2; mario_key[14] = 6;
  313.     Mario_bf[15]=660; Mario_lg[15]=1;
  314.     Mario_del[15]= 2; mario_key[15] = 13;
  315.     Mario_bf[16]=760; Mario_lg[16]=1;
  316.     Mario_del[16]= 2; mario_key[16] = 12;
  317.     Mario_bf[17]=860; Mario_lg[17]=1;
  318.     Mario_del[17]= 3; mario_key[17] = 12;
  319.     Mario_bf[18]=700; Mario_lg[18]=1; mario_key[18] = 11;
  320.     Mario_del[18]= 2;
  321.     Mario_bf[19]=760; Mario_lg[19]=1; mario_key[19] = 1;
  322.     Mario_del[19]= 4;
  323.     Mario_bf[20]=660; Mario_lg[20]=1; mario_key[20] = 6;
  324.     Mario_del[20]= 3;
  325.     Mario_bf[21]=520; Mario_lg[21]=1; mario_key[21] = 15;
  326.     Mario_del[21]= 2;
  327.     Mario_bf[22]=580; Mario_lg[22]=1; mario_key[22] = 2;
  328.     Mario_del[22]= 2;
  329.     Mario_bf[23]=480; Mario_lg[23]=1; mario_key[23] = 10;
  330.     Mario_del[23]= 5;
  331.  
  332.     Mario_bf[24]=510; Mario_lg[24]=1; mario_key[24] = 14;
  333.     Mario_del[24]= 5;
  334.     Mario_bf[25]=380; Mario_lg[25]=1; mario_key[25] = 13;
  335.     Mario_del[25]= 4;
  336.     Mario_bf[26]=320; Mario_lg[26]=1; mario_key[26] = 13;
  337.     Mario_del[26]= 5;
  338.     Mario_bf[27]=440; Mario_lg[27]=1; mario_key[27] = 11;
  339.     Mario_del[27]= 3;
  340.     Mario_bf[28]=480; Mario_lg[28]=1; mario_key[28] = 1;
  341.     Mario_del[28]= 3;
  342.     Mario_bf[29]=450; Mario_lg[29]=1; mario_key[29] = 4;
  343.     Mario_del[29]= 2;
  344.     Mario_bf[30]=430; Mario_lg[30]=1; mario_key[30] = 7;
  345.     Mario_del[30]= 3;
  346.     Mario_bf[31]=380; Mario_lg[31]=1; mario_key[31] = 8;
  347.     Mario_del[31]= 2;
  348.     Mario_bf[32]=660; Mario_lg[32]=1; mario_key[32] = 6;
  349.     Mario_del[32]= 2;
  350.     Mario_bf[33]=760; Mario_lg[33]=1; mario_key[33] = 15;
  351.     Mario_del[33]= 2;
  352.     Mario_bf[34]=860; Mario_lg[34]=1; mario_key[34] = 1;
  353.     Mario_del[34]= 3;
  354.     Mario_bf[35]=700; mario_key[35] = 13; Mario_lg[35]=1;
  355.     Mario_del[35]= 2;
  356.     Mario_bf[36]=760; mario_key[36] = 1; Mario_lg[36]=1;
  357.     Mario_del[36]= 4;
  358.     Mario_bf[37]=660; mario_key[37] = 7; Mario_lg[37]=1;
  359.     Mario_del[37]= 3;
  360.     Mario_bf[38]=520; mario_key[38] = 5; Mario_lg[38]=1;
  361.     Mario_del[38]= 2;
  362.     Mario_bf[39]=580; mario_key[39] = 14; Mario_lg[39]=1;
  363.     Mario_del[39]= 2;
  364.     Mario_bf[40]=480; mario_key[40] = 9; Mario_lg[40]=1;
  365.     Mario_del[40]= 5;
  366.  
  367.     Mario_bf[41]=500; mario_key[41] = 9;0; Mario_lg[41]=1;
  368.     Mario_del[41]= 3; mario_key[42] = 11;
  369.  
  370.     Mario_bf[42]=760; Mario_lg[42]=1;
  371.     Mario_del[42]= 1; mario_key[43] = 11;
  372.     Mario_bf[43]=720; Mario_lg[43]=1;
  373.     Mario_del[43]= 2; mario_key[44] = 2;
  374.     Mario_bf[44]=680; Mario_lg[44]=1;
  375.     Mario_del[44]= 2; mario_key[45] = 5;
  376.     Mario_bf[45]=620; Mario_lg[45]=2;
  377.     Mario_del[45]= 3; mario_key[46] = 13;
  378.  
  379.     Mario_bf[46]=650; Mario_lg[46]=2;
  380.     Mario_del[46]= 3; mario_key[47] = 3;
  381.     Mario_bf[47]=380; Mario_lg[47]=1;
  382.     Mario_del[47]= 2; mario_key[48] = 8;
  383.     Mario_bf[48]=430; Mario_lg[48]=1;
  384.     Mario_del[48]= 2; mario_key[49] = 13;
  385.  
  386.     Mario_bf[49]=500; Mario_lg[49]=1;
  387.     Mario_del[49]= 3;
  388.    
  389.  
  390.    songLengths = Mario_lg;
  391.    songNotesFrequences = Mario_bf;
  392.    songNotesDelays = Mario_del;
  393.    answerKeys = mario_key;
  394. }
  395.  
  396. void ResetScore()
  397. {
  398.     currScore = 0;
  399. }
  400.  
  401.  
  402. void SongPlaying(int length)
  403. {
  404.   int noteIndex = 0;
  405.   for(int i = 0; i < length + 18; i++)
  406.   {  
  407.       Note noteToSend = Note(0, 0, 0 , 0);
  408.       Note currentNote;
  409.       if(i < length)
  410.       {
  411.           currentNote = songNotes[i];
  412.  
  413.           for(int j = 0; j < currentNote.delay; j++)
  414.           {
  415.             if(j < currentNote.length)
  416.             {
  417.              
  418.               if(noteIndex == 0)
  419.               {
  420.                 noteToSend . comboValue = currentNote.comboValue;
  421.                 maxScore += 1;
  422.               }
  423.               else
  424.                noteToSend . comboValue = 0;
  425.              
  426.                noteIndex = (noteIndex +  1) % notePlay;
  427.               noteToSend . frequency = currentNote.frequency;                      
  428.             }
  429.             else
  430.             {
  431.                noteToSend . comboValue = 0;
  432.                noteToSend . frequency = 0;
  433.             }  
  434.              PushNote(noteToSend);
  435.           }
  436.       }
  437.       else
  438.       {
  439.           noteToSend . comboValue = 0;
  440.           noteToSend . frequency = 0;
  441.           PushNote(noteToSend);
  442.       }
  443.              
  444.   }
  445.   if(isPlaying == 1)
  446.   {
  447.     ShowEndScreen();
  448.   }
  449.   currScore = 0;
  450.   maxScore = 0;
  451.   low=high;
  452.   isPlaying = 0;
  453. }
  454.  
  455. void LCDController()
  456. {
  457.     char signs[4][8] =
  458.     {
  459.         { 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00 }, // BOTh EMPTY 0x01
  460.         { 0x1F, 0x10, 0x10, 0x1f, 0x1f, 0x10, 0x10, 0x1f }, // BOTh BUSY 0x02
  461.         { 0x00, 0x0e, 0x00, 0x00, 0x1f, 0x10, 0x10, 0x1f }, // BOT BUSY 0x03
  462.         { 0x1f, 0x10, 0x10, 0x1f, 0x00, 0x0e, 0x00, 0x00 }, // TOP BUSY 0x04
  463.  
  464.     };
  465.    
  466.     SEND_CMD(CG_RAM_ADDR);
  467.    
  468.     for(int i = 0; i < 4; i++)
  469.         for(int j = 0; j < 8; j++)
  470.            SEND_CHAR(signs[i][j]);
  471.  
  472. }
  473.    
  474. void InitBuzzerBits()
  475. {
  476.     P4DIR |= BIT2;
  477.     P4DIR |= BIT3;
  478.  
  479.     P4DIR &= ~BIT4;
  480.     P4DIR &= ~BIT5;
  481.     P4DIR &= ~BIT6;
  482.     P4DIR &= ~BIT7;
  483. }
  484.  
  485. void PrepareCustomChars()
  486. {
  487.     char signs[4][8] =
  488.     {
  489.       {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
  490.       {0x00,0x1f,0x1f,0x00,0x00,0x1f,0x1f,0x00},
  491.       {0x00,0x00,0x00,0x00,0x00,0x1f,0x1f,0x00},
  492.       {0x00,0x1f,0x1f,0x00,0x00,0x00,0x00,0x00}
  493.     };
  494.  
  495.     SEND_CMD(CG_RAM_ADDR);
  496.     for(int i = 0; i < 4; i++)
  497.         for(int j = 0; j < 8; j++)
  498.             SEND_CHAR(signs[i][j]);
  499.  
  500.     SEND_CMD(DD_RAM_ADDR);
  501. }
  502.  
  503. void WyswitlEkranWstepu()
  504. {
  505.     // wyswietlanie napisu MSPHero - Godlike UART, czy cos - miejsce na smieszek
  506.     SEND_CMD(DD_RAM_ADDR);
  507.     SEND_STRING(1,16,"     MSPHero    ");// TODO
  508.     SongPlaying(demoLength);
  509. }
  510.  
  511. int WyswietlMenu()
  512. {
  513.     int chosenOption = 0;
  514.     SEND_CMD(DD_RAM_ADDR);
  515.     SEND_STRING(1, 16, " MSPHero - Menu: ");
  516.     SEND_CMD(DD_RAM_ADDR2);
  517.     SEND_STRING(2, 16, "Lvl 1-4: q,w,e,r");
  518.     // wyswitlanie opcji:
  519.     // Zagraj piosenke:
  520.     // 1. Mario.
  521.     // 2. Metallica.
  522.     while(high != low)                  // gdy odebrano dane
  523.     {
  524.       if(Bufor[low] == 'q'){
  525.           chosenOption = 1;
  526.           SEND_CMD(DD_RAM_ADDR);
  527.           low=high;
  528.           break;
  529.       }
  530.       else  if(Bufor[low] == 'w'){
  531.           chosenOption = 2;
  532.           SEND_CMD(DD_RAM_ADDR);
  533.           low=high;
  534.           break;
  535.       }
  536.       else  if(Bufor[low] == 'e'){
  537.           chosenOption = 3;
  538.           SEND_CMD(DD_RAM_ADDR);
  539.           low=high;
  540.           break;
  541.       }
  542.       else if(Bufor[low] == 'r'){
  543.           chosenOption = 4;
  544.           SEND_CMD(DD_RAM_ADDR);
  545.           low=high;
  546.           break;
  547.       }
  548.       else{
  549.           low = (++low)%30;
  550.           chosenOption = 0;
  551.       }
  552.     }
  553.     return chosenOption;
  554. }
  555.  
  556. void PlaySong(int index)
  557. {
  558.     MakeSound(10, 1000);
  559.     MakeSound(50, 1000);
  560.     MakeSound(100, 1000);
  561.     MakeSound(400, 1000);
  562.     MakeSound(1000, 1000);
  563.     MakeSound(10, 1000);
  564.     MakeSound(100, 1000);
  565.     MakeSound(1000, 1000);
  566.     ResetScore();
  567.     if(index != 0)
  568.     {      
  569.       SongPlaying(songLength);
  570.     }
  571. }
  572.  
  573. int main( void )
  574. {
  575.     P4DIR |= BIT2;
  576.     P4DIR |= BIT3;
  577.    
  578.     P4DIR &= ~BIT4;
  579.     P4DIR &= ~BIT5;
  580.     P4DIR &= ~BIT6;
  581.     P4DIR &= ~BIT7;
  582.  
  583.     WDTCTL=WDTPW + WDTHOLD;               // wyłączenie WDT
  584.  
  585.     // Timer_A  ustawiamy na 500 kHz
  586.     // a przerwanie generujemy co 100 ms
  587.     TACTL = TASSEL_1 + MC_1 +ID_3;        // Wybieram ACLK, ACLK/8=500kHz,tryb Up
  588.     CCTL0 = CCIE;                         // włączenie przerwań od CCR0
  589.     CCR0=50000;                           // podzielnik 50000: przerwanie co 100 ms
  590.  
  591.     InitPortsLcd();                        // inicjalizacja portów LCD
  592.     InitLCD();                             // inicjalizacja LCD
  593.     clearDisplay();                        // czyszczenie wyświetlacza
  594.     initPortyUart();                       // inicjalizacja portow UART
  595.     initUart(1200); //ma byc 15200
  596.                      // inicjalizacja UARTa
  597.  
  598.      _EINT();       //TODO                        // włączenie przerwań
  599.     SEND_CMD(DD_RAM_ADDR);
  600.  
  601.     PrepareCustomChars();
  602.  
  603.     InitBuzzerBits();
  604.  
  605.     for(int i = 0; i < 16; i++)
  606.     {
  607.             Note emptyNote;
  608.             cycleValues[i] = emptyNote;
  609.     }
  610.    
  611.     FillMarioSong();
  612.     CreateSong();
  613.  
  614.     WyswitlEkranWstepu();
  615.  
  616.     while(1)
  617.     {
  618.         int chosenOption = WyswietlMenu();
  619.         ButtonPress();
  620.         if(chosenOption != 0)
  621.         {
  622.           switch(chosenOption)
  623.           {
  624.           case 1:
  625.             notePlay = 7;
  626.             break;
  627.           case 2:
  628.             notePlay = 5;
  629.             break;
  630.           case 3:
  631.             notePlay = 3;
  632.             break;
  633.           case 4:
  634.             notePlay = 1;
  635.             break;
  636.           }
  637.          
  638.           clearDisplay();
  639.           isPlaying = true;
  640.          PlaySong(chosenOption);
  641.         }
  642.     }
  643. }
  644.  
  645. void ShowScreen(int values[])
  646. {
  647.   int tab[16][2];
  648.   for(int y = 0; y < 16; y++)
  649.   {
  650.       int wart[2] = {0, 0};
  651.       int sprawdzanyBit = 8;
  652.       int sprawdzanaWartosc = values[y];
  653.       while(sprawdzanyBit != 0)
  654.       {
  655.           if(sprawdzanaWartosc >= sprawdzanyBit)
  656.           {
  657.               if(sprawdzanyBit == 8)
  658.                 wart[0] += 1;
  659.               if(sprawdzanyBit == 4)
  660.                 wart[0] += 2;
  661.               if(sprawdzanyBit == 2)
  662.                 wart[1] += 1;
  663.               if(sprawdzanyBit == 1)
  664.                 wart[1] += 2;
  665.               sprawdzanaWartosc -= sprawdzanyBit;
  666.           }
  667.           sprawdzanyBit /= 2;
  668.       }
  669.       for(int o = 0; o < 2; o++)
  670.       {
  671.         // BOTh EMPTY 0x00
  672.         // BOTh BUSY 0x01
  673.         // BOT BUSY 0x02
  674.         // TOP BUSY 0x03
  675.         if(wart[o] == 0)
  676.             tab[y][o] = 0x00;
  677.         else if(wart[o] == 1)
  678.             tab[y][o] = 0x03;
  679.         else if(wart[o] == 2)
  680.             tab[y][o] = 0x02;
  681.         else if(wart[o] == 3)
  682.             tab[y][o] = 0x01;
  683.       }
  684.   }
  685.   for(int j = 0; j < 2; j++)
  686.   {
  687.         if(j == 0)
  688.             SEND_CMD(DD_RAM_ADDR);
  689.         else
  690.             SEND_CMD(DD_RAM_ADDR2);
  691.         for(int i = 0; i < 16; i++)
  692.         {
  693.             SEND_CHAR(tab[i][j]);
  694.         }
  695.   }
  696. }
  697.  
  698.  
  699. #pragma vector = UART0RX_VECTOR           // procedura obsługi przerwania UART
  700. __interrupt void usart0_rx (void)
  701. {
  702.     keyboardPressed = 8;
  703.     Bufor[high] = RXBUF0;                     // wpisanie odebranych danych do bufora
  704.     high = (++high) % 30;                       // inkrementowanie znacznika końca danych
  705. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement