![](https://i-blog.csdnimg.cn/direct/659b2ac579a7418bbab7d26e26c05176.png)
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/fb.h>
int main(){
// 1、打开液晶屏
int lcd_fd = open("/dev/fb0",O_RDWR);
if(lcd_fd==-1){
perror("打开液晶屏失败!");
return -1;
}
//2、准备7个颜色
unsigned int red = 0xFF0000;
unsigned int orange = 0xFF8000;
unsigned int yellow = 0xFFFF00;
unsigned int green = 0xFF00;
unsigned int cyan = 0x00FFFF;
unsigned int blue = 0xFF;
unsigned int purple = 0x800080;
// 横刷
for(int y=0;y<68;y++){
for(int x=0;x<800;x++){
write(lcd_fd,&red,sizeof(red));
}
}
for(int y=68;y<136;y++){
for(int x=0;x<800;x++){
write(lcd_fd,&orange,sizeof(orange));
}
}
for(int y=136;y<204;y++){
for(int x=0;x<800;x++){
write(lcd_fd,&yellow,sizeof(yellow));
}
}
for(int y=204;y<272;y++){
for(int x=0;x<800;x++){
write(lcd_fd,&green,sizeof(green));
}
}
for(int y=272;y<340;y++){
for(int x=0;x<800;x++){
write(lcd_fd,&cyan,sizeof(cyan));
}
}
for(int y=340;y<408;y++){
for(int x=0;x<800;x++){
write(lcd_fd,&blue,sizeof(blue));
}
}
for(int y=408;y<480;y++){
for(int x=0;x<800;x++){
write(lcd_fd,&purple,sizeof(purple));
}
}
// 关闭液晶屏
close(lcd_fd);
return 0;
}
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/fb.h>
int main()
{
// 1、打开液晶屏
int lcd_fd = open("/dev/fb0", O_RDWR);
if (lcd_fd == -1)
{
perror("打开液晶屏失败!");
return -1;
}
// 2、准备7个颜色
unsigned int red = 0xFF0000;
unsigned int orange = 0xFF8000;
unsigned int yellow = 0xFFFF00;
unsigned int green = 0xFF00;
unsigned int cyan = 0x00FFFF;
unsigned int blue = 0xFF;
unsigned int purple = 0x800080;
// 竖刷
for (int y = 0; y < 480; ++y)
{
for (int x = 0; x < 114; ++x)
{
write(lcd_fd, &red, sizeof(red));
}
for (int x = 114; x < 228; ++x)
{
write(lcd_fd, &orange, sizeof(orange));
}
for (int x = 228; x < 342; ++x)
{
write(lcd_fd, &yellow, sizeof(yellow));
}
for (int x = 342; x < 456; ++x)
{
write(lcd_fd, &green, sizeof(green));
}
for (int x = 456; x < 570; ++x)
{
write(lcd_fd, &cyan, sizeof(cyan));
}
for (int x = 570; x < 684; ++x)
{
write(lcd_fd, &blue, sizeof(blue));
}
for (int x = 684; x < 800; ++x)
{
write(lcd_fd, &purple, sizeof(purple));
}
}
// 关闭液晶屏
close(lcd_fd);
return 0;
}