sexta-feira, 30 de dezembro de 2011

Building the hardware

Hello dear followers, this post is special for us, the last post of the year, and this show the first test with a small program in the hardware, the famous "Hello World", for this we use the MSP430F2013, a 2X16 LCD, an external 9V , a 5V regulator (LM7805), a 10K trimpot for LCD contrast and several jumpers for connecting the protoboard.

Since we will use 4-bit mode, the LCD must be connected only in their last 4 pins (D4, D5, D6 e D7) plus (RS, command and enable).


For this configuration we have the following electric diagram:



In our case we have the LCD backlight controlled by the timer (LM555), but that's a topic for another post.

Montando o hardware

Olá caros seguidores, esse post é especial para nós, o último post do ano, e neste mostraremos um primeiro programinha já testado com hardware, o famoso “Hello World”, para isso usamos o MSP430F2013, um LCD 2X16, uma fonte externa de 9V, um regulador de 5V (LM7805), um trimpot de 10K para o  contraste do LCD e vários jumpers para ligação na protoboard.
Como utilizaremos o modo de 4 bits do LCD devemos ligar apenas seus últimos 4 pinos (D4, D5, D6 e D7), além do (RS, comando e enable).
Para esta configuração temos o seguinte esquema elétrico:




No nosso caso já fizemos o backlight do LCD controlado pelo temporizador (LM555), mas isso já é assunto para outro post.


Feliz 2012 a todos!!!

domingo, 25 de dezembro de 2011

Programming the hardware

Hello dear followers, in this Christmas post we will finish our first program on the board using the hardware MSP430. For this we will use the libraries already created in the last post and now will do our "main.c".

The initial proposal is to print the code on the LCD "Hello world", is quite simple to test if the LCD is alive, so we created a vector of characters, of course do not forget the watchdog before, otherwise he will bark.

Now initialize the LCD, star the infinite loop to print the vector elements and the end command to jump go to the starting position.
So we have :
int main(void)
{
   WDTCTL = WDTPW + WDTHOLD;  // Stop watchdog
  unsigned char i;
  char Vet[12]="Hello World";
  InicializaLCD();   //Configution
  for (;;)   // Start infinite loop
  {
          for(i=0;i<11;i++)
      {
         EnviarDados(Vet[i]);
      }
         EnviarComando(0x80);    //Initial position
  }
}

The code can also be found here.

Running the LCD will show the message this way:


Okay, we already have our program running on the MSP430, the next post will show how to set up the circuit.

sexta-feira, 23 de dezembro de 2011

Hardware libraries

Hi, after a time we come back in this post to develop our hardware libraries of our project with the MSP430F2013.

First we will test the “Hello World” in the LCD, using 4 bits, this will give us some  trouble .
Then we will create a library “basico.h” that it has basic functions for any program that we will use:

// bit functions
#define BitSet (arg, bit) ((arg) |= (1<< bit))
#define BitClr (arg, bit) ((arg) &= ~ (1<< bit))
#define BitFlp (arg, bit) ((arg) ^= (1<< bit))
#define BitTst (arg, bit) ((arg) & (1<< bit))

Now we will create our “lcd.c”, this will make all the operations for functions to facilitate our LCD use.
Starting for delay, for we start the LCD, it needs a time before receiving commands, for this we will create an expend  time, using Loop, minor of 40us and a greater of 2ms, that uses the one of 40us.

In the boot function we configure the direction of the terminals with BitSet, we use the delay, and we send the commands of 4 bits 2 lines, incremental  mode, blink, to erase the display, and to order to the initial position.

To send command we create a function that catches the command of 8 bits, makes bitshift of 4, orders to read 4 and later the others 4. Already
to send data is practically the same thing, only that at  the beginning instead of use BitSet (P1OUT, RS) we use BitClr, that is the data mode.

Finally we have the dumb function that the position of the line, for sends command.
Thus, finally, let us create “lcd.h”:

