该代码通过二维数组实现图案,存在画面延迟,建议通过映射实现图案。
通过Linux平台用终端命令进行交叉编译(arm-linux-gcc)后,在开发板中运行程序即可。
代码如下:
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
//长宽——宽
#define L_wide 40
#define W_wide 40
//屏幕参数
#define ICTwide 480
#define ICTlength 800
//矩形参数
#define Orth_wide 240
#define Orth_length 400
//颜色设置
#define LCT_Color 0x7cfc00
#define Orth_Color 0xb23aee
#define Background_color 0xffffff;
//边差值
#define W_Dvalue (ICTwide-W_wide) //440
#define L_Dvalue (ICTlength-L_wide) //760
//矩形差值
#define Orth_W_Dvalue0 ((ICTwide-Orth_wide)/2) //120
#define Orth_L_Dvalue0 ((ICTlength-Orth_length)/2) //200
#define Orth_W_Dvalue1 ((ICTwide-Orth_W_Dvalue0)) //360
#define Orth_L_Dvalue1 ((ICTlength-Orth_L_Dvalue0)) //600
int main()
{
//1.打开lcd屏幕
int lcd_fd = open("/dev/fb0",O_RDWR);
if (lcd_fd == -1)
{
perror("open lcd fail");
}
//写入颜色
int color[ICTwide][ICTlength];
for(int i = 0; i < ICTwide;i++)
{
for(int j = 0;j < ICTlength;j++)
{
//底色
color[i][j]=Background_color;
//边框设置
//长
if((i>=0&&i<W_wide)&&(j<ICTlength))
{
color[i][j]=LCT_Color;
}
if((i>=W_Dvalue&&i<ICTwide)&&(j<ICTlength))
{
color[i][j]=LCT_Color;
}
//宽
if((i<ICTwide)&&(j>=0&&j<L_wide))
{
color[i][j]=LCT_Color;
}
if((i<ICTwide)&&(j>=L_Dvalue&&j<ICTlength))
{
color[i][j]=LCT_Color;
}
//矩形
if((i>=Orth_W_Dvalue0)&&(i<Orth_W_Dvalue1)&&(j>=Orth_L_Dvalue0)&&(j<Orth_L_Dvalue1))
{
color[i][j]=Orth_Color;
}
}
}
write(lcd_fd,color,ICTlength*ICTwide*4);
//关闭lcd
close(lcd_fd);
return 0;
}
样图如下: