2025年2月25日 星期二 甲辰(龙)年 腊月廿五 设为首页 加入收藏
rss
您当前的位置:首页 > 电子 > 嵌入式系统

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

时间:03-12来源:作者:点击数:42
  • 模块化思想
    交叉编译两个c文件的方法:
    在这里插入图片描述

模块化思想:

  • 。。。
  • 只有一个唯一的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定义成全局变量
  • }
  • //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
  • //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);
  • }
  • //main.c
  • #include "lcd.h"
  • #include "bmp.h"
  • int main()
  • {
  • //init();//打开帧缓冲 映射
  • bmp_inf("./1.bmp");
  • //end();//关闭帧缓冲设备文件 解除映射
  • }
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门