main.c

来自「博创2410的实验代码」· C语言 代码 · 共 79 行

C
79
字号
#include "../inc/drivers.h"
#include "../inc/lib.h"
#include <string.h>
#include <stdio.h>
#include "inc/macro.h"
#include  "inc/reg2410.h"
#include "inc/lcd320.h"
#pragma import(__use_no_semihosting_swi)  // ensure no functions that use semihosting 
#define RGB(r,g,b)	(((b)<<16)|((g)<<8)|(r)) //RGB888
U32 LCDBuffer[LCDHEIGHT][LCDWIDTH];
void  ARMTargetInit(void); 
void Buffer_FillRect(int left,int top,int right,int bottom,U32 color);
void Buffer_SetPixel(int x,int y,U32 color);
void LCD_Refresh();
void ClearScreen();
U32* pLCDFB=0;
int main(void)
{   
	ARMTargetInit();	//开发版初始化
	LCD_Init();			//LCD初始化
    ClearScreen();
	Buffer_FillRect(150,70,490,410,RGB(0,0,255)); 
	LCD_Refresh();
    while(1);
	return 0;
}
	
void Buffer_FillRect(int left,int top,int right,int bottom,U32 color)
{
	int i,j;
	
	for(i=left;i<=right;i++){
		for(j=top;j<=bottom;j++)
			Buffer_SetPixel(i,j,color);
	}
}
    
    void Buffer_SetPixel(int x,int y,U32 color)
{	        
			LCDBuffer[y][x]=color;			
}	
	
void LCD_Refresh()
{
	int i,j;
	U32 lcddata;
	U32 pixcolor;	//一个像素点的颜色
	U32 *p=pLCDFB;	
	U8* pbuf=(U8*)LCDBuffer[0];

#define RGB888_RGB565(p)	((p[2]>>3)|((p[1]&0xfc)<<3)|((p[0]&0xf8)<<8))
								B			G				R
	for(i=0;i<LCDWIDTH*LCDHEIGHT/2;i++){
		pixcolor=RGB888_RGB565(pbuf);	//变换RGB
		lcddata=pixcolor;
		pbuf+=4;

		pixcolor=RGB888_RGB565(pbuf);	//变换RGB
		lcddata|=pixcolor<<16;
		pbuf+=4;

		*p=lcddata;//每次送32位数据
		p++;
	}
   
//#endif
}	

void LCDLib_Init(unsigned int*pbuffer)
{
	pLCDFB=pbuffer;
	Uart_Printf(0,"\nLCD initialization is OK\n");
	
}

void ClearScreen()
{
 Buffer_FillRect(0,0,LCDWIDTH,LCDHEIGHT,RGB(255,255,255));
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?