Chinaunix首页 | 论坛 | 博客
  • 博客访问: 974409
  • 博文数量: 238
  • 博客积分: 2842
  • 博客等级: 少校
  • 技术积分: 2765
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-16 00:20
个人简介

stdlf

文章分类

全部博文(238)

文章存档

2013年(6)

2012年(13)

2011年(82)

2010年(89)

2009年(48)

我的朋友

分类:

2010-01-20 00:48:40

  1. #i nclude     
  2.    
  3. #i nclude "44b.h"    
  4. #i nclude "44blib.h"    
  5. #i nclude "def.h"    
  6.    
  7. #i nclude "lcd.h"    
  8. #i nclude "lcdlib.h"    
  9. #i nclude "glib.h"    
  10.    
  11. //SCR_XSIZE,SCR_YSIZE,LCD_XSIZE,LCD_YSIZE are defined in lcd.h    
  12.    
  13. #define M5D(n) ((n) & 0x1fffff)//只保留n的低21位    
  14.    
  15. #define ARRAY_SIZE_MONO     (SCR_XSIZE*1/8*SCR_YSIZE)//单色模式下的数组大小    
  16. #define ARRAY_SIZE_G4       (SCR_XSIZE*2/8*SCR_YSIZE)//G4灰度模式下数组大小    
  17. #define ARRAY_SIZE_G16      (SCR_XSIZE*4/8*SCR_YSIZE)//G16灰度模式下数组大小    
  18. #define ARRAY_SIZE_COLOR    (SCR_XSIZE*8/8*SCR_YSIZE)//彩色模式下数组大小    
  19.    
  20. #define HOZVAL          (LCD_XSIZE/4-1)//数据线位数位4,VD[3:0]    
  21. #define HOZVAL_COLOR    (LCD_XSIZE*3/8-1)//彩色模式时,数据线位数为8,VD[7:0]    
  22. #define LINEVAL         (LCD_YSIZE-1)//单扫描模式    
  23. #define MVAL            (13)    
  24.    
  25. #define CLKVAL_MONO     (6)    
  26. #define CLKVAL_G4       (6)    
  27. #define CLKVAL_G16      (6)    
  28. #define CLKVAL_COLOR    (6)    
  29. #define MVAL_USED       (0)    
  30.    
  31. unsigned int (*Buffer1)[SCR_XSIZE*1/32];//ARM7的内存地址是4B(32位)对齐,指向数组的指针变量Buffer1,单色模式    
  32. unsigned int (*Buffer4)[SCR_XSIZE*2/32];//ARM7的内存地址是4B(32位)对齐,指向数组的指针变量Buffer4,4级灰度模式    
  33. unsigned int (*Buffer16)[SCR_XSIZE*4/32];//ARM7的内存地址是4B(32位)对齐,指向数组的指针变量Buffer16,16级灰度模式    
  34. unsigned int (*Buffer256)[SCR_XSIZE*8/32];//ARM7的内存地址是4B(32位)对齐,指向数组的指针变量Buffer256,彩色模式    
  35.    
  36.    
  37. /************************************************************  
  38. *函数名:Lcd_Init  
  39. *功能:初始化LCD控制器  
  40. *入口参数:depth---单色模式为1,  
  41.                 ---4级灰度模式为4  
  42.                 ---16级灰度模式为16  
  43.                 ---彩色模式为256  
  44. *出口参数:无  
  45. ************************************************************/   
  46. void Lcd_Init(int depth)   
  47. {   
  48.     //320x240 1bit/1pixel LCD    
  49.     rPDATC = ( rPDATC & (~(1<<8)) );//打开LCD显示屏背光    
  50.        
  51.     switch(depth)   
  52.     {   
  53.        case 1://单色模式,每个像素1位,即2级灰度        
  54.        if((U32)Buffer1==0)   
  55.        {   
  56.           //The total  memory should be inside 4MB.    
  57.           //For example, if total memory is 8MB, the  memory     
  58.           //should be in 0xc000000~0xc3fffff or c400000~c7fffff.    
  59.           //But, the following code doesn't meet this condition(4MB)     
  60.           //if the code size & location is changed..    
  61.           Buffer1=(unsigned int (*)[SCR_XSIZE/32])malloc(ARRAY_SIZE_MONO);//动态分配内存     
  62.        }   
  63.    
  64.        rLCDCON1=(0)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_MONO<<12);   
  65.        //Disable ENVID,VD[7:0] Invert,4B_SNGL_SCAN,WDLY=16clk,WLH=16clk    
  66.            
  67.        rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);     
  68.        //LINEBLANK=10 (without any calculation)     
  69.            
  70.        rLCDSADDR1= (0x0<<27) | ( ((U32)Buffer1>>22)<<21 ) | M5D((U32)Buffer1>>1);   
  71.        //Monochrome mode, LCDBANK(4MB对齐), LCDBASEU(2B对齐)    
  72.            
  73.        rLCDSADDR2= M5D( (((U32)Buffer1+(SCR_XSIZE*LCD_YSIZE*1/8))>>1) ) | (MVAL<<21);   
  74.        //LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,BSWP disable,LCDBASEL(2B对齐), MVAL    
  75.           
  76.        rLCDSADDR3= (LCD_XSIZE*1/16) | ( ((SCR_XSIZE-LCD_XSIZE)*1/16)<<9 );   
  77.        //LCD_XSIZE是实屏宽度,SCR_XSIZE是虚屏宽度,OFFSIZE, PAGEWIDTH都是以16位为单位    
  78.    
  79.        rLCDCON1=(1)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_MONO<<12);   
  80.        //enable ENVID,4B_SNGL_SCAN,WDLY=16clk,WLH=16clk,    
  81.        break;   
  82.    
  83.     case 4://4级灰度    
  84.     if((U32)Buffer4==0)   
  85.     {   
  86.         //The total  memory should be inside 4MB.    
  87.         //For example, if total memory is 8MB, the  memory     
  88.         //should be in 0xc000000~0xc3fffff or c400000~c7fffff.    
  89.         //But, the following code doesn't meet this condition(4MB)     
  90.         //if the code size & location is changed..    
  91.         Buffer4=(unsigned int (*)[SCR_XSIZE/16])malloc(ARRAY_SIZE_G4);    
  92.     }   
  93.    
  94.     rLCDCON1=(0)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G4<<12);   
  95.     //disable ENVID,VD[7:0] Invert,4B_SNGL_SCAN,WDLY=16clk,WLH=16clk    
  96.            
  97.     rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);     
  98.     //LINEBLANK=10 (without any calculation)     
  99.           
  100.     rLCDSADDR1= (0x1<<27) | ( ((U32)Buffer4>>22)<<21 ) | M5D((U32)Buffer4>>1);   
  101.     //4-gray mode, LCDBANK(4MB对齐), LCDBASEU(2B对齐)    
  102.        
  103.     rLCDSADDR2= M5D((((U32)Buffer4+(SCR_XSIZE*LCD_YSIZE*2/8))>>1)) | (MVAL<<21);   
  104.     //LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,BSWP disable,LCDBASEL(2B对齐), MVAL    
  105.        
  106.     rLCDSADDR3= (LCD_XSIZE*2/16) | ( ((SCR_XSIZE-LCD_XSIZE)*2/16)<<9 );   
  107.     //LCD_XSIZE是实屏宽度,SCR_XSIZE是虚屏宽度,OFFSIZE, PAGEWIDTH都是以16位为单位    
  108.    
  109.     //The following value has to be changed for better display.    
  110.     //Select 4 levels among 16 gray levels.    
  111.     rBLUELUT=0xfa40;    
  112.     rDITHMODE=0x0;   
  113.     rDP1_2 =0xa5a5;         
  114.     rDP4_7 =0xba5da65;   
  115.     rDP3_5 =0xa5a5f;   
  116.     rDP2_3 =0xd6b;   
  117.     rDP5_7 =0xeb7b5ed;   
  118.     rDP3_4 =0x7dbe;   
  119.     rDP4_5 =0x7ebdf;   
  120.     rDP6_7 =0x7fdfbfe;   
  121.    
  122.     rLCDCON1=(1)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G4<<12);   
  123.     //enable ENVID,4B_SNGL_SCAN,WDLY=16clk,WLH=16clk,    
  124.     break;   
  125.    
  126.     case 16:   
  127.     if((U32)Buffer16==0)   
  128.     {   
  129.         //The total  memory should be inside 4MB.    
  130.         //For example, if total memory is 8MB, the  memory     
  131.         //should be in 0xc000000~0xc3fffff or c400000~c7fffff.    
  132.         //But, the following code doesn't meet this condition(4MB)     
  133.         //if the code size & location is changed..    
  134.         Buffer16=(unsigned int (*)[SCR_XSIZE/8])malloc(ARRAY_SIZE_G16);    
  135.     }   
  136.    
  137.     //The following value has to be changed for better display.    
  138.     rDITHMODE=0x12210;//芯片手册规定的值        
  139.     rDP1_2 =0xa5a5;         
  140.     rDP4_7 =0xba5da65;   
  141.     rDP3_5 =0xa5a5f;   
  142.     rDP2_3 =0xd6b;   
  143.     rDP5_7 =0xeb7b5ed;   
  144.     rDP3_4 =0x7dbe;   
  145.     rDP4_5 =0x7ebdf;   
  146.     rDP6_7 =0x7fdfbfe;   
  147.    
  148.    
  149.    
  150.     rLCDCON1=(0)|(1<<1)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G16<<12);   
  151.     //disable ENVID,INVVD invert,4B_SNGL_SCAN,WDLY=16clk,WLH=16clk,    
  152.        
  153.     rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);     
  154.     //LINEBLANK=10 (without any calculation)     
  155.        
  156.     rLCDSADDR1= (0x2<<27) | ( ((U32)Buffer16>>22)<<21 ) | M5D((U32)Buffer16>>1);   
  157.     // 16-gray, LCDBANK(4MB对齐), LCDBASEU(2B对齐)    
  158.        
  159.     rLCDSADDR2= M5D((((U32)Buffer16+(SCR_XSIZE*LCD_YSIZE*4/8))>>1)) | (MVAL<<21);   
  160.     //LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,BSWP disable,LCDBASEL(2B对齐), MVAL    
  161.        
  162.     rLCDSADDR3= (LCD_XSIZE*4/16) | ( ((SCR_XSIZE-LCD_XSIZE)*4/16)<<9 );   
  163.     //LCD_XSIZE是实屏宽度,SCR_XSIZE是虚屏宽度,OFFSIZE, PAGEWIDTH都是以16位为单位    
  164.        
  165.     rLCDCON1=(1)|(1<<1)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G16<<12);   
  166.     //enable ENVID, FS LCD set    
  167.     break;   
  168.    
  169.     case 256:   
  170.     if((U32)Buffer256==0)   
  171.     {   
  172.         //The total  memory should be inside 4MB.    
  173.         //For example, if total memory is 8MB, the  memory     
  174.         //should be in 0xc000000~0xc3fffff or c400000~c7fffff.    
  175.         //But, the following code doesn't meet this condition(4MB)     
  176.         //if the code size & location is changed..    
  177.         Buffer256=(unsigned int (*)[SCR_XSIZE/4])malloc(ARRAY_SIZE_COLOR);    
  178.     }   
  179.    
  180.     rLCDCON1=(0)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);   
  181.     //disable ENVID,8B_SNGL_SCAN,WDLY=16clk,WLH=16clk,    
  182.        
  183.     rLCDCON2=(LINEVAL)|(HOZVAL_COLOR<<10)|(10<<21);     
  184.     //LINEBLANK=10 (without any calculation)     
  185.            
  186.     rLCDSADDR1= (0x3<<27) | ( ((U32)Buffer256>>22)<<21 ) | M5D((U32)Buffer256>>1);   
  187.     //256-color, LCDBANK(4MB对齐), LCDBASEU(2B对齐)    
  188.        
  189.     rLCDSADDR2= M5D((((U32)Buffer256+(SCR_XSIZE*LCD_YSIZE*8/8))>>1)) | (MVAL<<21);   
  190.     //LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,BSWP disable,LCDBASEL(2B对齐), MVAL    
  191.        
  192.     rLCDSADDR3= (LCD_XSIZE*8/16) | ( ((SCR_XSIZE-LCD_XSIZE)*8/16)<<9 );   
  193.     //LCD_XSIZE是实屏宽度,SCR_XSIZE是虚屏宽度,OFFSIZE, PAGEWIDTH都是以16位为单位    
  194.    
  195.     //The following value has to be changed for better display.    
  196.     rREDLUT  =0xfdb96420;   
  197.     rGREENLUT=0xfdb96420;   
  198.     rBLUELUT =0xfb40;   
  199.    
  200.     rDITHMODE=0x0;   
  201.     rDP1_2 =0xa5a5;         
  202.     rDP4_7 =0xba5da65;   
  203.     rDP3_5 =0xa5a5f;   
  204.     rDP2_3 =0xd6b;   
  205.     rDP5_7 =0xeb7b5ed;   
  206.     rDP3_4 =0x7dbe;   
  207.     rDP4_5 =0x7ebdf;   
  208.     rDP6_7 =0x7fdfbfe;   
  209.    
  210.     rLCDCON1=(1)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);   
  211.     //enable ENVID,8B_SNGL_SCAN,WDLY=16clk,WLH=16clk,    
  212.     break;   
  213.    
  214.     default:   
  215.             break;   
  216.     }      
  217. }   
  218.    
  219.    
  220. /************************************************************  
  221. *函数名:Lcd_MoveViewPort  
  222. *功能:实现滚屏  
  223. *入口参数:(vx,vy)---视口左上角坐标  
  224.            depth---单色模式为1,  
  225.                 ---4级灰度模式为4  
  226.                 ---16级灰度模式为16  
  227.                 ---彩色模式为256  
  228. *出口参数:无  
  229. ************************************************************/   
  230. void Lcd_MoveViewPort(int vx,int vy,int depth)   
  231. {   
  232.     U32 addr;   
  233.     switch(depth)   
  234.     {   
  235.     case 1:   
  236.         // LCDBASEU,LCDBASEL register has to be changed before 12 words before the end of VLINE.    
  237.         // In mono mode, x=320 is 10 words, So, We can't change LCDBASEU,LCDBASEL     
  238.         // during LINECNT=1~0 at mono mode.     
  239.    
  240.         //The processor mode should be superviser mode.      
  241.         DisableInterrupt();    
  242.    
  243.     #if (LCD_XSIZE<512)//LCD_XSIZE是实屏宽度,SCR_XSIZE是虚屏宽度    
  244.         while((rLCDCON1>>22)<=1); // if x<512    
  245.     #else       
  246.         while((rLCDCON1>>22)==0); // if x>512 ((12+4)*32)     
  247.     #endif    
  248.    
  249.     addr=(U32)Buffer1+(vx/8)+vy*(SCR_XSIZE*1/8);   
  250.     rLCDSADDR1= (0x0<<27) | ( (addr>>22)<<21 ) | M5D(addr>>1);   
  251.     //LCD_XSIZE是实屏宽度,SCR_XSIZE是虚屏宽度,monochrome, LCDBANK 4MB对齐, LCDBASEU 2B对齐    
  252.        
  253.     rLCDSADDR2= M5D( ((addr+(SCR_XSIZE*LCD_YSIZE*1/8))>>1) ) | (MVAL<<21);   
  254.     //LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,LCDBASEL 2B对齐    
  255.    
  256.     EnableInterrupt();   
  257.     break;   
  258.    
  259.     case 4:   
  260.         //The processor mode should be superviser mode.      
  261.         DisableInterrupt();    
  262.    
  263.         #if (LCD_XSIZE<256)//LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,    
  264.            while((rLCDCON1>>22)<=1); // if x<256    
  265.         #else       
  266.            while((rLCDCON1>>22)==0); // if x>256    
  267.         #endif    
  268.        
  269.         addr=(U32)Buffer4+(vx/4)+vy*(SCR_XSIZE*2/8);   
  270.         rLCDSADDR1= (0x1<<27) | ( (addr>>22)<<21 ) | M5D(addr>>1);   
  271.         //4-gray, LCDBANK 4MB对齐, LCDBASEU 2B对齐    
  272.        
  273.         rLCDSADDR2= M5D(((addr+(SCR_XSIZE*LCD_YSIZE*2/8))>>1)) | (MVAL<<21);   
  274.         //LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,LCDBASEL 2B对齐    
  275.    
  276.         EnableInterrupt();   
  277.         break;   
  278.    
  279.     case 16:   
  280.         //The processor mode should be superviser mode.      
  281.         DisableInterrupt();    
  282.    
  283.         #if (LCD_XSIZE<128)//LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,    
  284.            while((rLCDCON1>>22)<=1); // if x<128    
  285.         #else       
  286.            while((rLCDCON1>>22)==0); // if x>128    
  287.         #endif    
  288.         addr=(U32)Buffer16+(vx/2)+vy*(SCR_XSIZE*4/8);   
  289.         rLCDSADDR1= (0x2<<27) | ( (addr>>22)<<21 ) | M5D(addr>>1);   
  290.         //LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,16-gray, LCDBANK 4MB对齐, LCDBASEU 2B对齐    
  291.            
  292.         rLCDSADDR2= M5D(((addr+(SCR_XSIZE*LCD_YSIZE*4/8))>>1)) | (MVAL<<21);   
  293.         //LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,LCDBASEL 2B对齐    
  294.    
  295.         EnableInterrupt();   
  296.         break;   
  297.    
  298.     case 256:   
  299.         //The processor mode should be superviser mode.      
  300.         DisableInterrupt();    
  301.    
  302.         #if (LCD_XSIZE<64)//LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,    
  303.            while((rLCDCON1>>22)<=1); // if x<64    
  304.         #else       
  305.            while((rLCDCON1>>22)==0); // if x>64    
  306.         #endif    
  307.         addr=(U32)Buffer256+(vx/1)+vy*(SCR_XSIZE*8/8);   
  308.         rLCDSADDR1= (0x3<<27) | ( (addr>>22)<<21 ) | M5D(addr>>1);   
  309.         //LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,256-color, LCDBANK 4MB对齐, LCDBASEU 2B对齐    
  310.         rLCDSADDR2= M5D(((addr+(SCR_XSIZE*LCD_YSIZE*8/8))>>1)) | (MVAL<<21);   
  311.         //LCD_YSIZE是实屏高度,SCR_XSIZE是虚屏宽度,LCDBASEL 2B对齐    
  312.            
  313.         EnableInterrupt();   
  314.         break;   
  315.     }   
  316. }       
  317.    
  318. /************************************************************  
  319. *函数名:Lcd_DispON  
  320. *功能:打开LCD显示屏  
  321. *入口参数:无  
  322. *出口参数:无  
  323. ************************************************************/   
  324. void Lcd_DispON(void)   
  325. {   
  326.     Delay(5000);   
  327.     rPDATC = ( rPDATC & (~(1<<8)) );   
  328.     Delay(5000);   
  329. }   
  330.    
  331. /************************************************************  
  332. *函数名:Lcd_DispOFF  
  333. *功能:关闭LCD显示屏  
  334. *入口参数:无  
  335. *出口参数:无  
  336. ************************************************************/   
  337. void Lcd_DispOFF(void)   
  338. {   
  339.     Delay(5000);   
  340.     rPDATC = ( rPDATC | (1<<8) );   
  341.     Delay(5000);   
  342. }   
  343.    
  344. /************************************************************  
  345. *函数名:Lcd_PowerReset  
  346. *功能:LCD显示屏上电复位  
  347. *入口参数:无  
  348. *出口参数:无  
  349. ************************************************************/   
  350. void Lcd_PowerReset(void)      
  351. {   
  352.     U8 i;   
  353.     rPDATC = ( rPDATC | 3<<4 );       //crtl=1,adj=1    
  354.     for(i=0;i<1;i++);   
  355.     rPDATC = ( rPDATC & (~(1<<5)) );  //ctrl=0    
  356.     for(i=0;i<2;i++);   
  357.     rPDATC = ( rPDATC | 1<<5 );       //ctrl=1    
  358.     for(i=0;i<1;i++);   
  359.     rPDATC = ( rPDATC & (~(1<<4)) );  //adj=0    
  360.    
  361. }   
  362.    
  363. /************************************************************  
  364. *函数名:Lcd_PowerUp  
  365. *功能:LCD显示屏上电  
  366. *入口参数:无  
  367. *出口参数:无  
  368. ************************************************************/   
  369. void Lcd_PowerUp(void)   
  370. {   
  371.     U8 i;   
  372.     rPDATC = ( rPDATC | 2<<4 );       //ctrl=1,adj=0    
  373.     for(i=0;i<2;i++);   
  374.     rPDATC = ( rPDATC | 1<<4 );       //adj=1    
  375.     for(i=0;i<1;i++);   
  376.     rPDATC = ( rPDATC & (~(1<<4)) );  //adj=0    
  377.     for(i=0;i<2;i++);   
阅读(450) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~