Manejo de Un LCD 16x2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Manejo

 de  un  LCD  16x2  


 

 
#include <wiringPi.h>
#include <lcd.h>

#include <stdio.h>
#include <stdlib.h>
//#include <stdint.h>

#ifndef TRUE
# define TRUE (1==1)
# define FALSE (1==2)
#endif

static void waitForEnter (void) {


printf ("Press ENTER to continue: ") ;
(void)fgetc (stdin) ;
}

void pingPong (int lcd, int cols, int repeat) {


int position = 0 ;
int dir = 0 ;
int i;

for(i=0; i<repeat*cols; i++){

if (dir == 0) {
dir = 1 ;
lcdPosition (lcd, 0, 0) ;
lcdPutchar (lcd, '*') ;
lcdPosition (lcd, cols-1, 1) ;
lcdPutchar (lcd, '*') ;
//return ;
}

lcdPosition (lcd, position, 0) ;


lcdPutchar (lcd, ' ') ;

lcdPosition (lcd, (cols-1)-position, 1) ;


lcdPutchar (lcd, ' ') ;

position += dir ;

if (position == cols) {
dir = -1 ;
--position ;
}

if (position < 0) {
dir = 1 ;
++position ;
}

lcdPosition (lcd, position, 0) ;


lcdPutchar (lcd, '*') ;

lcdPosition (lcd, (cols-1)-position, 1) ;


lcdPutchar (lcd, '*') ;
delay(200);

}
}

int main(){
int fd;
// (rows, cols, mode, RS, STR, d0, d1, d2, d3, d4, d5, d6, d7)
fd = lcdInit (2, 16, 4, 11, 10, 4, 5, 6, 7, 0, 0, 0, 0) ;

if (fd < 0) {
fprintf (stderr, "lcdInit failed\n") ;
exit(EXIT_FAILURE) ;
}

wiringPiSetup () ;
lcdClear(fd);
lcdHome(fd);
lcdCursor(fd, FALSE);

lcdPosition (fd, 0, 0) ; lcdPuts (fd, "Prueba") ;


lcdPosition (fd, 0, 1) ; lcdPuts (fd, " Errgabo 2014 :)") ;

waitForEnter();

lcdClear(fd);

pingPong(fd, 16,4);

lcdClear(fd);

lcdPosition (fd, 0, 0) ; lcdPuts (fd, "======FIN======") ;


return(EXIT_SUCCESS);
}
 

You might also like