ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

粤嵌gec6818开发板LED屏幕上画图(数组与内存映射的采用)

2021-11-17 21:04:30  阅读:1403  来源: 互联网

标签:draw LED int 开发板 color fc gec6818 && include


交叉开发
    在一个有编辑/编译功能的PC机上进行编辑/编译,生成的可执行文件通过
    交叉开发工具下载到目标机(GEC-6818)
    
    开发板 --- Linux内核 --- Linux指令
    首先创建自己的工作目录
    
    mkdir xxx
    
    下载交叉编译生成的可执行文件:
        rx 可执行文件名
        传输 --- 发送xmodem --- 浏览到我们所要发送的文件 --- 选中 --- 发送
        如果发送的是一个可执行文件,没有可执行的权限
            chmod +x 可执行文件名  --- 再去运行
        !!! 下载可执行文件必须是交叉编译生成的
        arm-linux-gcc 源文件名 -o 可执行文件名    

2 屏幕操作
    屏幕分辨率:800*480
    800 一行有800个像素点 480行
    像素点:显示颜色的最小单位
    颜色:ARGB --- 每个分量一个字节 
        A:透明度
        R:红色分量 0 - ff
        G:绿色分量
        B:蓝色分量
                
        绿色:0x0000ff00        
                
    如果我们想要绿屏:
        每个像素点全部显示绿色:0x0000ff00
        
    打开屏幕
        int lcd_fd = open("/dev/fb0",O_RDWR);
        if(lcd_fd == -1)
        {
            perror("open lcd fail");
            return -1;
        }
    操作屏幕
        //写入数据
        int color[800*480]={0};
        for(int i=0;i<480;i++)
        {
            for(int j=0;j<800;j++)
            {
                color[i*800+j]=0x0000ff00;
            }
        }
        write(lcd_fd,color,800*480*4);
    关闭屏幕
        close(lcd_fd);

因为引用了 #include<math.h> 

切记 切记 Liunx 编译时 要加 -lm

类似 arm-linux-gcc 1.c -lm

画太极图

#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include <sys/mman.h>
#include<unistd.h>
#include<math.h> 
int *plcd = NULL;
#define WHITE 0x00FFFFFF 
#define BLAK 0x00000000 
void draw_point(int x, int y, int color)
{
	if (x >= 0 && x<800 && y >= 0 && y<480)
	{
		*(plcd + y * 800 + x) = color;
	
	}
}

void draw_circle(int x, int y,double r ,int color)
{
	if (x >= 0 && x<480 && y >= 0 && y<800)
	{
		for (double i = 0; i < 480; i++)
    {
		for (double j = 0; j < 800; j++)
			{
				double all=(i-x)*(i-x)+(j-y)*(j-y);
				double fc=sqrt(all);
				if(r>fc)
				{
						draw_point(j, i, color);
					//	printf("fc=%lf\n",fc);
				}
			}
	}
	
	}
}

void draw_circle_b(int x, int y,double r ,int color)
{
	if (x >= 0 && x<480 && y >= 0 && y<800)
	{
		for (double i = 0; i < 480; i++)
    {
		for (double j = 0; j < 800; j++)
			{
				if(i<x){
					double all=(i-x)*(i-x)+(j-y)*(j-y);
					double fc=sqrt(all);
					if(r>fc)
					{
						draw_point(j, i, color);
					//	printf("fc=%lf\n",fc);
					}					
				}
			}
	}
	
	}
}

void clear(int color)
{
	int x,y;
	for(y=0;y<480;y++)
	{
		for(x=0;x<800;x++)
		{
			draw_point(x,y,color);
		}
	}
}

