找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1614|回复: 0
收起左侧

51单片机彩屏图片显示

[复制链接]
ID:301757 发表于 2018-10-12 19:12 | 显示全部楼层 |阅读模式
基于51单片机进行 彩屏图片显示

单片机源程序如下:
  1. /*
  2. ================================================================================
  3. Copytight      : Yihetech Co,.Ltd, All rightd reserved. 版权归属亿和电子工作室

  4. File Name      : lcd.c
  5. Description    : LCD module operations
  6. Date           : 2009-7-19 21:17:45
  7. Version        : V1.0
  8. Author         : LiYong(李勇), yihe_liyong@126.com
  9. Target device  : C8051F340
  10. Compiler       : KeilC51 V8.16
  11. Note           : 转载时务必保留此信息,否则无权以任何形式传播本文件
  12. ================================================================================
  13. */
  14. #define _LCD_C_
  15. #include "LCD.H"


  16. #define LCDCOM           0
  17. #define LCDDAT           1

  18. sbit LED_RD = P2^5;
  19. sbit LED_CS = P2^7;
  20. sbit LED_WR = P2^4;
  21. sbit LED_A0 = P2^3;
  22. sbit BLACKLIGHT = P2^0;
  23. sbit RESET = P2^6;


  24. void _delay_ms(unsigned char del)
  25. {
  26.         unsigned int i,j;
  27.         for(i=0; i<del; i++)
  28.         for(j=0; j<182; j++)   
  29.         ;
  30. }
  31. /*
  32. ================================================================================
  33. * Name        : LCD_Init( )
  34. * Description : Initialize the LCD module
  35. * Input       : None
  36. * Output      : None
  37. * Note        : None
  38. ================================================================================
  39. */
  40. void LCDWR( INT8U cmd_dt, INT8U value )
  41. {
  42.         LED_RD = 1;
  43.         LED_CS = 1;
  44.         LED_WR = 1;
  45.         if(cmd_dt)
  46.         {
  47.                 LED_A0 = 1;
  48.         }
  49.         else
  50.         {
  51.                 LED_A0 = 0;       
  52.         }
  53.         P0 = value;
  54.         LED_CS = 0;
  55.         LED_WR = 0;
  56.         LED_WR = 1;
  57.         LED_CS = 1;
  58. }
  59. /*
  60. ================================================================================
  61. * Name        : LCD_Init( )
  62. * Description : Initialize the LCD module
  63. * Input       : None
  64. * Output      : None
  65. * Note        : None
  66. ================================================================================
  67. */
  68. void LCD_Init( void )
  69. {
  70.                 RESET=1;
  71.                 _delay_ms(10);  //Delay 1ms
  72.                 RESET=0;
  73.                 _delay_ms(10);  //Delay 1ms
  74.                 RESET=1;
  75.                 _delay_ms(10);  //Delay 120ms

  76.                 LCDWR( LCDCOM, 0x01);//software reset
  77.                 _delay_ms(50);       //delay 150ms
  78.                 LCDWR( LCDCOM, 0x11);//software reset

  79.                 LCDWR( LCDCOM,0xB1); // Auto load set
  80.                 LCDWR ( LCDDAT,0x02);//auto load disable//0x9f
  81.                 LCDWR ( LCDDAT,0x35);
  82.                    LCDWR ( LCDDAT,0x36);
  83.                 LCDWR( LCDCOM,0xB2);  //EE read/write mode
  84.                 LCDWR ( LCDDAT,0x02); //set read  mode
  85.                 LCDWR ( LCDDAT,0x35);
  86.                 LCDWR ( LCDDAT,0x36);
  87.                 LCDWR( LCDCOM,0xB3);  //EE read/write mode
  88.                 LCDWR ( LCDDAT,0x02); //set read  mode
  89.                 LCDWR ( LCDDAT,0x35);
  90.                 LCDWR ( LCDDAT,0x36);
  91.                 LCDWR( LCDCOM,0xB4);  //EE read/write mode
  92.                 LCDWR ( LCDDAT,0x07); //set read  mode
  93.                
  94.                   
  95.                 LCDWR( LCDCOM,0xb6);   
  96.                 LCDWR ( LCDDAT,0xb4);
  97.                 LCDWR ( LCDDAT,0xf0);
  98.                                 
  99.                 LCDWR( LCDCOM,0xc0);   
  100.                 LCDWR ( LCDDAT,0xa2);
  101.                 LCDWR ( LCDDAT,0x02);
  102.             LCDWR ( LCDDAT,0x84);
  103.                 LCDWR( LCDCOM,0xc1);
  104.                 LCDWR ( LCDDAT,0x05);
  105.                 //LCDWR( LCDCOM,0xc2);
  106.                 //LCDWR ( LCDDAT,0x0a);
  107.                 //LCDWR ( LCDDAT,0x00);
  108.                 //LCDWR( LCDCOM,0xc3);
  109.                 //LCDWR ( LCDDAT,0x8a);
  110.                 //LCDWR ( LCDDAT,0x2a);
  111.                 //LCDWR( LCDCOM,0xc4);
  112.                 //LCDWR ( LCDDAT,0x8a);
  113.                 //LCDWR ( LCDDAT,0xee);
  114.                 //LCDWR( LCDCOM,0xd9);
  115.                 //LCDWR ( LCDDAT,0x40);

  116.                 LCDWR( LCDCOM,0xc5);
  117.                 LCDWR ( LCDDAT,0x02);
  118.                 LCDWR( LCDCOM,0xc7);
  119.                 LCDWR ( LCDDAT,0x00);

  120.                 LCDWR( LCDCOM,0x36);
  121.                 LCDWR ( LCDDAT,0xc8);

  122. //////////


  123.         LCDWR( LCDCOM,0xe0);   //write contrast for mobile
  124.                 LCDWR ( LCDDAT,0x12);
  125.                 LCDWR ( LCDDAT,0x1c);
  126.                 LCDWR ( LCDDAT,0x10);
  127.                 LCDWR ( LCDDAT,0x18);
  128.                 LCDWR ( LCDDAT,0x33);

  129.                 LCDWR ( LCDDAT,0x2c);
  130.                 LCDWR ( LCDDAT,0x25);
  131.                 LCDWR ( LCDDAT,0x28);
  132.                 LCDWR ( LCDDAT,0x27);

  133.                 LCDWR ( LCDDAT,0x2f);
  134.                 LCDWR ( LCDDAT,0x3c);
  135.                 LCDWR ( LCDDAT,0x00);
  136.                 LCDWR ( LCDDAT,0x03);

  137.                 LCDWR ( LCDDAT,0x03);
  138.                 LCDWR ( LCDDAT,0x10);

  139.                 //-----------OTPB SET----------------------//
  140.                 LCDWR( LCDCOM,0xe1);// bias set
  141.                 LCDWR ( LCDDAT,0x12);
  142.                 LCDWR ( LCDDAT,0x1c);
  143.                 LCDWR ( LCDDAT,0x10);
  144.                 LCDWR ( LCDDAT,0x18);
  145.                 LCDWR ( LCDDAT,0x33);

  146.                 LCDWR ( LCDDAT,0x2c);
  147.                 LCDWR ( LCDDAT,0x25);
  148.                 LCDWR ( LCDDAT,0x28);
  149.                 LCDWR ( LCDDAT,0x27);

  150.                 LCDWR ( LCDDAT,0x2f);
  151.                 LCDWR ( LCDDAT,0x3c);
  152.                 LCDWR ( LCDDAT,0x00);
  153.                 LCDWR ( LCDDAT,0x03);

  154.                 LCDWR ( LCDDAT,0x03);
  155.                 LCDWR ( LCDDAT,0x10);


  156.                 LCDWR( LCDCOM,0x2a);// bias set
  157.                 LCDWR ( LCDDAT,0x00);
  158.                 LCDWR ( LCDDAT,0x02);
  159.                 LCDWR ( LCDDAT,0x00);
  160.                 LCDWR ( LCDDAT,0x81);

  161.                 LCDWR( LCDCOM,0x2b);// bias set
  162.                 LCDWR ( LCDDAT,0x00);
  163.                 LCDWR ( LCDDAT,0x03);
  164.                 LCDWR ( LCDDAT,0x00);
  165.                 LCDWR ( LCDDAT,0x82);

  166.                 LCDWR( LCDCOM,0xf0);// bias set
  167.                 LCDWR ( LCDDAT,0x01);
  168.                 LCDWR( LCDCOM,0xf6);// bias set
  169.                 LCDWR ( LCDDAT,0x00);
  170.                 LCDWR( LCDCOM,0x3a);// bias set
  171.                 LCDWR ( LCDDAT,0x05);

  172.                 _delay_ms(50);  
  173.                 LCDWR( LCDCOM,0x29);   //booster set
  174.                 _delay_ms(50);  
  175.                 //LCDWR( LCDCOM,0x2c);   //booster efficiency set
  176. }
  177. /*
  178. ========================================================================================================
  179. Name: LCDDrawDollop
  180. Function: Draw a dollop at a special area
  181. Input:        1. *dollop : The pointer of a DOLLOP struct
  182. Output: None
  183. Note: The value of the input structrue must be correct, This function does not check the parameters.
  184. Author: LiYong
  185. Date  : 2008.08.09
  186. ========================================================================================================
  187. */
  188. void LCDSetArea( INT16U x1, INT16U y1, INT16U x2, INT16U y2 )
  189. {
  190.         x1+=2;
  191.         x2+=2;
  192.         y1+=3;
  193.         y2+=3;       

  194.     LCDWR ( LCDCOM, 0x2A);
  195.         LCDWR ( LCDDAT,  x1>>8);
  196.         LCDWR ( LCDDAT, x1);
  197.         LCDWR ( LCDDAT,  x2>>8);
  198.         LCDWR ( LCDDAT, x2 + 0);

  199.         LCDWR ( LCDCOM, 0x2B);
  200.         LCDWR ( LCDDAT,  y1>>8);
  201.         LCDWR ( LCDDAT, y1);
  202.         LCDWR ( LCDDAT,  y2>>8);
  203.         LCDWR ( LCDDAT, y2);
  204.         LCDWR ( LCDCOM, 0x2C);
  205. }

  206. void        LCDDrawDollop( DOLLOP* dollop )
  207. {
  208.         INT16U x,y;

  209.         LCDSetArea(dollop->xs, dollop->ys, dollop->xe, dollop->ye);           //Set a area at the screen
  210.         for( x = 0; x < dollop->xe - dollop->xs + 1; x ++ )                                        //Display rows
  211.         {
  212.                  for( y = 0; y < dollop->ye - dollop->ys + 1; y ++ )                                 //Display columns
  213.                 {
  214.                          LCDWR( LCDDAT, dollop->Color>>8 );
  215.                         LCDWR( LCDDAT, dollop->Color );
  216.                 }
  217.         }
  218. }
  219. /*
  220. ========================================================================================================
  221. Name: LCDDrawPoint( );
  222. Function: Draw a point
  223. Input:        -pPoint, A structure pointer
  224. Output: None
  225. ========================================================================================================
  226. */
  227. void LCDDrawPoint( POINT* pPoint )
  228. {
  229.     LCDSetArea( pPoint->x, pPoint->y, pPoint->x, pPoint->y );
  230.         LCDWR ( LCDDAT,  ( pPoint->Color >> 8 ) & 0xff );
  231.         LCDWR ( LCDDAT,  pPoint->Color & 0xff );
  232. }
  233. /*
  234. ========================================================================================================
  235. Name: LCDDrawHRLine( );
  236. Function: Draw a line
  237. Input:        -pLine, A structure pointer to a line
  238. Output: None
  239. ========================================================================================================
  240. */
  241. void LCDDrawHRLine( LINE* pLine )
  242. {
  243.         INT8U x0, x1, y0, y1;
  244.         if( pLine->xs != pLine->xe && pLine->ys != pLine->ye )   return;
  245.         if( pLine->ys > pLine->ye )
  246.         {
  247.                 y0 = pLine->ye;
  248.                 y1 = pLine->ys;
  249.         }
  250.         else
  251.         {
  252.                 y0 = pLine->ys;
  253.                 y1 = pLine->ye;
  254.         }
  255.         if( pLine->xs > pLine->xe )
  256.         {
  257.                 x0 = pLine->xe;
  258.                 x1 = pLine->xs;
  259.         }
  260.         else
  261.         {
  262.                 x0 = pLine->xs;
  263.                 x1 = pLine->xe;
  264.         }
  265.         LCDSetArea( x0, y0, x1, y1 );
  266.         x0 = x1 - x0;
  267.         if( x0 == 0 ) x0 = y1 - y0;
  268.         for( y0 = 0; y0 < x0; y0 ++ )
  269.         {
  270.                 LCDWR( LCDDAT, pLine->Color >> 8 );
  271.                 LCDWR( LCDDAT, pLine->Color );
  272.         }
  273. }
  274. /*
  275. ========================================================================================================
  276. Name: PrintBitBlock
  277. Function: Print a special block in the screen.
  278. Input:        pBitBlock: This is a pointer, It points to a block whitch contains informations of the block,
  279.         eg. height, width, and so on.
  280. Output: None
  281. Note:   None
  282. Author: LiYong
  283. Date  : 2008.08.09
  284. ========================================================================================================
  285. */
  286. void        PrintBitBlock( BitBlock *pBitBlock )
  287. {
  288.     INT8U        Row, Column;
  289.         INT32U        BytesAbs;
  290.         INT8U        RowBytes;

  291.         LCDSetArea( pBitBlock->xs, pBitBlock->ys,
  292.                 pBitBlock->xs + pBitBlock->Width - 1, pBitBlock->ys + pBitBlock->Height - 1 );

  293.         RowBytes = pBitBlock->Width >> 3;
  294.         if( pBitBlock->Width & 0x07 )
  295.         {
  296.                  RowBytes ++;
  297.         }
  298.         for( Row = 0; Row <  pBitBlock->Height; Row ++ )
  299.         {
  300.                  for( Column = 0; Column < pBitBlock->Width; Column ++ )
  301.                 {
  302.                          BytesAbs = Row * RowBytes + ( Column >> 3 )        ;
  303.                         if( *( pBitBlock->pData + BytesAbs )        & ( 1<<( Column & 0x07 )) )
  304.                         {
  305.                                  LCDWR( LCDDAT, pBitBlock->Color >> 8 );
  306.                                 LCDWR( LCDDAT, pBitBlock->Color );
  307.                         }
  308.                         else
  309.                         {
  310.                                  LCDWR( LCDDAT, pBitBlock->BackColor >> 8 );
  311.                                 LCDWR( LCDDAT, pBitBlock->BackColor );
  312.                         }
  313.                 }
  314.         }
  315. }
  316. /*
  317. ========================================================================================================
  318. Name: GUI_Image( )
  319. Function: Print a image
  320. Input:        point to a struct which contains the informations of the image
  321. Output: None
  322. Note:   None
  323. Author: LiYong
  324. Date  : 2008.08.09
  325. ========================================================================================================
  326. */
  327. void GUI_Image( IMAGE *pImage )
  328. {
  329.     INT16U x, y;
  330.     INT32U datacount = 0;
  331.     LCDSetArea( pImage->xs, pImage->ys, pImage->xs + pImage->length - 1, pImage->ys + pImage->height - 1 );

  332.     for( x = 0; x < pImage->length; x ++ )
  333.     {
  334.         for( y = 0; y < pImage->height; y ++ )
  335.         {
  336.             LCDWR( LCDDAT, *( pImage->pData + datacount++ ) );
  337.             LCDWR( LCDDAT, *( pImage->pData + datacount++ ) );

  338.         }
  339.     }
  340. }
  341. /*
  342. ================================================================================
  343. -----------------------------------End of file----------------------------------
  344. ================================================================================
  345. */
复制代码

所有资料51hei提供下载:
彩屏图片显示.rar (208.52 KB, 下载次数: 10)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表