使用c语言让LCD1608循环显示 "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
时间: 2023-06-29 18:15:11 浏览: 34
以下是使用C语言让LCD1608循环显示 "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" 的代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wiringPi.h>
#include <lcd.h>
#define LCD_RS 3 // Register select pin
#define LCD_E 0 // Enable Pin
#define LCD_D4 6 // Data pin 4
#define LCD_D5 1 // Data pin 5
#define LCD_D6 5 // Data pin 6
#define LCD_D7 4 // Data pin 7
int main()
{
int lcd;
char days[7][4] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
int i = 0;
// Initialize wiringPi and LCD
wiringPiSetup();
lcd = lcdInit(2, 16, 4, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, 0, 0, 0, 0);
// Loop through the days array and display each day on the LCD
while(1)
{
lcdClear(lcd);
lcdPosition(lcd, 0, 0);
lcdPuts(lcd, days[i]);
i = (i + 1) % 7;
sleep(1); // Wait for 1 second before displaying the next day
}
return 0;
}
```
这段代码使用了 wiringPi 库和 lcd 库来控制树莓派上的 LCD1608 显示屏。我们首先定义了 LCD 的引脚,然后初始化了 wiringPi 和 LCD,之后使用一个死循环来循环显示每个星期的日期。我们使用一个字符串数组来存储日期,然后使用 lcdPosition 和 lcdPuts 函数来在 LCD 上显示日期。最后,我们使用 sleep 函数来等待 1 秒钟,然后再显示下一个日期。