int main()
{
	int lcd_fd = open("/dev/fb0",O_RDWR);
	if (lcd_fd == -1)
	{
		perror("open lcd fail");
	}
	plcd = mmap(NULL, 800 * 480 * 4, PROT_READ | PROT_WRITE, MAP_SHARED,lcd_fd,0);
	if (plcd==NULL)
	{
		perror("mmao  fail");
	}
	int color = 0x0000FFFF;
	
    clear(0x00666666);
	draw_circle(240, 400,200, BLAK);
	draw_circle_b(240, 400,200, WHITE);
    draw_circle(240, 300,100, WHITE); 
    draw_circle(240, 500,100, BLAK); 
    draw_circle(240, 300,25, BLAK); 
    draw_circle(240, 500,25, WHITE); 

//	draw_circle(240, 400,50, color);  
	close(lcd_fd);
	munmap(plcd,800*480*4);
	return 0;
}





画笑脸

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

#define WHITE 0x00FFFFFF 
#define BLAK 0x00000000 
#define org 0x00CDAD00
#define gray 0x00CD853F 

int *plcd = NULL;  

void draw_point(int x, int y, int color)
{
	if (x >= 0 && x<800 && y >= 0 && y<480)
	{
		*(plcd + y * 800 + x) = color;
	
	}
}

void draw_circle(int x, int y,double r ,int color)//HUAYUAN
{
	if (x >= 0 && x<480 && y >= 0 && y<800)
	{
		for (double i = 0; i < 480; i++)
    {
		for (double j = 0; j < 800; j++)
			{
				double all=(i-x)*(i-x)+(j-y)*(j-y);
				double fc=sqrt(all);
				if(r>fc)
				{
						draw_point(j, i, color);
					//	printf("fc=%lf\n",fc);
				}
			}
	}
	
	}
}

void draw_circle_b(int x, int y,double r ,int color)//BANYUAN
{
	if (x >= 0 && x<480 && y >= 0 && y<800)
	{
		for (double i = 0; i < 480; i++)
    {
		for (double j = 0; j < 800; j++)
			{
				if(i<x){
					double all=(i-x)*(i-x)+(j-y)*(j-y);
					double fc=sqrt(all);
					if(r>fc)
					{
						draw_point(j, i, color);
					//	printf("fc=%lf\n",fc);
					}					
				}
			}
	}
	
	}
}

void draw_circle_c(int x, int y,double r ,int color)//BANYUAN
{
	if (x >= 0 && x<480 && y >= 0 && y<800)
	{
		for (double i = 0; i < 480; i++)
    {
		for (double j = 0; j < 800; j++)
			{
				if(i>x){
					double all=(i-x)*(i-x)+(j-y)*(j-y);
					double fc=sqrt(all);
					if(r>fc)
					{
						draw_point(j, i, color);
					//	printf("fc=%lf\n",fc);
					}					
				}
			}
	}
	
	}
}

void clear(int color)
{
	int x,y;
	for(y=0;y<480;y++)
	{
		for(x=0;x<800;x++)
		{
			draw_point(x,y,color);
		}
	}
}


int main()
{
	int lcd_fd = open("/dev/fb0",O_RDWR);
	if (lcd_fd == -1)
	{
		perror("open lcd fail");
	}
	plcd = mmap(NULL, 800 * 480 * 4, PROT_READ | PROT_WRITE, MAP_SHARED,lcd_fd,0);
	if (plcd==NULL)
	{
		perror("mmap  fail");
	}
	int color = 0x0000FFFF;
	
    clear(0x00666666);
	draw_circle(240, 400,200, org);//画橙底 
	
	//draw_circle(180, 480,30, HUI);//眼睛1 
    //draw_circle(180, 320,30, HUI); //眼睛2 
    
    draw_circle_b(170, 300,50, gray); 
     draw_circle_b(170, 300,40, org);
     
     draw_circle_b(170, 500,50, gray); 
     draw_circle_b(170, 500,40, org);
	  
    //draw_circle(240, 300,25, BLAK); 
    //draw_circle(240, 500,25, WHITE); 
    draw_circle_c(250, 400,150, WHITE);
  
//	draw_circle(240, 400,50, color);  
  int x,y;
	for(y=0;y<480;y++)
	{
		for(x=0;x<800;x++)
		{
			if (x >=400 && x<402 && y >=250 && y<400 )
			draw_point(x,y,BLAK);
			if (x >=300 && x<302 && y >=250 && y<362 )
			draw_point(x,y,BLAK);
			if (x >=500 && x<502 && y >=250 && y<362 )
			draw_point(x,y,BLAK);
		}
	}
	close(lcd_fd);
	munmap(plcd,800*480*4);
	return 0;
}




