Advertisement
RogerTango

LCD specific initialization code.c

Feb 18th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.58 KB | None | 0 0
  1. //Initialization for 7inch 800x480 SSD1963
  2. //LCD ID READ: 01-57-61-01-FF
  3. //coldtears electronics
  4. //http://coldtearselectronics.wikispace.com
  5.  
  6. unsigned int  HDP=799; //Horizontal Display Period
  7. unsigned int  HT=1000; //Horizontal Total
  8. unsigned int  HPS=51;  //LLINE Pulse Start Position
  9. unsigned int  LPS=3;   //   Horizontal Display Period Start Position
  10. unsigned char HPW=8;   //   LLINE Pulse Width
  11. unsigned int  VDP=479;  //Vertical Display Period
  12. unsigned int  VT=530;   //Vertical Total
  13. unsigned int  VPS=24;   //  LFRAME Pulse Start Position
  14. unsigned int  FPS=23;   //Vertical Display Period Start Positio
  15. unsigned char   VPW=3;  // LFRAME Pulse Width
  16.  
  17. #define White          0xFFFF
  18. #define Black          0x0000
  19. #define Blue           0x001F
  20. #define Blue2          0x051F
  21. #define Red            0xF800
  22. #define Magenta        0xF81F
  23. #define Green          0x07E0
  24. #define Cyan           0x7FFF
  25. #define Yellow         0xFFE0
  26. #define Gray           0x2104
  27. #define PURPLE         0xF11F
  28. #define Orange         0xFD20
  29.  
  30. void LCD_Init(void)
  31. {
  32.  
  33.     LCD_RST_0();
  34.     _delay_ms(500);
  35.     LCD_RST_1();
  36.     LCD_CS_1();
  37.     LCD_RD_1();
  38.     LCD_RW_1();
  39.     LCD_RS_1();
  40.  
  41.     _delay_ms(100);
  42.     LCD_CS_0();
  43.     LCD_Instruction(0x00E2);   
  44.     LCD_Data(0x0023);
  45.     LCD_Data(0x0002);
  46.     LCD_Data(0x0004);
  47.  
  48.     LCD_Instruction(0x00E0);  // PLL enable
  49.     LCD_Data(0x0001);
  50.     _delay_ms(1);  
  51.     LCD_Instruction(0x00E0);
  52.     LCD_Data(0x0003);
  53.     _delay_ms(5);  
  54.     LCD_Instruction(0x0001);  // software reset
  55.     _delay_ms(5);  
  56.     LCD_Instruction(0x00E6);   
  57.     LCD_Data(0x0004);
  58.     LCD_Data(0x0093);
  59.     LCD_Data(0x00e0);  
  60.  
  61.     LCD_Instruction(0x00B0);    //LCD SPECIFICATION
  62.     LCD_Data(0x0000);
  63.     LCD_Data(0x0000);
  64.     LCD_Data((HDP>>8)&0X00FF);  //Set HDP
  65.     LCD_Data(HDP&0X00FF);
  66.     LCD_Data((VDP>>8)&0X00FF);  //Set VDP
  67.     LCD_Data(VDP&0X00FF);
  68.     LCD_Data(0x0000);
  69.  
  70.     LCD_Instruction(0x00B4);    //HSYNC
  71.     LCD_Data((HT>>8)&0X00FF);  //Set HT
  72.     LCD_Data(HT&0X00FF);
  73.     LCD_Data((HPS>>8)&0X00FF);  //Set HPS
  74.     LCD_Data(HPS&0X00FF);
  75.     LCD_Data(HPW);             //Set HPW
  76.     LCD_Data((LPS>>8)&0X00FF);  //Set HPS
  77.     LCD_Data(LPS&0X00FF);
  78.     LCD_Data(0x0000);
  79.  
  80.     LCD_Instruction(0x00B6);    //VSYNC
  81.     LCD_Data((VT>>8)&0X00FF);   //Set VT
  82.     LCD_Data(VT&0X00FF);
  83.     LCD_Data((VPS>>8)&0X00FF);  //Set VPS
  84.     LCD_Data(VPS&0X00FF);
  85.     LCD_Data(VPW);             //Set VPW
  86.     LCD_Data((FPS>>8)&0X00FF);  //Set FPS
  87.     LCD_Data(FPS&0X00FF);      
  88.        
  89.     LCD_Instruction(0x00BA);
  90.     LCD_Data(0x000F);    //GPIO[3:0] out 1
  91.  
  92.     LCD_Instruction(0x00B8);
  93.     LCD_Data(0x0007);    //GPIO3=input, GPIO[2:0]=output
  94.     LCD_Data(0x0001);    //GPIO0 normal
  95.  
  96.     LCD_Instruction(0x0036); //rotation
  97.     LCD_Data(0x0000);      
  98.        
  99.     LCD_Instruction(0x00F0); //pixel data interface
  100.     LCD_Data(0x0003);      
  101.     _delay_ms(5);          
  102.  
  103.     LCD_Instruction(0x0026); //display on
  104.     LCD_Data(0x0008);
  105.  
  106.     LCD_Instruction(0x0029); //display on
  107.  
  108.     LCD_Instruction(0x00BE); //set PWM for B/L
  109.     LCD_Data(0x0001);
  110.     LCD_Data(0x0088); //medium backlight
  111.     LCD_Data(0x0001);
  112.     LCD_Data(0x00F0);
  113.     LCD_Data(0x0000);
  114.     LCD_Data(0x0000);
  115.      
  116.     LCD_CS_1();
  117.     LCD_RD_1();
  118.     LCD_RW_1();
  119.     LCD_RS_1();
  120. }
  121.  
  122. void adjust_backlight()
  123. {
  124. //  if(PWM_Value==255) PWM_Value=0;
  125. //  else if (PWM_Value==0) PWM_Value=255;
  126.     LCD_CS_0();
  127.     LCD_Instruction(0x00BE); //set PWM for B/L
  128.     LCD_Data(0x0001);
  129.     LCD_Data(PWM_Value);
  130.     LCD_Data(0x0001);
  131.     LCD_Data(0x00F0);
  132.     LCD_Data(0x0000);
  133.     LCD_Data(0x0000);
  134.     LCD_CS_1();
  135. }
  136. void LCD_Set_AREA(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
  137. {
  138.   LCD_CS_0();
  139.   LCD_Instruction(0x002A);LCD_Data(x1>>8);
  140.   LCD_Data(0x00FF&x1); LCD_Data(x2>>8);
  141.   LCD_Data(0x00FF&x2);      
  142.  
  143.   LCD_Instruction(0x002B);LCD_Data(y1>>8);
  144.   LCD_Data(0x00FF&y1); LCD_Data(y2>>8);
  145.   LCD_Data(0x00FF&y2);
  146.   LCD_Instruction(WriteDatatoGRAM);
  147.   LCD_CS_1();                            
  148. }
  149. void show_colour_bar(void)
  150. {
  151.     unsigned int i,j;
  152.     LCD_CS_0();
  153.     LCD_Instruction(0x002C);
  154.   for(i=0;i<480;i++)
  155.   {
  156.     for(j=0;j<800;j++)
  157.     {
  158.       if(i>400)LCD_Data(White);
  159.       else if(i>350)LCD_Data(Blue);
  160.       else if(i>300)LCD_Data(Green);
  161.       else if(i>250)LCD_Data(Cyan);
  162.       else if(i>200)LCD_Data(Red);
  163.       else if(i>150)LCD_Data(Blue2);     
  164.       else if(i>100)LCD_Data(Magenta);
  165.       else if(i>50)LCD_Data(Yellow);
  166.       else LCD_Data(Black);
  167.     }    
  168.   }
  169.  
  170.     LCD_CS_1();
  171. }
  172.  
  173. void LCD_Fill(unsigned long color)
  174. {
  175.     unsigned int j,m;
  176.     unsigned long ia;
  177.     LCD_CS_0();
  178.     LCD_Instruction(0x002C);
  179.     for(ia=0;ia<384000;ia++)
  180.      {
  181.        
  182.              LCD_Data(color);
  183.       }
  184.      LCD_CS_1();
  185.  
  186. }
  187. int main(void)
  188. {
  189. _delay_ms(100);    
  190. Init_Coms();
  191. init_AVR();
  192. LCD_Init();
  193. while(1)
  194. {  
  195. _delay_ms(400);
  196. LCD_Set_AREA(0,0,799,479);
  197. show_colour_bar();
  198. LCD_Fill(Black);
  199. _delay_ms(400);
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement