SNAKE PARA MSP430
Autor: Marco Antônio | Publicado: 2014-11-18T12:39:00-08:00

//SNAKE PARA MSP430 - VERSÃO FINAL 
//MODELO programado em C está publicado no post anterior
//Vídeos explicativos nos links abaixo
//Parte 1
//Parte 2
//Parte 3 




//JOGO SNAKE
#include #include #include  //Define o valor da constante RAND_MAX -&gt; rand() produz um valor entre 0 e RAND_MAX#include  //Permite o uso da função rand()#include //______________________________________________________________________________//DECLARAÇÃO DAS VARIÁVEIS GLOBAISunsigned int matriz[8][8]; //tabuleirounsigned int *zeros[16],*snake[36],*cresce[3]; //vetores de ponteirosunsigned int i,j,scorep,cont,movimento,level;unsigned int contazeros,size,lugar,headline,headcol; //variáveis de operação//______________________________________________________________________________//DECLARAÇÃO DE FUNÇÕES//ENCONTRA ESPAÇO VAZIO E GERA NOVO PONTOvoid gerafruta(void) //Procura espaços vazios na matriz{&nbsp;&nbsp;&nbsp; contazeros=0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lugar = rand()%4; //gera um valor aleatório para procura em 1 dos 4 quadrantes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (lugar==2) //1o quadrante&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=0;i<4 br="" i="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(j=0;j<4 br="" j="">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (matriz[i][j]==0) //Encontra os espaços vazios na matriz&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; zeros[contazeros] = &amp;matriz[i][j];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; contazeros++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (lugar==3 || contazeros==0) //2o quadrante&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=0;i<4 br="" i="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(j=4;j<8 br="" j="">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (matriz[i][j]==0) //Encontra os espaços vazios na matriz&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; zeros[contazeros] = &amp;matriz[i][j];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; contazeros++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (lugar==1 || contazeros==0) //3o quadrante&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=4;i<8 br="" i="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(j=0;j<4 br="" j="">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (matriz[i][j]==0) //Encontra os espaços vazios na matriz&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; zeros[contazeros] = &amp;matriz[i][j];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; contazeros++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (lugar==0 || contazeros==0) //4o quadrante&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=4;i<8 br="" i="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(j=4;j<8 br="" j="">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (matriz[i][j]==0) //Encontra os espaços vazios na matriz&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; zeros[contazeros] = &amp;matriz[i][j];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; contazeros++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lugar = rand()%contazeros; //gera um valor aleatório (0 a contazeros-1)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *zeros[lugar] = 2; //zeros[lugar] = endereço da matriz onde foi criada a nova fruta/*Na funçao acima, foi criado um vetor de ponteiros.No vetor zeros[] são armazenados os endereços de memoria dos zeros da matrizA função rand() gera um número entre zero e RAND_MAX (definido na biblioteca stdlib.h,com o valor de 0x3fffffff no caso desse programa) e o operador % devolve o resto da divisão (para um valor x temos x%3 = 0, 1 ou 2)A variável lugar gera um número aleatorio dentre as posiçoes do vetor de zerosPor fim o LED correspondente ao espaço da matriz é ligadoTendo ocorrido problemas de falta de memória para armazenar vetores de 64 posiçõeso vetor de zeros foi reduzido para 16 posições, e faz referência a um dos quatro quadrantesescolhidos aleatóriamente para busca de um espaço vazio que será preenchido pela nova fruta*/}void reinicia(void){&nbsp;&nbsp;&nbsp; //INICIALIZA MATRIZ VETORES E VARIAVEIS&nbsp; i=0;j=0;scorep=0;cont=0;contazeros=0;lugar=0;size=0;headline=0;headcol=0;movimento=0;&nbsp; for (i=0;i<36 br="" i="" snake="">&nbsp; for (i=0;i<16 br="" i="" zeros="">&nbsp; for (i=0;i<3 br="" cresce="" i="">&nbsp; for (i=0;i<8 br="" i="" inicializa="" matriz="">&nbsp; {&nbsp;&nbsp;&nbsp; for (j=0;j<8 br="" j="">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; matriz[i][j]=0;&nbsp;&nbsp;&nbsp; }&nbsp; }&nbsp; &nbsp; //SITUAÇÃO INICIAL DO JOGO&nbsp; matriz[5][1] = 1;&nbsp; snake[0] = &amp;matriz[5][1];&nbsp; matriz[5][2] = 1;&nbsp; snake[1] = &amp;matriz[5][2];&nbsp; matriz[5][3] = 1;&nbsp; snake[2] = &amp;matriz[5][3];&nbsp; headline=5;&nbsp; headcol=3;&nbsp; size=3;&nbsp; gerafruta();&nbsp; P1OUT |= 0x80; //Pino MR1 (Master reset 1) do CI 74LS90, controla o reset do contador - 1=Reset 0=Count&nbsp; P1OUT &amp;= ~0x80;&nbsp; P1OUT |= 0x20; //Controla o pino BL do CI 4511, acende o display de LED de 7 segmentos}void score(void){&nbsp; P1OUT |= 0x40;&nbsp; P1OUT &amp;= ~0x40;&nbsp; &nbsp; scorep++;}//______________________________________________________________________________void acende(void)//Função de clock do shift register{&nbsp;&nbsp;&nbsp; P2OUT &amp;= ~0x01; //DATA = 0(LIGA)&nbsp;&nbsp;&nbsp; P2OUT |= 0x02; //CLOCK ALTO&nbsp;&nbsp;&nbsp; P2OUT &amp;= ~0x02; //CLOCK BAIXO//COLUNAS VERDES -&gt; SINAL BAIXO LIGA / ALTO DESLIGA//Função de controle do SHIFT REGISTER 74LS164 - Pinos(MSP) P2.0(ENTRADA A),P2.1(CLOCK),P2.2(RESET)//Estabelece a situação ligado/desligado de cada LED da linha//O primeiro valor é definido para QA, no sinal de Clock esse valor é transferido para QB e assim por diante até chegar em QH//Serão deslocados 8 valores e então a linha será energizada}//______________________________________________________________________________void apaga(void)//Função de clock do shift register{&nbsp;&nbsp;&nbsp; P2OUT |= 0x01; //DATA = 1(DESLIGA)&nbsp;&nbsp;&nbsp; P2OUT |= 0x02; //CLOCK ALTO&nbsp;&nbsp;&nbsp; P2OUT &amp;= ~0x02; //CLOCK BAIXO}//______________________________________________________________________________void desligalinhas(void){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //P1=1111b&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; P1OUT |= 0x0F; //Para desligar todas as colunas basta apontar o DEMUX para a saída 15 não conectada ao circuito//linhas//Função de controle do DEMUX 74154 - Pinos(MSP) P1.0(LSB),1,2,3(MSB)//Seleciona uma saída de 1 a 15 (usadas apenas as 8 primeiras saídas), a saída escolhida recebe sinal baixo, todas as demais sinal alto//Foram utilizados transistores PNP já que a saída do DEMUX é sinal baixo//Usado para acionamento das linhas da Matriz 8x8}void linha1(void){&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; P1OUT &amp;= 0xF0; //P1=0000b}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void linha2(void){&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; P1OUT = ((P1OUT&amp;0xF0)|0x01); //P1=0001b&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //P1OUT é zerado com o comando AND e depois setado com OR}void linha3(void){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; P1OUT = ((P1OUT&amp;0xF0)|0x02); //P1=0010b}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; void linha4(void){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; P1OUT = ((P1OUT&amp;0xF0)|0x03); //P1=0011b}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void linha5(void){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; P1OUT = ((P1OUT&amp;0xF0)|0x04); //P1=0100b}void linha6(void){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; P1OUT = ((P1OUT&amp;0xF0)|0x05); //P1=0101b}void linha7(void){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; P1OUT = ((P1OUT&amp;0xF0)|0x06); //P1=0110b}void linha8(void){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; P1OUT = ((P1OUT&amp;0xF0)|0x07); //P1=0111b}void game_over(void){&nbsp; desligalinhas();&nbsp; for (i=0;i<4 br="" i="">&nbsp; {&nbsp; P1OUT |= 0x20; //P1.5 Controla o pino BL no CI 4511, faz o display de LED de 7 segmentos piscar quando o jogo termina&nbsp; __delay_cycles(500000);&nbsp; P1OUT &amp;= ~0x20;&nbsp; __delay_cycles(500000);&nbsp; }}//______________________________________________________________________________//FUNÇÃO UPvoid up(void){&nbsp; if (headline==0){game_over();reinicia();return;} //se a cobra estiver na borda superior dá gameover - a condição de baixo nao entrou junto no if pois se a headline ja fosse zero ficaria matriz[-1] e daria erro&nbsp;&nbsp;&nbsp; else if (matriz[headline-1][headcol]==1 &amp;&amp; snake[0]!=&amp;matriz[headline-1][headcol]){game_over();reinicia();return;} //se o proximo destino colidir com corpo (menos a cauda) da cobra -&gt; gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline-1][headcol]==1 &amp;&amp; snake[0]==&amp;matriz[headline-1][headcol] &amp;&amp; snake[0]==cresce[0] &amp;&amp; cont&gt;0){game_over();reinicia();return;} //caso particular em que a cobra irá crescer, assim ocorre colisao com a cauda -&gt; gameover&nbsp;&nbsp;&nbsp; //else if (snake[size-2]==&amp;matriz[headline-1][headcol]){} //se a cobra tentar retornar sobre si mesmo a jogada será invalida - Se (proximo local = pescoço da cobra) -&gt; jogada invalida&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; headline--; //desloca uma linha para cima&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[0]==cresce[0] &amp;&amp; cont&gt;0) //QUANDO A COBRA DEVE CRESCER - quando a fruta engolida estiver no ultimo segmento da cobra e o contador de frutas engolidas for maior que 0 (caso contrario cresceria passando novamente pelo mesmo local mesmo que sem fruta)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //snake[0]=rabo da cobra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cont--;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cresce[i]=cresce[i+1]; //desloca para a esquerda o vetor de crescimento - para o caso de mais de uma fruta engolida e nao digerida&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else //QUANDO A COBRA NAO PRECISA CRESCER&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[0] = 0; //apaga o ultimo ponto da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[i] = snake[i+1]; //movimenta a cobra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[i] = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[size-1] = &amp;matriz[headline][headcol]; //snake[size-1] recebe o novo endereço da cabeça da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[size-1] = 1; //escreve 1 no endereço&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[size-1]==zeros[lugar]) //SE A COBRA ENGOLIR UMA NOVA FRUTA - se o endereço da fruta e da cabeça da cobra forem o mesmo&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(cont==3) {score();score();}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; score();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cresce[cont]=zeros[lugar]; //vetor cresce recebe o endereço da fruta engolida&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cont++; //novo espaço para guardar mais um endereço de fruta engolida&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gerafruta();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; }}//______________________________________________________________________________//FUNÇÃO DOWNvoid down(void){&nbsp;&nbsp;&nbsp; if (headline==7){game_over();reinicia();return;} //se a cobra estiver na borda inferior dá gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline+1][headcol]==1 &amp;&amp; snake[0]!=&amp;matriz[headline+1][headcol]){game_over();reinicia();return;} //se o proximo destino colidir com corpo (menos a cauda) da cobra -&gt; gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline+1][headcol]==1 &amp;&amp; snake[0]==&amp;matriz[headline+1][headcol] &amp;&amp; snake[0]==cresce[0] &amp;&amp; cont&gt;0){game_over();reinicia();return;} //caso particular em que a cobra irá crescer, assim ocorre colisao com a cauda -&gt; gameover&nbsp;&nbsp;&nbsp; //else if (snake[size-2]==&amp;matriz[headline+1][headcol]){} //se a cobra tentar retornar sobre si mesmo a jogada será invalida - Se (proximo local = pescoço da cobra) -&gt; jogada invalida&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; headline++; //desloca uma linha para baixo&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[0]==cresce[0] &amp;&amp; cont&gt;0) //QUANDO A COBRA DEVE CRESCER - quando a fruta engolida estiver no ultimo segmento da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cont--;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cresce[i]=cresce[i+1]; //desloca para a esquerda o vetor de crescimento - para o caso de mais de uma fruta engolida e nao digerida&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else //QUANDO A COBRA NAO PRECISA CRESCER&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[0] = 0; //apaga o ultimo ponto da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[i] = snake[i+1]; //movimenta a cobra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[i] = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[size-1] = &amp;matriz[headline][headcol]; //snake[size-1] recebe o novo endereço da cabeça da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[size-1] = 1; //escreve 1 no endereço&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[size-1]==zeros[lugar]) //SE A COBRA ENGOLIR UMA NOVA FRUTA - se o endereço da fruta e da cabeça da cobra forem o mesmo&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(cont==3) {score();score();}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; score();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cresce[cont]=zeros[lugar]; //vetor cresce recebe o endereço da fruta engolida&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cont++; //novo espaço para guardar mais um endereço de fruta engolida&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gerafruta();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; }}//______________________________________________________________________________//FUNÇÃO LEFTvoid left(void){&nbsp;&nbsp;&nbsp; if (headcol==0){game_over();reinicia();return;} //se a cobra estiver na borda inferior -&gt; gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline][headcol-1]==1 &amp;&amp; snake[0]!=&amp;matriz[headline][headcol-1]){game_over();reinicia();return;} //se o proximo destino colidir com corpo (menos a cauda) da cobra -&gt; gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline][headcol-1]==1 &amp;&amp; snake[0]==&amp;matriz[headline][headcol-1] &amp;&amp; snake[0]==cresce[0] &amp;&amp; cont&gt;0){game_over();reinicia();return;} //caso particular em que a cobra irá crescer, assim ocorre colisao com a cauda -&gt; gameover&nbsp;&nbsp;&nbsp; else if (snake[size-2]==&amp;matriz[headline][headcol-1]){} //se a cobra tentar retornar sobre si mesmo a jogada será invalida - Se (proximo local = pescoço da cobra) -&gt; jogada invalida&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; headcol--; //desloca uma coluna para esquerda&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[0]==cresce[0] &amp;&amp; cont&gt;0) //QUANDO A COBRA DEVE CRESCER - quando a fruta engolida estiver no ultimo segmento da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cont--;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cresce[i]=cresce[i+1]; //desloca para a esquerda o vetor de crescimento - para o caso de mais de uma fruta engolida e nao digerida&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else //QUANDO A COBRA NAO PRECISA CRESCER&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[0] = 0; //apaga o ultimo ponto da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[i] = snake[i+1]; //movimenta a cobra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[i] = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[size-1] = &amp;matriz[headline][headcol]; //snake[size-1] recebe o novo endereço da cabeça da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[size-1] = 1; //escreve 1 no endereço&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[size-1]==zeros[lugar]) //SE A COBRA ENGOLIR UMA NOVA FRUTA - se o endereço da fruta e da cabeça da cobra forem o mesmo&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(cont==3) {score();score();}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; score();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cresce[cont]=zeros[lugar]; //vetor cresce recebe o endereço da fruta engolida&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cont++; //novo espaço para guardar mais um endereço de fruta engolida&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gerafruta();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; }}//______________________________________________________________________________//FUNÇÃO RIGHTvoid right(void){&nbsp;&nbsp;&nbsp; if (headcol==7){game_over();reinicia();return;} //se a cobra estiver na borda inferior dá gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline][headcol+1]==1 &amp;&amp; snake[0]!=&amp;matriz[headline][headcol+1]){game_over();reinicia();return;} //se o proximo destino colidir com corpo (menos a cauda) da cobra -&gt; gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline][headcol+1]==1 &amp;&amp; snake[0]==&amp;matriz[headline][headcol+1] &amp;&amp; snake[0]==cresce[0] &amp;&amp; cont&gt;0){game_over();reinicia();return;} //caso particular em que a cobra irá crescer, assim ocorre colisao com a cauda -&gt; gameover&nbsp;&nbsp;&nbsp; //else if (snake[size-2]==&amp;matriz[headline][headcol+1]){} //se a cobra tentar retornar sobre si mesmo a jogada será invalida - Se (proximo local = pescoço da cobra) -&gt; jogada invalida&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; headcol++; //desloca uma coluna para direita&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[0]==cresce[0] &amp;&amp; cont&gt;0) //QUANDO A COBRA DEVE CRESCER - quando a fruta engolida estiver no ultimo segmento da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cont--;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cresce[i]=cresce[i+1]; //desloca para a esquerda o vetor de crescimento - para o caso de mais de uma fruta engolida e nao digerida&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else //QUANDO A COBRA NAO PRECISA CRESCER&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[0] = 0; //apaga o ultimo ponto da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[i] = snake[i+1]; //movimenta a cobra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[i] = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[size-1] = &amp;matriz[headline][headcol]; //snake[size-1] recebe o novo endereço da cabeça da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[size-1] = 1; //escreve 1 no endereço&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[size-1]==zeros[lugar]) //SE A COBRA ENGOLIR UMA NOVA FRUTA - se o endereço da fruta e da cabeça da cobra forem o mesmo&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(cont==3) {score();score();}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; score();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cresce[cont]=zeros[lugar]; //vetor cresce recebe o endereço da fruta engolida&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cont++; //novo espaço para guardar mais um endereço de fruta engolida&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gerafruta();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; }}//______________________________________________________________________________void setup_MSP(void)//SETUP DO uC{&nbsp; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer to prevent time out reset&nbsp; BCSCTL1 = CALBC1_1MHZ;&nbsp; //ajusta o DCO para 1MHz&nbsp; DCOCTL = CALDCO_1MHZ;&nbsp;&nbsp; //ajusta o DCO para 1MHz&nbsp; &nbsp; P1SEL = 0x00;&nbsp; P1SEL2 = 0x00;&nbsp; P1REN = 0x00; //Desabilita o resistor&nbsp; P1DIR = 0xFF; //Definição de pinos OUT (bit=1 -&gt; output)&nbsp; P1OUT = 0xFF;&nbsp; &nbsp; P2SEL = 0x00;&nbsp; P2SEL2 = 0x00;&nbsp; P2REN = 0x00; //Desabilita o resistor&nbsp; P2DIR = 0xFF; //Definição de pinos OUT (bit=1 -&gt; output)&nbsp; P2OUT = 0xFF;&nbsp; //BOTÕES&nbsp; P2DIR &amp;= ~(BIT3+BIT4+BIT5+BIT6); //4 botões -&gt; INPUT&nbsp; P2REN |= (BIT3+BIT4+BIT5+BIT6); //Habilita os resistores&nbsp; P2OUT &amp;= ~(BIT3+BIT4+BIT5+BIT6); //0=Pull-down / 1=Pull-up&nbsp; P2IE = (BIT3+BIT4+BIT5+BIT6); //habilita a interrupção dos pinos P2.3 P2.4 P2.5 P2.6&nbsp; P2IES = 0; //Interrupção na 0=borda_subida / 1=borda_descida&nbsp; P2IFG = 0; //zera a flag de interrupção//&nbsp; P1IE = 0x0F; //habilita a interrupção dos pinos P1.0 P1.1 P1.2 P1.3//&nbsp; P1IFG = 0; //zera a flag de interrupção}//______________________________________________________________________________void setup_TIMER(void)//Setup do timer{&nbsp; TA0CTL = TASSEL_2 + ID_3 + MC_0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //TASSEL (timer_A clock source select) seleciona a fonte do timer, 2=0x10 que indica SMCLK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //ID (input divider) 0=0x00(/1) &gt; 1=0x01(/2) &gt; 2=0x10(/4) &gt; 3=0x11(/8)&nbsp;&nbsp;&nbsp; --&gt;QUANTO MAIOR O NUMERO MAIS DEMORA PARA CHEGAR NO VALOR MAXIMO (PISCA MAIS LENTO)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //MC (mode control) 0=0x00(stop) &gt; 1=0x01(up) &gt; 2=0x10(continuous) &gt; 3=0x11(up/down)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //UP(periodo diferente de 0xFFFF) conta até o valor armazenado no registrador TACCR0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //e seta a flag CCIFG no registrador TACCTL0 quando atinge o valor de comparação no registrador TACCR0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //e seta a flag TAIFG no registrador TACTL quando o timer passa do valor armazenado no registrador TACCR0 para 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //CONTINUOUS seta flag TAIFG no registrador TACTL quando zera a contagem &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //UP/DOWN timer conta até TACCR0 e depois decrementa até zero (grafico triangular)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //seta flag CCIFG em DOIS MOMENTOS: quando atinge o valor de TACCR0 ou volta para zero&nbsp;&nbsp;&nbsp; &nbsp; TA0CCTL0 = CCIE; //(capture/compare interrupt enable) habilita a interrupção pela flag CCIFG&nbsp; //TA0CCR0 = 0xFFFF;&nbsp; TA0CCTL0 &amp;= ~CCIFG; //limpa flag de interrupção}//______________________________________________________________________________void imprime(void)//FUNÇAO IMPRIME MATRIZ{&nbsp;&nbsp;&nbsp; for (i=0;i<8 br="" i="">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; desligalinhas();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(j=0;j<8 br="" j="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (matriz[i][j]!=0) acende();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else apaga();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(i==0) linha1();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if(i==1) linha2();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if(i==2) linha3();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if(i==3) linha4();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if(i==4) linha5();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if(i==5) linha6();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if(i==6) linha7();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else linha8();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; __delay_cycles(250); &nbsp;&nbsp;&nbsp; }}/*void escrita(void);matriz[i][j] = 1;matriz[i][j] = 1;matriz[i][j] = 1;matriz[i][j] = 1;matriz[i][j] = 1;matriz[i][j] = 1;matriz[i][j] = 1;0x7f, 0x88, 0x88, 0x88, 0x88, 0x7f,&nbsp; // A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0xff, 0x91, 0x91, 0x91, 0x91, 0x6e,&nbsp; // B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0xff, 0x02, 0x04, 0x04, 0x02, 0xff,&nbsp; // W&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0xc3, 0x24, 0x18, 0x18, 0x24, 0xc3,&nbsp; // X&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0xc0, 0x20, 0x1f, 0x1f, 0x20, 0xc0,&nbsp; // Y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0xc3, 0x85, 0x89, 0x91, 0xa1, 0xc3,&nbsp; // Z*///______________________________________________________________________________void main (void) //Programa{&nbsp; &nbsp; setup_MSP();&nbsp; setup_TIMER();&nbsp; reinicia();&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //É POSSIVEL USAR OS COMANDOS ABAIXO NO LUGAR DE time(NULL)&nbsp;&nbsp;&nbsp; //time_t t;&nbsp;&nbsp;&nbsp; //srand((unsigned) time(&amp;t)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //srand( (unsigned)time(NULL) );/*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; srand(time(NULL)) alimenta a função rand com uma semente de tempo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A função time(NULL) é calculado corresponde ao total de segundos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; passados desde 1 de janeiro de 1970 até a data atual.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Desta forma, a cada execução o valor da "semente" será diferente.*/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; __bis_SR_register(GIE); //habilita interrupção&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; TA0CTL |= MC_2; //run timer&nbsp; //TA0CTL &amp;= ~MC_2; //stop timer&nbsp; while(1) imprime();//loop infinito}#pragma vector = PORT2_VECTOR__interrupt void interrupt_botao (void){&nbsp;&nbsp;&nbsp; if (P2IN&amp;0x08 &amp;&amp; movimento!=2) movimento=1; //Define a movimentação da cobra executada pela interrupção do timer&nbsp;&nbsp;&nbsp; else if (P2IN&amp;0x10 &amp;&amp; movimento!=1) movimento=2;&nbsp;&nbsp;&nbsp; else if (P2IN&amp;0x20 &amp;&amp; movimento!=4) movimento=3;&nbsp;&nbsp;&nbsp; else if (P2IN&amp;0x40 &amp;&amp; movimento!=3 &amp;&amp; movimento!=0) movimento=4;&nbsp;&nbsp;&nbsp; P2IFG = 0; //limpa flag de interrupção}#pragma vector = TIMER0_A0_VECTOR__interrupt void interrupt_timer(void){&nbsp; if (movimento==1) up();&nbsp; else if (movimento==2) down();&nbsp; else if (movimento==3) right();&nbsp; else if (movimento==4) left();&nbsp; TA0CCTL0 &amp;= ~CCIFG; //limpa flag de interrupção}<!--8--><!--8--><!--4--><!--8--><!--8--><!--3--><!--16--><!--36--><!--8--><!--8--><!--4--><!--8--><!--8--><!--4--><!--4--><!--4-->