#ifndef LCD_H
#define LCD_H
void Delay40us (void);
void Delay2ms (void);
void EnviarComando (unsigned to char cmd);
void EnviarDados (unsigned to char value);
void InicializaLCD (void);
void MudaPosicao (unsigned to char lin, unsigned to char col);
#endif

All the libraries can be found in our site
clicking here.
With this, the libraries are read, we will to create the in the next post.

Until soon!

sexta-feira, 16 de dezembro de 2011

Programando o hardware

Olá caros seguidores, nesse post de Natal terminaremos a programação do nosso primeiro programa para embarcarmos no hardware usando o MSP430. Para isso usarmos as bibliotecas já criadas no último post e agora faremos nosso “main.c”.
A proposta inicial é imprimir no LCD o código “Hello world”, é algo bem simples para testarmos se o LCD está vivo, para isso criamos um vetor de caracteres, claro não se esqueça do watchdog antes, senão ele vai latir.
Agora inicializamos o LCD e abrimos o loop infinito para impressão dos elementos do vetor, ao final enviamos comando para ir para a posição inicial.

Assim temos:

int main(void)
{
   WDTCTL = WDTPW + WDTHOLD;  // Interrompe o watchdog

  unsigned char i;
  char Vet[12]="Hello World";

  InicializaLCD();   //Configuração
  for (;;)   // Inicia loop infinito

  {
          for(i=0;i<11;i++)
      {

         EnviarDados(Vet[i]);
      }

         EnviarComando(0x80);    //Posição Inicial
  }

}


O código também pode ser encontrado aqui.


Funcionando na plaquinha a mensagem ficará dessa forma:



  
Pronto, já temos nosso programa montado para rodar no MSP430, no próximo post mostraremos como montar o circuito.


Feliz Natal a todos!

sexta-feira, 9 de dezembro de 2011

Bibliotecas para o hardware


Olá, caros seguidores, após um tempo fora voltamos nesse post para desenvolver nossas bibliotecas para o hardware do nosso projeto com o MSP430F2013.

Primeiramente iremos testar o “Hello World” no LCD, usando 4 bits, isso nos dará um pouco mais de trabalho.

Criaremos, então, uma biblioteca “basico.h” que tem funções básicas para qualquer programa que iremos utilizar:

//funções de bit
#define BitSet(arg,bit) ((arg) |= (1<<bit))
#define BitClr(arg,bit) ((arg) &= ~(1<<bit))
#define BitFlp(arg,bit) ((arg) ^= (1<<bit))
#define BitTst(arg,bit) ((arg) & (1<<bit))



Agora criaremos nossa “lcd.c”, esta fará todas as operações por funções para deixar mais fácil utilizarmos o LCD posteriormente.

Começando pelo delay, para inicializaremos o LCD, ele precisa de um tempo antes de receber comandos, para isso criaremos um gasto de tempo, por loop, menor de 40us e um maior de 2ms, que usa o de 40us.

Na função de inicialização configuramos as direção dos terminais com BitSet, damos o delay, e enviamos os comandos de 4 bits 2 linhas, modo incremental, blink, apagar o display, e mandar para a posição inicial.

Para enviar comando criamos uma função que pega o comando de 8 bits faz o bitshift de 4, manda ler 4 e depois os outros 4. Já para enviar dados é praticamente o mesmo esquema, só que no início ao invés de dar BitSet (P1OUT,RS) damos BitClr, que é o modo dados.

Por fim temos a função que muda a posição da linha, por envia comando.

Assim, por último, criemos a “lcd.h”:

#ifndef LCD_H
                #define LCD_H
                void Delay40us(void);
                void Delay2ms(void);
                void EnviarComando(unsigned char cmd);
                void EnviarDados(unsigned char valor);
                void InicializaLCD(void);
                void MudaPosicao(unsigned char lin, unsigned char col);

#endif

Todas as bibliotecas podem ser encontrada no nosso site clicando aqui.


 Com isso já temos as bibliotecas prontas, o programa iremos criar no próximo post.

Até logo!