0% found this document useful (0 votes)
43 views2 pages

Manejo de Un LCD 16x2

This document contains code to control a 16x2 LCD display using wiringPi and lcd libraries in C. It defines a pingPong function that moves an asterisk character back and forth across the LCD rows in a ping pong manner. The main function initializes the LCD, displays some test text, calls the pingPong function, clears the LCD and displays a finish message.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views2 pages

Manejo de Un LCD 16x2

This document contains code to control a 16x2 LCD display using wiringPi and lcd libraries in C. It defines a pingPong function that moves an asterisk character back and forth across the LCD rows in a ping pong manner. The main function initializes the LCD, displays some test text, calls the pingPong function, clears the LCD and displays a finish message.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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