admin管理员组

文章数量:1794759

模块化思想——粤嵌GEC6818读取图片宽度、高度、色深

  • 模块化思想 交叉编译两个c文件的方法:

模块化思想:

代码语言:javascript代码运行次数:0运行复制
。。。
只有一个唯一的main函数‘
一个或者多个功能函数 
main.c
lcd.c   lcd.h
bmp.c   bmp.h
led.c   led.h
beef.c   beef.h
.....



.h怎么写? 
例:led.h

#ifndef  __LED_H__
#define  __LED_H__


// 变量的定义 
// 函数的声明

//。。。

#endif



功能函数: 封装一个函数 
/*
	功能函数:对一个坐标点为(x,y)的像素点上色。
	参数: 
		@x : 像素点的X轴坐标值
		@y :像素点的Y轴坐标值
		@color : 要画的颜色
*/
void draw_point (  int x, int y, int color )
{
	if(x>=0 && x<800 && y>=0 && y<480)
	*(p + 800*y +x ) = 0x00ff0000 ;//p定义成全局变量
}
代码语言:javascript代码运行次数:0运行复制
//lcd.h
#ifndef __LCD_H__
#define __LCD_H__


#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>


extern int *p ;

void init() ;
void end();





#endif
代码语言:javascript代码运行次数:0运行复制
//lcd.c
#include "lcd.h"
int fd = 0;
void init() 
{
	fd = open("/dev/fb0",O_RDWR);
	if(fd==-1)
	{
		perror("open error\n");
		return ;
	}
	
	p = mmap (NULL,800*480*4 ,PROT_READ | PROT_WRITE ,MAP_SHARED , fd , 0);
	if(p == MAP_FAILED)
	{
		perror("mmap error\n");
		return ;
	}
}
void end()
{
	close(fd);
	munmap(p,800*480*4);
}
代码语言:javascript代码运行次数:0运行复制
//main.c
#include "lcd.h"
#include "bmp.h"
int main()
{	
	//init();//打开帧缓冲 映射
	 bmp_inf("./1.bmp");
	//end();//关闭帧缓冲设备文件 解除映射
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2024-10-12,如有侵权请联系 cloudcommunity@tencent 删除include变量编译函数模块化

本文标签: 模块化思想粤嵌GEC6818读取图片宽度高度色深