开发板的使用之屏幕操作

目录

一、显示屏显示颜色

操作步骤:

例1:全屏显示红色

例2:横屏显示三色

例3:竖屏显示三色

一、显示屏显示颜色

一个屏幕是800*480个像素

是将准备好的颜色数据写入到显示屏的设备中(/dev/fb0),由操作系统利用文件控制显示屏硬件

操作步骤:

1.准备800*480个像素点颜色数据

2.打开显色屏设备文件

参数: 

        Pathname:打开文件的路径名

        flags:权限

                O_RDONLY:只读

                O_WRONLY:只写

                O_RDWR:可读可写

返回值

        成功:文件对应的文件描述符

        失败:-1

 查看函数的使用方法:man 2 函数名

3.将颜色数据写入设备文件

参数

        fd:要写入数据的文件描述符

        buf:要写入数据的缓冲去(泛型指针)

        count:要写入的字节数

返回值

        成功:正确写入的字节数

        失败: 

4.关闭设备文件

close()

例1:全屏显示红色

代码:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc,char **argv)
{
	/*1.准备颜色 */
	int color[800*480];	
	for(int i=0;i<800*480;i++)
		color[i]= 0xff0000;//红色数据
	/*2.打开设备 */
	int fd = open("/dev/fb0",O_WRONLY);
	if(-1==fd)
	{
		printf("文件打开失败");
		return -1;
	}
	/*3.将颜色数据写入设备文件*/
	int ret=write(fd,color,800*480*4);//每个元素占4个字节
	if(-1==ret)
	{
		printf("文件写入失败");
		return -2;
	}
	/*4.关闭设备文件*/
	close(fd);
	return 0;
}

再ubuntu上编译:

 在securecrt上编译传到开发板上:

开发板上就显示了红色

例2:横屏显示三色

代码:

方法一:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc,char **argv)
{
	/*1.准备颜色 */
	int color[480][800];
	int i,j;
	//循环屏幕的第一块颜色的每一行
	for(i=0;i<160;i++)
	{
		for(j=0;j<800;j++)//循环每一列
		{
			color[i][j]=0x00ff0000;
		}			
	}
	//循环屏幕的第二块颜色的每一行
	for(i=161;i<320;i++)
	{
		for(j=0;j<800;j++)
		{
			color[i][j]=0x0000ff00;
		}			
	}
	//循环屏幕的第三块颜色的每一行
	for(i=321;i<480;i++)
	{
		for(j=0;j<800;j++)
		{
			color[i][j]=0x000000ff;
		}			
	} 

	/*2.打开设备 */
	int fd = open("/dev/fb0",O_WRONLY);
	if(-1==fd)
	{
		printf("文件打开失败");
		return -1;
	}
	/*3.将颜色数据写入设备文件*/
	int ret=write(fd,color,800*480*4);//每个元素占4个字节
	if(-1==ret)
	{
		printf("文件写入失败");
		return -2;
	}
	/*4.关闭设备文件*/
	close(fd);
	return 0;
}

 方法二:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc,char **argv)
{
	/*1.准备颜色 */
	/*****方法二****/
	int color[800*480];
	int i = 0;
	for(;i<800*160;i++)
		color[i] = 0xff0000;//显示红色
	for(;i<800*320;i++)
		color[i] = 0xff00;//显示绿色
	for(;i<800*480;i++)
		color[i] = 0xff;//显示蓝色
	
	/*2.打开设备 */
	int fd = open("/dev/fb0",O_WRONLY);
	if(-1==fd)
	{
		printf("文件打开失败");
		return -1;
	}
	/*3.将颜色数据写入设备文件*/
	int ret=write(fd,color,800*480*4);//每个元素占4个字节
	if(-1==ret)
	{
		printf("文件写入失败");
		return -2;
	}
	/*4.关闭设备文件*/
	close(fd);
	return 0;
}

结果如图:

例3:竖屏显示三色

 代码:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc,char **argv)
{
	/*1.准备颜色 */
	int color[800*480];
	for(int i=0;i<800*480;i++)
	{
		int tmp = i%800;
		if(tmp<200)
			color[i] = 0xff0000;//显示红色
		else if(tmp<500)
			color[i] = 0xff00;//显示绿色
		else
			color[i] = 0xff;//显示蓝色
			
	}
	
	/*2.打开设备 */
	int fd = open("/dev/fb0",O_WRONLY);
	if(-1==fd)
	{
		printf("文件打开失败");
		return -1;
	}
	/*3.将颜色数据写入设备文件*/
	int ret=write(fd,color,800*480*4);//每个元素占4个字节
	if(-1==ret)
	{
		printf("文件写入失败");
		return -2;
	}
	/*4.关闭设备文件*/
	close(fd);
	return 0;
}

结果显示:

二、使用rz上传文件

1.利用rx将rz上传开发板

2.修改rz的执行权限  chmod u+x rz

3.将rz移到【/bin]  mv rz /bin

4.将需要上传的文件直接拖到CRT界面

5.松开鼠标之后,选择【发送Zmodel]

  • 5
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

想敲代码的羊羊羊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值