/*1.lcd测试*/
#include <stdio.h>      // 包含标准输入输出库函数
#include <stdlib.h>     // 包含标准库函数,如exit()
#include <string.h>     // 包含字符串处理函数
#include <strings.h>    // 包含字符串处理函数(POSIX扩展)
#include <fcntl.h>      // 包含文件控制常量和函数
#include <sys/types.h>  // 包含系统数据类型定义
#include <sys/stat.h>   // 包含文件状态结构和函数
#include <unistd.h>     // 包含Unix标准函数,如read()、write()

int main()
{
    // 打开帧缓冲设备文件,O_RDWR表示以读写模式打开
    int fd = open("/dev/fb0", O_RDWR);
    if(fd < 0)  // 检查文件是否成功打开
    {
        perror("open");  // 输出错误信息
        exit(1);         // 程序异常退出
    }

    // 定义一个数组存储像素数据,假设LCD分辨率为800×480
    int color_buf[800 * 480];
    int i;  // 循环计数器

    // 将屏幕前1/3区域填充为黑色(RGB: 0,0,0)
    for(i = 0; i < 800 * 480 / 3; i++)
    {
        color_buf[i] = 0x00;  // 黑色
    }

    // 将屏幕中间1/3区域填充为红色(RGB: 255,0,0)
    for(; i < 800 * 480 * 2 / 3; i++)
    {
        color_buf[i] = 0x00ff0000;  // 红色(ARGB格式,高位在前)
    }

    // 将屏幕后1/3区域填充为黄色(RGB: 255,255,0)
    for(; i < 800 * 480; i++)
    {
        color_buf[i] = 0x00ffff00;  // 黄色(ARGB格式)
    }

    // 将整个像素缓冲区写入帧缓冲设备,实现图像显示
    write(fd, color_buf, sizeof(color_buf));

    // 关闭帧缓冲设备文件,释放资源
    close(fd);

    return 0;  // 程序正常退出
}

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