Ejemplo de uso - Mostrar hora y día
En el siguiente código se genera un main.c que simplemente escribe algo de texto, incluyendo la hora y día actuales de la Raspberry Pi. Si no sabes cómo compilarlo puedes visitar el siguiente tutorial.
Development Environment for the Raspberry Pi using a Cross Compiling Toolchain and Eclipse
#include "bcm2835.h"
#include "lcd_pcd8544.h"
#include "string.h"
#include "stdlib.h"
#include <stdio.h>
#include "time.h"
#include "typedefs.h"
int main(int argc, char **argv)
{
char string[100];
printf("Nokia 5110 Raspberry Pin");
printf("Close with Ctrl+Cn");
// initialize the LCD
Nokia_5110_Init();
Nokia_5110_Set_Cursor(0, 0);
Nokia_5110_Putstring("Nokia 5110 LCD");
Nokia_5110_Set_Cursor(1, 2);
Nokia_5110_Putstring_Inverse("Raspberry Pi");
while(1)
{
time_t t = time((void*)0);
struct tm tm = *localtime(&t);
sprintf(string, " %d-%02d-%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
printf("%sn", string);
Nokia_5110_Set_Cursor(0, 4);
Nokia_5110_Putstring(string);
sprintf(string, " %02d:%02d:%02d",
tm.tm_hour, tm.tm_min, tm.tm_sec);
printf("%sn", string);
Nokia_5110_Set_Cursor(0, 5);
Nokia_5110_Putstring(string);
bcm2835_delay(500);
}
Nokia_5110_Stop_SPI();
return 0;
}
Espero que no se me haya pasado ningún detalle de la conexión ni del código.