源码及效果图
http://download.youkuaiyun.com/source/683489
- 这是我继上一篇实现OSD的又一次整理。本来想实现一个好看一点的界面,但是要移GUI,没时间弄又要换工作了。本次的功能是用红外遥控器的上,下,左,右键来移动LCD屏上的一个矩形。
- 效果图:user113/ddswanqilin/upload/629712374.rar
- 以下源码是 在上篇源码的基础添加。在上一篇IR_read()部分添加了返回值。
- /*************************OSD INIT**********************************************/
- #define ir_up 0xe21d
- #define ir_down 0xd22d
- #define ir_left 0xea15
- #define ir_right 0xca35
- void OSD_control(void);
- /*******************************************************************************/
- /***************************LCD********************************************/
- void LCD_On(void); //wan 08.6.20
- void * malloc(unsigned nbyte) ;//wan 08.6.20
- void free(void *pt);//wan 08.6.20
- void test_pixel(int horizontal_start,int horizontal_end ,int vertical_start,int vertical_end ,U8 colour);//WAN 08.6.24
- void LCD_PutPixel(int x,int y,U8 rgb);//WAN 08.6.24
- void test_lcd(void);//WAN 08.6.24
- void Display_VDT_LOGO(void);
- /**************************************************/
- /*****************LCD INIT***wan 08.6.20**************************/
- extern char Image$$RW$$Limit[];
- void *mallocPt=Image$$RW$$Limit;
- #define HEAPEND (_ISR_STARTADDRESS-STACKSIZE-0x500) // = 0xc7ff000
- #define STACKSIZE 0xa00 //SVC satck size(do not use user stack)
- U32 (*LcdBuffer)[640/4];
- /***************************************************/
- //********************************************************************************Void
- void * malloc(unsigned nbyte) //wan 08.6.20
- /*Very simple; Use malloc() & free() like Stack*/
- //void *mallocPt=Image$$RW$$Limit;
- {
- void *returnPt=mallocPt;
- mallocPt= (int *)mallocPt+nbyte/4+((nbyte%4)>0); //to align 4byte
- if( (int)mallocPt > HEAPEND )
- {
- mallocPt=returnPt;
- return 0;
- }
- return returnPt;
- }
- void free(void *pt)
- {
- mallocPt=pt;
- }
- /*********************是否要开看硬件电路结构**********************/
- void LCD_On(void)
- {
- Delay(100);
- rPDATC = rPDATC |(1<<8) ;
- rPDATC=rPDATC|(1<<9);
- Delay(100);
- }
- /********************************************************************/
- /*************************LCD INIT *********************************/
- void lcd_init(void)//wan 08.6.20
- {
- LcdBuffer=(unsigned int (*)[640/4])malloc(640/1*240);
- rLCDCON1=(0x0)|(0x2<<5)|(0x1<<7)|(0x3<<8)|(0x3<<10)|(10<<12);
- rLCDCON2=(240-1)|((640*3/8-1)<<10)|(10<<21);
- rLCDSADDR1=(0x3<<27)|(((U32)LcdBuffer>>22)<<21)|((U32)LcdBuffer>>1)&0x1fffff;
- rLCDSADDR2=(((U32)LcdBuffer+640*240)>>1)|(13<<21)&0x1fffff;
- rREDLUT =0xfdb96420;
- rGREENLUT=0xfdb96420;
- rBLUELUT =0xfb40;
- rDITHMODE=0x12210;
- rDP1_2 =0xa5a5;
- rDP4_7 =0xba5da65;
- rDP3_5 =0xa5a5f;
- rDP2_3 =0xd6b;
- rDP5_7 =0xeb7b5ed;
- rDP3_4 =0x7dbe;
- rDP4_5 =0x7ebdf;
- rDP6_7 =0x7fdfbfe;
- rLCDCON1=(0x1)|(0x2<<5)|(0x1<<7)|(0x3<<8)|(0x3<<10)|(10<<12);
- }
- /*************************************************************************/
- /****************************************************************************
- 【功能说明】液晶显示屏全屏填充某一个8位二进制数
- ****************************************************************************/
- void Lcddraw_backgroundcolor(U8 color_code) //wan 08.6.20
- {int i;
- U32 *pbuf=(U32 *)LcdBuffer;
- for(i=0;i<640*240/4;i++)
- *pbuf++=(color_code<<24)+(color_code<<16)+(color_code<<8)+color_code;
- }
- //***************************************************************************
- void test_lcd(void) //测屏软件:全屏显示256色
- {int i=0;
- //test_data[5]={0xff,0x0,0xe0,0x1c,0x03},//白,黑,红,绿,蓝
- for(i=0;i<0xff;i++)
- {
- Delay(5000);
- Lcddraw_backgroundcolor(i);
- Delay(5000);
- }
- }
- /*************************************************************************
- 函数功能:绘制任意点的象素
- 参数: 任意点的坐标(X Y)
- 该点的颜色 rgb
- 大端显示模式32位 屏幕象素低坐标 存储在内存空间的高端
- 比如(0,0)是存在24位到32位而不是0-8位
- **************************************************************************/
- void LCD_PutPixel(int x,int y,U8 rgb)// wan 08.6.24
- {
- U32 mask[4]={0x00ffffff,0xff00ffff,0xffff00ff,0xffffff00};
- LcdBuffer[y][x/4]=(LcdBuffer[y][x/4] & mask[x%4])|((U32)rgb<<(3-x%4)*8);
- }
- /*****************************************************************
- 函数功能:绘制一个矩形
- 参数: horizontal_start 水平起始坐标(X方向)
- horizontal_end 水平结束坐标
- vertical_start 垂直起始坐标(Y方向)
- vertical_end 垂直结束坐标
- ******************************************************************/
- void test_pixel(int horizontal_start,int horizontal_end ,int vertical_start,int vertical_end ,U8 colour)//WAN 08.6.24
- {int i=0,j=0;
- for(i=vertical_start;i<vertical_end;i++)
- for(j=horizontal_start;j<horizontal_end;j++)
- LCD_PutPixel(j, i,colour);
- }
- /*****************************************************
- 在屏幕上显示"VDT" LOGO
- 使用一个字模软件 zimo221
- ******************************************************/
- void Display_VDT_LOGO(void)//wan 08.6.26
- {U8 VDTARRAY[61][2]={
- {1,1},{1,2},{1,3},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11},
- {1,15},{1,16},{1,17},{1,18},{1,19},{1,20},{1,21},{2,2},{2,6},
- {2,9},{2,12},{2,15},{2,18},{2,21},{3,2},{3,6},{3,9},{3,13},
- {3,18},{4,3},{4,5},{4,9},{4,13},{4,18},{5,3},{5,5},{5,9},{5,13},{5,18},
- {6,3},{6,5},{6,9},{6,13},{6,18},{7,3},{7,5},{7,9},{7,13},{7,18},{8,4},{8,9},{8,12},
- {8,18},{9,4},{9,8},{9,9},{9,10},{9,11},{9,17},{9,18},{9,19}
- };
- U8 j=0,x=0,y=0;
- for(j=0;j<61;j++)
- { x=VDTARRAY[j][1]+100;
- y=VDTARRAY[j][0]+300;
- LCD_PutPixel( x, y, 0xff);//显示区域可以给 X,Y加一个常数
- }
- }
- /******************************************************************************
- LCD: 夏普 LM7M632 640*240
- 坐标方向 左上角(0,0)
- 右上角(640,0)
- 左下角(0,240)
- 右下角(640,240)
- *******************************************************************************/
- void OSD_control(void)// wan 08.6.29
- {static int control_command=0,move=10,x_s=100,x_e=200,y_s=100,y_e=200;//后面四个变量应为静态变量以便记录本次数据
- IR_open();
- control_command=IR_read();
- switch(control_command)
- {
- case ir_up:
- {
- if(!((y_s-move)<=0)) //当图片碰到四周的时候就不继续了。
- { y_s=y_s-move;
- y_e=y_e-move;
- test_pixel(x_s,x_e,y_s,y_e,0x1c);
- test_pixel(x_s,x_e,y_e,y_e+move,0x03);//清除走过的痕迹 0x03为背景色
- }
- break;
- }
- case ir_down:
- {
- if(!((y_e-move)>=240))
- {
- y_s=y_s+move;
- y_e=y_e+move;
- test_pixel(x_s, x_e,y_s,y_e,0x1c);
- test_pixel(x_s,x_e,y_s-move,y_s,0x03);//清除走过的痕迹 0x03为背景色
- }
- break;
- }
- case ir_left:
- {
- if(!((x_s-move)<=0))
- {
- x_s=x_s-move;
- x_e=x_e-move;
- test_pixel(x_s, x_e,y_s,y_e,0x1c);
- test_pixel(x_e,x_e+move,y_s,y_e,0x03);//清除走过的痕迹 0x03为背景色
- }
- break;
- }
- case ir_right:
- {
- if(!((x_e-move)>=640))
- {
- x_s=x_s+move;
- x_e=x_e+move;
- test_pixel(x_s, x_e,y_s,y_e,0x1c);
- test_pixel(x_s-move,x_s,y_s,y_e,0x03);//清除走过的痕迹 0x03为背景色
- }
- break;
- }
- default:
- test_pixel(x_s, x_e,y_s,y_e,0x1c);
- }
- IR_close();
- }
- void Main(void)
- {
- Isr_Init();
- Port_Init();
- Uart_Init(0,115200);
- //wan 08.6.20
- lcd_init();
- // LCD_On();
- //IR_open();
- // Uart_Select(1);
- // Delay(0); //calibrate Delay()
- // Delay(5000);
- Lcddraw_backgroundcolor(0x03);//08.6.26
- test_pixel(100,200,100,200,0x1c);//
- while(1)
- {//
- // uart_IR_flash(1);
- // uart_ir();
- //key_ad();
- // IR_open();
- // IR_read();
- // IR_close();
- //ir_test();
- OSD_control();
-
- // Uart_Printf("LCD TEST !/n");
- //test_lcd();
- //test_pixel(100,200,100,200,0x1c);
- //Display_VDT_LOGO();
- }
- }