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!

Nenhum comentário:

Postar um comentário