#include "avr_compiler.h" #include "lcd.c" void draw_horse(unsigned char p); void create_horse(PGM_P horse); void delay_ms(unsigned int t); /* Patrones de los nuevos caracteres a crearse */ PROGMEM const unsigned char Horse0[] = { 0x00,0x60,0x70,0x78,0x18,0x00,0x70,0x78,0x78,0x78,0x78,0x00,0x70,0x70,0x70,0x7 8, 0x78,0x00,0x7E,0x1E,0x0E,0x3E,0x3F,0x00,0x06,0x03,0x01,0x00,0x38,0x00,0x4F,0x0 7, 0x0F,0x0F,0x0B,0x00,0x13,0x03,0x03,0x3F,0x47,0x00,0x03,0x13,0x0F,0x00,0x00,0x0 0 }; PROGMEM const unsigned char Horse1[] = { 0x40,0x60,0x70,0x70,0x30,0x00,0x70,0x78,0x78,0x78,0x70,0x00,0x70,0x70,0x78,0x7 8, 0x78,0x00,0x7E,0x1E,0x0E,0x3F,0x3E,0x00,0x01,0x00,0x00,0x00,0x38,0x00,0x4F,0x0 7, 0x03,0x0F,0x77,0x00,0x03,0x03,0x03,0x03,0x3F,0x00,0x53,0x0B,0x06,0x00,0x00,0x0 0 }; PROGMEM const unsigned char Horse2[] = { 0x40,0x70,0x78,0x38,0x18,0x00,0x70,0x78,0x78,0x78,0x78,0x00,0x70,0x70,0x70,0x7 8, 0x78,0x00,0x7E,0x3E,0x0E,0x3E,0x3F,0x00,0x07,0x00,0x20,0x1F,0x07,0x00,0x03,0x0 B, 0x1F,0x1F,0x27,0x00,0x49,0x13,0x17,0x1F,0x1F,0x00,0x07,0x0E,0x18,0x20,0x40,0x0 0 }; int main(void) { unsigned char i, h; lcd_init();
// // Inicializar LCD
while(1) { /* Horse desplazándose a la derecha */ for(i=0; i<16; i++) // Para LCD de 2×16 { h = i % 3; // Caballo que corresponde switch (h) { case 0: create_horse((PGM_P)Horse0); break; // Crear caballo 0 case 1: create_horse((PGM_P)Horse1); break; // Crear caballo 1 case 2: create_horse((PGM_P)Horse2); break; // Crear caballo 2 } draw_horse(i); // Dibujar en posición i el caballo recién creado delay_ms(400); } }
} /***************************************************************************** * Dibuja el caballo presente en CGRAM a partir de la columna p. * Cada caballo se forma por 8 caracteres gráficos identificados de 0 a 7. ****************************************************************************/
void draw_horse(unsigned char p) { unsigned char i; lcd_clear(); // Limpiar pantalla y regresar a DDRAM for(i=0; i<8; i++) // 8 piezas por cada caballo { if(i<4) lcd_cmd(LCD_LINE1+p+i); else lcd_cmd(LCD_LINE2+p+i-4); lcd_data(i); } } /****************************************************************************** * Crear los caracteres que componen los caballos. Volcar sus patrones en CGRAM. * Previamente se limpia el LCD para evitar parapadeos. *****************************************************************************/ void create_horse(PGM_P horse) { unsigned char i, j, b, dato; lcd_clear(); lcd_cmd(LCD_CGRAM);
// Limpiar pantalla // Instrucción Set CGRAM Address
for(i=0; i<8; i++) // 8 piezas por caballo { /**************************************************** * Bucle para crear un carácter gráfico. * 6 bytes por pieza, pero se toman los 5 primeros. ***************************************************/ for(b=0; b<8; b++) // 8 bits { dato = 0x00; for(j=0; j<5; j++) { if( pgm_read_byte(horse+6*i+j) & (1<
} void delay_ms(unsigned int t) { while(t--) delay_us(1000); }