Estoy tratando de desplazar un texto en la primera fila de una pantalla LCD de 16x2 usando PIC16F688 (Usando el compilador MikroC). Por el momento, quiero hacer una función que ingrese un texto y lo desplace de derecha a izquierda, como si el primer carácter apareciera a la derecha y cuando entrara el siguiente carácter, el último se moviera una columna a la izquierda. ¿Es posible hacer esto como una función general (método) que calcula automáticamente el número de caracteres? Si fuera C# o algo más, sabría que es posible hacerlo con la función STRLEN. Pero, ¿qué hay de hacer esto en PIC:
void leftScroll(char text[])
{
int chars = strlen(text); //get number of characters in given text
char number[] = chars; // store number of charcters
Lcd_Out(1,1, chars); //show number of characters (DEBUG)
}
¡Cualquier sugerencia sería agradable!
Aquí está mi programa hasta ahora. Esto desplaza el texto de derecha a izquierda. Pero quiero que mi mensaje comience desde la izquierda y carácter por carácter.
// LCD module connections
sbit LCD_RS at RC4_bit;
sbit LCD_EN at RC5_bit;
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
// End LCD module connections
char Message1[] = "Sean Walter"; //Top line message
char Message2[] = "Welcome to my LCD project!";
char i;
void main()
{
ANSEL = 0b00000100; // RA2/AN2 is analog input
ADCON0 = 0b00001000; // Analog channel select @ AN2
ADCON1 = 0x00;
CMCON0 = 0x07 ; // Disbale comparators
TRISC = 0b00000000; // PORTC All Outputs
TRISA = 0b00001100; // PORTA All Outputs, Except RA3 and RA2
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,Message1);
Lcd_Out(2,1, Message2);
do
{
delay_ms(50);
for(i=0; i<2; i++) { // Move text to the right 4 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
}
delay_ms(50);
}
while(1);
}
La forma más sencilla de obtener un efecto de desplazamiento es tratar el texto de entrada como un búfer circular. Mantenga un puntero de lectura, que se incrementa cada vez que renderiza. Para representar, lea una ventana de texto que se extiende desde el puntero de lectura.
Si desea un desplazamiento tipo serpiente para su pantalla de 16x2, extienda el ejemplo a continuación para mostrar una ventana de 32 caracteres o dos ventanas de 16 caracteres (la pantalla de 16x2 que tengo en realidad tiene varios bytes de almacenamiento fuera de la pantalla, lo que significa que una ventana simple de 32 bytes puede no funciona para usted).
#include <stdio.h>
#include <string.h>
// Get text[offset] if text were an infinitely long repeating loop
char getLoopChar(const char *text, int offset)
{
return text[offset % strlen(text)];
}
int main(int argc, char *argv[])
{
const char *text = "This is a scrolling message...";
int window_start = 0;
while(1)
{
int i;
for (i=0;i<16;i++) // loop over characters in the window
putchar(getLoopChar(text, window_start+i));
putchar('\n');
window_start++;
}
return 0;
}
Sean87
toby jaffey
Sean87
abdullah kahraman
putchar('\n');
aquí.toby jaffey