画微笑

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

#define WHITE 0x00FFFFFF 
#define BLAK 0x00000000 
#define org 0x00CDAD00
#define HUI 0x00CD853F 

int *plcd = NULL;  

void draw_point(int x, int y, int color)
{
	if (x >= 0 && x<800 && y >= 0 && y<480)
	{
		*(plcd + y * 800 + x) = color;
	
	}
}

void draw_circle(int x, int y,double r ,int color)//HUAYUAN
{
	if (x >= 0 && x<480 && y >= 0 && y<800)
	{
		for (double i = 0; i < 480; i++)
    {
		for (double j = 0; j < 800; j++)
			{
				double all=(i-x)*(i-x)+(j-y)*(j-y);
				double fc=sqrt(all);
				if(r>fc)
				{
						draw_point(j, i, color);
					//	printf("fc=%lf\n",fc);
				}
			}
	}
	
	}
}

void draw_circle_b(int x, int y,double r ,int color)//BANYUAN
{
	if (x >= 0 && x<480 && y >= 0 && y<800)
	{
		for (double i = 0; i < 480; i++)
    {
		for (double j = 0; j < 800; j++)
			{
				if(i>x){
					double all=(i-x)*(i-x)+(j-y)*(j-y);
					double fc=sqrt(all);
					if(r>fc)
					{
						draw_point(j, i, color);
					//	printf("fc=%lf\n",fc);
					}					
				}
			}
	}
	
	}
}

void clear(int color)
{
	int x,y;
	for(y=0;y<480;y++)
	{
		for(x=0;x<800;x++)
		{
			draw_point(x,y,color);
		}
	}
}

int main()
{
	int lcd_fd = open("/dev/fb0",O_RDWR);
	if (lcd_fd == -1)
	{
		perror("open lcd fail");
	}
	plcd = mmap(NULL, 800 * 480 * 4, PROT_READ | PROT_WRITE, MAP_SHARED,lcd_fd,0);
	if (plcd==NULL)
	{
		perror("mmao  fail");
	}
	int color = 0x0000FFFF;
	
    clear(0x00666666);
	draw_circle(240, 400,200, org);//画橙底 
	
	draw_circle(180, 480,30, HUI);//眼睛1 
    draw_circle(180, 320,30, HUI); //眼睛2 
    
    draw_circle_b(270, 400,50, HUI); 
     draw_circle_b(270, 400,40, org); 
    //draw_circle(240, 300,25, BLAK); 
    //draw_circle(240, 500,25, WHITE); 

//	draw_circle(240, 400,50, color);  
	close(lcd_fd);
	munmap(plcd,800*480*4);
	return 0;
}





 四叶草 彩虹

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

#define WHITE 0x00FFFFFF 
#define BLAK 0x00000000 
#define org 0x00CDAD00
#define HUI 0x00CD853F 

int *plcd = NULL;  

void draw_point(int x, int y, int color)
{
	if (x >= 0 && x<800 && y >= 0 && y<480)
	{
		*(plcd + y * 800 + x) = color;
	
	}
}

void draw_circle(int x, int y,double r ,int color)//HUAYUAN
{
	if (x >= 0 && x<480 && y >= 0 && y<800)
	{
		for (double i = 0; i < 480; i++)
    {
		for (double j = 0; j < 800; j++)
			{
				double all=(i-x)*(i-x)+(j-y)*(j-y);
				double fc=sqrt(all);
				if(r>fc)
				{
						draw_point(j, i, color);
					//	printf("fc=%lf\n",fc);
				}
			}
	}
	
	}
}

