Étape 4: Comment les personnages animés sur l’écran
Animate.c
Cette image est plutôt ennuyeuse. Mais regardez la vidéo plus tard dans ce post.
Animate.c exemple montre les fonctions animateLeft() et animateRight().
J’ai voulu pimenter la tâche d’écriture de texte dans des affichages.
À l’aide de commandes de hd44780_set_cursorPosition() de fonction, l’incrémentation/décrémentation, MoveLeft et MoveRight, vous pouvez faire une animation de texte plutôt sympa.
Laissez-nous examiner le code et voir comment nous pouvons accomplir cette tâche.
#include #include "hd44780_4bit_lib.h" #include /* * This code example writes text to the screen using the * Cursor Increment, Decrement and Cursor Left and Right * commands, along with some functions that anaimate the * printing of characters to the display * I was going to use timer events for the character * wait time, but I wanted the code to be non CPU specific. */void main() { WDTCTL = WDTPW | WDTHOLD; // Disable watchdog timer // according to spec give the display 10ms to come up to voltage __delay_cycles(10000 * CPUSPEED); // set up data length, number of lines and font // notice we have setup the display for 2 lines //and using the 5 x 8 character size hd44780_init(N_2LINE, FONT_8); // if needed set up the cursor // hd44780_send_command(HD44780_CMD_DISPLAY_ON_CURSOR); // hd44780_send_command(HD44780_CMD_DISPLAY_ON_CURSOR_BLINK); hd44780_send_command(HD44780_CMD_INCREMENT); hd44780_send_command(HD44780_CMD_MOVE_CURSOR_RIGHT); hd44780_setCursorPosition(0, 0); // The anaimate functions take three parameters: // The text string to print // The visible width of the display in characters // The justification, 'L' for Left justification // 'C' for centered text // 'R' for right jusificatiopn // The number of clock cycles you want to wait after // each character is printed hd44780_animateRight("This is Right", 20, 'C', 2500); hd44780_send_command(HD44780_CMD_DECREMENT); hd44780_send_command(HD44780_CMD_MOVE_CURSOR_LEFT); hd44780_setCursorPosition(1, 19); hd44780_animateLeft("This is Left", 20, 'C', 2500); hd44780_send_command(HD44780_CMD_INCREMENT); hd44780_send_command(HD44780_CMD_MOVE_CURSOR_RIGHT); hd44780_send_command(HD44780_CMD_RETURN_HOME); }
Prenons le code et l’examen article par article :
hd44780_setCursorPosition(0, 0); // The anaimate functions take three parameters: // The text string to print // The visible width of the display in characters // The justification, 'L' for Left justification // 'C' for centered text // 'R' for right jusificatiopn // The number of clock cycles you want to wait after // each character is printed hd44780_animateRight("This is Right", 20, 'C', 2500);
Tout d’abord, nous avons mis le compteur d’adresse AC pour incrémenter le texte, puis nous avons mis en place l’écran pour déplacer le curseur vers la droite.
Ensuite, nous avons mis la position du curseur à la ligne 0, colonne 0.
Nous appelons ensuite la fonction hd44780_animateRight().
Notez que nous devons passer quelques arguments de cette méthode.
Le texte que vous souhaitez imprimer à l’écran
La largeur apparente de ligne à l’écran, sur ma ligne d’affichage on est partagé entre deux 20 lignes sur l’écran.
Ensuite, nous spécifions la justification du texte à l’écran. « L » pour la justification gauche, « C » pour centre justification et « R » pour justification droite.
Vous devez également entrer un micro seconde temps de pause, ce paramètre spécifie le temps de pause après que chaque caractère est imprimé à l’écran. En changeant ce paramètre, vous pouvez accélérer ou ralentir l’animation des personnages en cours d’impression à l’écran.
Appeler la fonction hd44780_animateRight() sera ensuite imprimer la chaîne de texte à l’écran.
hd44780_send_command(HD44780_CMD_DECREMENT); hd44780_send_command(HD44780_CMD_MOVE_CURSOR_LEFT); hd44780_setCursorPosition(1, 19); hd44780_animateLeft("This is Left", 20, 'C', 2500); hd44780_send_command(HD44780_CMD_INCREMENT); hd44780_send_command(HD44780_CMD_MOVE_CURSOR_RIGHT); hd44780_send_command(HD44780_CMD_RETURN_HOME);
De même, nous pouvons alors changer l’AC, adresse à l’encontre de décrémenter la position du curseur et déplace les caractères vers la gauche.
Maintenant, nous avons mis la position du curseur à la ligne 1 et colonne 19, dernier caractère de la première ligne. N’oubliez pas l’écran est de base zéro. Commence à compter de 0 au lieu de cela, si 1.
Nous appelons ensuite hd44780_animateLeft() pour animer les caractères vers la gauche.
Ces échantillons de codage sont juste un exemple de base de ce que vous pouvez faire avec l’interface de contrôleur hd44780.
Si je viens avec plus d’ajouts à la bibliothèque, que je vais les ajouter que tout tout le monde a fait savoir dans un nouveau poste.