模块化思想:
- 。。。
- 只有一个唯一的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();//关闭帧缓冲设备文件 解除映射
- }
-