void draw_circle_b(int x, int y,double r ,int color)//BANYUAN
{
	if (x >= 0 && x<480 && y >= 0 && y<800)
	{
		for (double i = 0; i < 480; i++)
    {
		for (double j = 0; j < 800; j++)
			{
				if(i>x){
					double all=(i-x)*(i-x)+(j-y)*(j-y);
					double fc=sqrt(all);
					if(r>fc)
					{
						draw_point(j, i, color);
					//	printf("fc=%lf\n",fc);
					}					
				}
			}
	}
	
	}
}

void clear(int color)
{
	int x,y;
	for(y=0;y<480;y++)
	{
		for(x=0;x<800;x++)
		{
			draw_point(x,y,color);
		}
	}
}

int main()
{
	int lcd_fd = open("/dev/fb0",O_RDWR);
	if (lcd_fd == -1)
	{
		perror("open lcd fail");
	}
	plcd = mmap(NULL, 800 * 480 * 4, PROT_READ | PROT_WRITE, MAP_SHARED,lcd_fd,0);
	if (plcd==NULL)
	{
		perror("mmao  fail");
	}
	int color = 0x0000FFFF;
	
    clear(0x00666666);
   while(1)
   
 {
     int x,y; 
   
   for(x=0;x<800;x++)
		for(y=0;y<480;y++)
			if(y<160)
				*(plcd + y * 800 + x) = 0x0000ff00;
			else if(y<320)
				*(plcd + y * 800 + x) = 0x000000ff;
			else
				*(plcd + y * 800 + x) = 0x00ff0000;


	draw_circle(240, 400,200, org);//画橙底 
	
    draw_circle_b(270, 400,50, HUI); 
     draw_circle_b(270, 400,40, org); 
    

    draw_circle(180, 480,30, HUI);//眼睛1 
    draw_circle(180, 320,30, HUI); //眼睛2 
    
	
	int i,j;
    int cir_color[480][800];
	for(i=0;i<480;i++)
	{
		for(j=0;j<800;j++)
		{
			if((i-480)*(i-480) + (j-400)*(j-400)<51*51)
				cir_color[i][j]=0x00FF0033;
			else if((i-480)*(i-480) + (j-400)*(j-400)<107*107)
				cir_color[i][j]=0x00FF6600;
			else if((i-480)*(i-480) + (j-400)*(j-400)<168*168)
				cir_color[i][j]=0x00FFFF00;
			else if((i-480)*(i-480) + (j-400)*(j-400)<234*234)
				cir_color[i][j]=0x0000FF00;
			else if((i-480)*(i-480) + (j-400)*(j-400)<307*307)
				cir_color[i][j]=0x0000FFFF;
			else if((i-480)*(i-480) + (j-400)*(j-400)<385*385)
				cir_color[i][j]=0x000000FF;
			else
				cir_color[i][j]=0x00FF00CC;
		}			
	}

    lcd_fd = open("/dev/fb0",O_RDWR);
	if(-1 == lcd_fd)
	{
		printf("open lcd error\n");
	}
	write(lcd_fd,cir_color,800*480*4);

sleep(2);
   
    int si_color[480][800];
	for(i=0;i<480;i++)
	{
		//遍历二维数组每一行的每一列
		for(j=0;j<800;j++)
		{
			int a =  (i-150)*(i-150) + (j-300)*(j-300);
			int b = (i-330)*(i-330) + (j-300)*(j-300);
			int c = (i-150)*(i-150) + (j-500)*(j-500);
			int d = (i-330)*(i-330) + (j-500)*(j-500);
			int r2 = 150*150;
 
			if (a<r2 && b<r2)
				si_color[i][j]=0x00FF0033;
			else if(a<r2 && c<r2)
				si_color[i][j]=0x00FF6600;
			else if(b<r2 && d<r2)
				si_color[i][j]=0x00FFFF00;
			else if(c<r2 && d<r2)
				si_color[i][j]=0x0000FF00;
			else
				si_color[i][j]=0x00FF00CC;
		}			
	}
lcd_fd = open("/dev/fb0",O_RDWR);
	if(-1 == lcd_fd)
	{
		printf("open lcd error\n");
	}
	write(lcd_fd,si_color,800*480*4);

   
   sleep(1);

}
   
	close(lcd_fd);
	munmap(plcd,800*480*4);
	return 0;
}




