mmote.ru/content/other/avr-runline/index.md

68 lines
1.1 KiB
Markdown
Raw Normal View History

2023-01-01 18:21:01 +03:00
---
title: "Бегущая строка"
categories: ["mcu", "archive"]
date: 2016-02-19T00:00:00+03:00
draft: false
featured_image: miniature.jpg
---
<!--more-->
```c
#include <avr/io.h>
#include <string.h>
#include <util/delay.h>
#include "lcd_lib.h"
#define LINE 16
char *str = "Postapokaliptichesky1232323123";
char *pstr;
char buf[LINE + 1];
void lcd_clear() {
LCDsendCommand(0x01);
}
void lcd_zero_coord() {
char y = 0;
char x = 0;
LCDsendCommand(0x80 | ((0x40 * y) + x));
}
void lcd_data(char byte) {
LCDsendChar(byte);
}
void lcd_str(char *s) {
while (*s != '\0') lcd_data(*(s++));
}
int main(void) {
LCDinit();
lcd_clear();
while (1) {
int len = strlen(str) + LINE;
for (int i = 0; i < len; ++i) {
lcd_clear();
lcd_zero_coord();
strcpy(buf, str);
int spaces = LINE - i;
buf[i] = '\0';
pstr = buf;
if (spaces > 0) for (int s = 0; s < spaces; ++s) lcd_data(' ');
else pstr += i - LINE;
lcd_str(pstr);
_delay_ms(100);
}
}
}
```
![|](anim.gif)