OSD (一) 用红外遥控器 控制LCD画面

源码及效果图

  http://download.csdn.net/source/683489

  1.  这是我继上一篇实现OSD的又一次整理。本来想实现一个好看一点的界面,但是要移GUI,没时间弄又要换工作了。本次的功能是用红外遥控器的上,下,左,右键来移动LCD屏上的一个矩形。
  2. 效果图:user113/ddswanqilin/upload/629712374.rar
  3. 以下源码是 在上篇源码的基础添加。在上一篇IR_read()部分添加了返回值。
  4.   
  5. /*************************OSD INIT**********************************************/
  6. #define ir_up 0xe21d
  7. #define ir_down 0xd22d
  8. #define ir_left 0xea15
  9. #define ir_right 0xca35
  10. void OSD_control(void);
  11. /*******************************************************************************/
  12. /***************************LCD********************************************/
  13. void LCD_On(void); //wan 08.6.20
  14. void * malloc(unsigned nbyte) ;//wan 08.6.20
  15. void free(void *pt);//wan 08.6.20
  16. void test_pixel(int horizontal_start,int horizontal_end ,int vertical_start,int vertical_end ,U8 colour);//WAN 08.6.24
  17. void LCD_PutPixel(int x,int y,U8 rgb);//WAN 08.6.24
  18. void test_lcd(void);//WAN 08.6.24
  19. void Display_VDT_LOGO(void);
  20. /**************************************************/
  21. /*****************LCD INIT***wan 08.6.20**************************/
  22. extern char Image$$RW$$Limit[];
  23. void *mallocPt=Image$$RW$$Limit;
  24. #define HEAPEND     (_ISR_STARTADDRESS-STACKSIZE-0x500) // = 0xc7ff000
  25. #define STACKSIZE    0xa00 //SVC satck size(do not use user stack)
  26. U32 (*LcdBuffer)[640/4];
  27. /***************************************************/
  28. //********************************************************************************Void 
  29. void * malloc(unsigned nbyte)  //wan 08.6.20
  30. /*Very simple; Use malloc() & free() like Stack*/
  31. //void *mallocPt=Image$$RW$$Limit;
  32. {
  33.     void *returnPt=mallocPt;
  34.     mallocPt= (int *)mallocPt+nbyte/4+((nbyte%4)>0); //to align 4byte
  35.     if( (int)mallocPt > HEAPEND )
  36.     {
  37.  mallocPt=returnPt;
  38.  return 0;
  39.     }
  40.     return returnPt;
  41. }
  42. void free(void *pt)
  43. {
  44.     mallocPt=pt;
  45. }
  46. /*********************是否要开看硬件电路结构**********************/
  47. void LCD_On(void
  48. {
  49.  Delay(100);
  50.     rPDATC = rPDATC |(1<<8) ;
  51.  rPDATC=rPDATC|(1<<9);
  52.     Delay(100);
  53. }
  54. /********************************************************************/
  55. /*************************LCD INIT *********************************/
  56. void lcd_init(void)//wan 08.6.20
  57.   LcdBuffer=(unsigned int (*)[640/4])malloc(640/1*240); 
  58.   rLCDCON1=(0x0)|(0x2<<5)|(0x1<<7)|(0x3<<8)|(0x3<<10)|(10<<12);
  59.   rLCDCON2=(240-1)|((640*3/8-1)<<10)|(10<<21);
  60.   
  61.   rLCDSADDR1=(0x3<<27)|(((U32)LcdBuffer>>22)<<21)|((U32)LcdBuffer>>1)&0x1fffff;
  62.   rLCDSADDR2=(((U32)LcdBuffer+640*240)>>1)|(13<<21)&0x1fffff;
  63.   rREDLUT  =0xfdb96420;
  64.   rGREENLUT=0xfdb96420;
  65.   rBLUELUT =0xfb40;
  66.   
  67.   rDITHMODE=0x12210;
  68.   rDP1_2 =0xa5a5;      
  69.   rDP4_7 =0xba5da65;
  70.   rDP3_5 =0xa5a5f;
  71.   rDP2_3 =0xd6b;
  72.   rDP5_7 =0xeb7b5ed;
  73.   rDP3_4 =0x7dbe;
  74.   rDP4_5 =0x7ebdf;
  75.   rDP6_7 =0x7fdfbfe;
  76.   
  77.   rLCDCON1=(0x1)|(0x2<<5)|(0x1<<7)|(0x3<<8)|(0x3<<10)|(10<<12);
  78. }
  79. /*************************************************************************/
  80. /****************************************************************************
  81. 【功能说明】液晶显示屏全屏填充某一个8位二进制数
  82. ****************************************************************************/
  83. void Lcddraw_backgroundcolor(U8 color_code)  //wan 08.6.20
  84. {int i;
  85. U32 *pbuf=(U32 *)LcdBuffer;
  86. for(i=0;i<640*240/4;i++)
  87.  *pbuf++=(color_code<<24)+(color_code<<16)+(color_code<<8)+color_code;
  88. //***************************************************************************
  89. void test_lcd(void//测屏软件:全屏显示256色
  90. {int i=0;
  91. //test_data[5]={0xff,0x0,0xe0,0x1c,0x03},//白,黑,红,绿,蓝
  92. for(i=0;i<0xff;i++)
  93.   {
  94.     Delay(5000);
  95.     Lcddraw_backgroundcolor(i);
  96.     Delay(5000);
  97.   }
  98. }
  99. /*************************************************************************
  100. 函数功能:绘制任意点的象素
  101. 参数:    任意点的坐标(X Y)
  102.           该点的颜色  rgb
  103. 大端显示模式32位  屏幕象素低坐标  存储在内存空间的高端 
  104. 比如(0,0)是存在24位到32位而不是0-8位            
  105. **************************************************************************/
  106. void LCD_PutPixel(int x,int y,U8 rgb)// wan 08.6.24
  107. {
  108.  U32 mask[4]={0x00ffffff,0xff00ffff,0xffff00ff,0xffffff00};
  109.  LcdBuffer[y][x/4]=(LcdBuffer[y][x/4] & mask[x%4])|((U32)rgb<<(3-x%4)*8);
  110. }
  111. /*****************************************************************
  112. 函数功能:绘制一个矩形
  113. 参数:    horizontal_start 水平起始坐标(X方向)
  114.           horizontal_end   水平结束坐标 
  115.           vertical_start   垂直起始坐标(Y方向)
  116.           vertical_end     垂直结束坐标
  117. ******************************************************************/
  118. void test_pixel(int horizontal_start,int horizontal_end ,int vertical_start,int vertical_end ,U8 colour)//WAN 08.6.24
  119. {int i=0,j=0; 
  120. for(i=vertical_start;i<vertical_end;i++)
  121.  for(j=horizontal_start;j<horizontal_end;j++)
  122.   LCD_PutPixel(j, i,colour);
  123. }
  124. /*****************************************************
  125. 在屏幕上显示"VDT" LOGO 
  126. 使用一个字模软件 zimo221
  127. ******************************************************/
  128. void Display_VDT_LOGO(void)//wan 08.6.26
  129. {U8 VDTARRAY[61][2]={
  130.                     {1,1},{1,2},{1,3},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11},
  131.      {1,15},{1,16},{1,17},{1,18},{1,19},{1,20},{1,21},{2,2},{2,6},
  132.      {2,9},{2,12},{2,15},{2,18},{2,21},{3,2},{3,6},{3,9},{3,13},
  133.      {3,18},{4,3},{4,5},{4,9},{4,13},{4,18},{5,3},{5,5},{5,9},{5,13},{5,18},
  134.      {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},
  135.      {8,18},{9,4},{9,8},{9,9},{9,10},{9,11},{9,17},{9,18},{9,19}
  136. };
  137. U8 j=0,x=0,y=0;
  138. for(j=0;j<61;j++)
  139.  { x=VDTARRAY[j][1]+100;
  140.         y=VDTARRAY[j][0]+300;
  141.   LCD_PutPixel( x,  y, 0xff);//显示区域可以给 X,Y加一个常数
  142.      }
  143. }
  144. /******************************************************************************
  145. LCD: 夏普 LM7M632 640*240
  146.      坐标方向  左上角(0,0)
  147.                右上角(640,0)
  148.                左下角(0,240)
  149.                右下角(640,240)
  150. *******************************************************************************/
  151. void OSD_control(void)// wan 08.6.29
  152. {static  int control_command=0,move=10,x_s=100,x_e=200,y_s=100,y_e=200;//后面四个变量应为静态变量以便记录本次数据
  153.  IR_open();
  154.  control_command=IR_read();
  155.  switch(control_command)
  156.   {
  157.        case ir_up:
  158.               {
  159.       if(!((y_s-move)<=0)) //当图片碰到四周的时候就不继续了。
  160.        { y_s=y_s-move;
  161.          y_e=y_e-move;
  162.          test_pixel(x_s,x_e,y_s,y_e,0x1c);
  163.          test_pixel(x_s,x_e,y_e,y_e+move,0x03);//清除走过的痕迹 0x03为背景色
  164.        }
  165.       break;
  166.       }
  167.     case ir_down:
  168.                {
  169.      if(!((y_e-move)>=240))
  170.      {
  171.      y_s=y_s+move;
  172.      y_e=y_e+move;
  173.      test_pixel(x_s, x_e,y_s,y_e,0x1c);
  174.      test_pixel(x_s,x_e,y_s-move,y_s,0x03);//清除走过的痕迹 0x03为背景色
  175.       }
  176.      break;
  177.                } 
  178.    case ir_left:
  179.               {
  180.        
  181.      if(!((x_s-move)<=0))
  182.      {
  183.      x_s=x_s-move;
  184.      x_e=x_e-move;
  185.      test_pixel(x_s, x_e,y_s,y_e,0x1c);
  186.      test_pixel(x_e,x_e+move,y_s,y_e,0x03);//清除走过的痕迹 0x03为背景色
  187.       }
  188.      break;
  189.                 }
  190.    case ir_right:
  191.                {
  192.       
  193.       if(!((x_e-move)>=640))
  194.       {
  195.       x_s=x_s+move;
  196.       x_e=x_e+move;
  197.       test_pixel(x_s, x_e,y_s,y_e,0x1c); 
  198.       test_pixel(x_s-move,x_s,y_s,y_e,0x03);//清除走过的痕迹 0x03为背景色
  199.        }
  200.       break;
  201.        }
  202.        default:
  203.              test_pixel(x_s, x_e,y_s,y_e,0x1c);
  204.   }
  205.  IR_close();
  206. }
  207. void Main(void)
  208. {  
  209.     Isr_Init();
  210.     Port_Init();
  211.     Uart_Init(0,115200); 
  212.  //wan 08.6.20
  213.  lcd_init();
  214. // LCD_On();
  215.  //IR_open();
  216.    // Uart_Select(1);
  217. //    Delay(0);  //calibrate Delay()
  218.    // Delay(5000);
  219.  Lcddraw_backgroundcolor(0x03);//08.6.26
  220.   test_pixel(100,200,100,200,0x1c);//
  221.    while(1)
  222.   {// 
  223.     // uart_IR_flash(1);
  224.   // uart_ir();
  225.  //key_ad();
  226.  //   IR_open();
  227.  //   IR_read();
  228.  //  IR_close();
  229.   //ir_test();
  230. OSD_control();
    • // Uart_Printf("LCD TEST !/n");
    • //test_lcd();
    • //test_pixel(100,200,100,200,0x1c);
    • //Display_VDT_LOGO();
    •    }
    •    
    • }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值