切记 切记 Liunx 编译时 要加 -lm

电子相册代码实现

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
#include <math.h>
#include <stdlib.h>
int * p = NULL ;

void draw_point(int x,int y,int color)
{
	if(x>=0 && x<800 && y>=0 && y<480 )
	{
		*(p+800*y+x) = color ;
	}
}

void show_bmp (char * pathname ,int x ,int y)
{
	int fd = open(pathname,O_RDONLY);
	if(fd == -1)
	{
		perror("open error\n");
		return ;
	}
	int fd1 = open("/dev/fb0",O_RDWR);
	if(fd1 == -1)
	{
		perror("open error\n");
		return ;
	}
	printf("open success\n");
	
	p = mmap(NULL,800*480*4,PROT_READ | PROT_WRITE,MAP_SHARED ,fd1,0);
	if(p == NULL )
	{
		perror("mmap error\n");
		return ;
	}
	int width,height;
	short depth;
	unsigned char buf[4] ;
	//读取宽度
	lseek(fd,0x12,SEEK_SET);
	read(fd,buf,4);
	width = buf[3]<<24 | buf[2]<< 16 | buf[1] << 8 | buf[0];
	//读取高度
	read(fd,buf,4);
	height  = buf[3]<<24 | buf[2]<< 16 | buf[1] << 8 | buf[0];
	//读取色深
	lseek(fd,0x1c,SEEK_SET);
	read(fd,buf,2);
	depth = buf[1] << 8  | buf[0];
	//打印信息
	printf("width = %d  height = %d  depth = %d \n",width,height,depth);

	
	int line_valid_bytes = abs(width) * depth / 8 ; 
	int laizi=0;
	if( (line_valid_bytes % 4) !=0   )
	{
		laizi =  4 - line_valid_bytes%4;
	}
	int line_bytes = line_valid_bytes  +  laizi ;
	
	int total_bytes = line_bytes * abs(height) ; 
	
	unsigned char * p1  = malloc(total_bytes);
	
	lseek(fd,54,SEEK_SET);
	read(fd,p1,total_bytes);
	
	
	unsigned char a ,r ,g, b ;
	int i = 0;
	int x0=0,y0=0; 
	int color ;
	for(y0=0;y0<abs(height);y0++)
	{
		for(x0=0;x0<abs(width);x0++)
		{
			
		
			b = p1[i++];
			g = p1[i++];
			r = p1[i++];
			if(depth == 32)
			{
				a=p1[i++];
			}
			if(depth == 24)
			{
				a = 0;
			}
			color = a << 24 | r << 16 | g << 8 | b ;
			draw_point(width>0?x+x0:abs(width)+x-1-x0,
					height>0? y+height-1-y0 : y+y0,color);
			
			
		}
		i = i +laizi ;
			
	}
	free(p1);
	close(fd1);
	munmap(p,800*480*4);
	close(fd);
	
}
int main()
{
	while(1)
	{
	
	show_bmp("1.bmp",0 ,0);// 自己存储的图片
	sleep(2);
	show_bmp("2.bmp",0 ,0);
	sleep(2);
	show_bmp("3.bmp",0 ,0);
	sleep(2);
	show_bmp("4.bmp",0 ,0);
	sleep(2);
	show_bmp("5.bmp",0 ,0);
	sleep(2);
}
	return 0;
}

标签:draw,LED,int,开发板,color,fc,gec6818,&&,include
来源: https://blog.csdn.net/qq_41975868/article/details/121366236

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有