Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4251611
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: 嵌入式

2011-06-29 10:41:47

工程代码:  10_spi模拟彩屏_1.rar  
彩屏:

很好的两个参考资料:
http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=4493558&bbs_page_no=185&bbs_id=9999
http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=4742238&bbs_page_no=2&bbs_id=3020


物理结构:
VCC GND  RST RS SDIN SCLK CS


说明:
       循环显示  纯黑,纯红
       使用 模拟spi 功能,  GPIOC ,APB2, 将APB2的频率调到 72MHZ。
  1. #ifndef __LCD_H
  2. #define __LCD_H

  3. #include "stm32f10x.h"
  4. #include "delay.h"

  5. #define TFT_PORT GPIOC     //LCD 选择管脚
  6. #define TFT_RST GPIO_Pin_6 //复位
  7. #define TFT_RS GPIO_Pin_7 //寄存器选择
  8. #define TFT_SDIN GPIO_Pin_8 //数据传输
  9. #define TFT_SCLK GPIO_Pin_9 //CLK时钟
  10. #define TFT_CS      GPIO_Pin_10 //片选信号

  11. #define Set_Rst TFT_PORT->BSRR = TFT_RST; //复位1
  12. #define Clr_Rst TFT_PORT->BRR = TFT_RST; //复位0

  13. #define Set_Rs TFT_PORT->BSRR = TFT_RS; //寄存器选择1
  14. #define Clr_Rs TFT_PORT->BRR = TFT_RS; //寄存器选择0

  15. #define Set_Dat TFT_PORT->BSRR = TFT_SDIN;//数据 高
  16. #define Clr_Dat TFT_PORT->BRR = TFT_SDIN;//数据 低

  17. #define Set_Clk TFT_PORT->BSRR = TFT_SCLK;//时钟 高
  18. #define Clr_Clk TFT_PORT->BRR = TFT_SCLK;//时钟 低

  19. #define Set_Cs TFT_PORT->BSRR = TFT_CS; //片选信号 高
  20. #define Clr_Cs TFT_PORT->BRR = TFT_CS; //片选信号 低

  21. void LCD18_Init(void);    //初始化 LCD GPIO管脚,彩屏寄存器
  22. void LCD18_DataWrite_IC(u8 dat);
  23. void LCD18_DataWrite(u8 LCD_DataH,u8 LCD_DataL);
  24. void LCD18_Dsp_Single_Colour(u8 DH, u8 DL);
  25. void write_command (u8 cmd);
  26. void write_data (u8 data);

  27. #endif

  1. #include "lcd.h"

  2. void LCD18_Init(void)
  3. {
  4.     GPIO_InitTypeDef GPIO_InitStructure;
  5.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

  6.     GPIO_InitStructure.GPIO_Pin = TFT_SCLK | TFT_SDIN | TFT_CS | TFT_RS | TFT_RST;
  7.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  8.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  9.     GPIO_Init(GPIOC, &GPIO_InitStructure);


  10.     Clr_Rst;
  11.     delay_ms(10);
  12.     Set_Rst;
  13.     delay_ms(20);
  14.     //-----LCD Software Reset------//
  15.     write_command(0x01); //Sofeware setting
  16.     delay_ms(10);
  17.     write_command(0x11);//Sleep out
  18.     delay_ms(120);
  19.     //ST7735R Frame Rate
  20.     write_command(0xB1);
  21.     write_data(0x01);
  22.     write_data(0x2C);
  23.     write_data(0x2D);
  24.     write_command(0xB2);
  25.     write_data(0x01);
  26.     write_data(0x2C);
  27.     write_data(0x2D);
  28.     write_command(0xB3);
  29.     write_data(0x01);
  30.     write_data(0x2C);
  31.     write_data(0x2D);
  32.     write_data(0x01);
  33.     write_data(0x2C);
  34.     write_data(0x2D);
  35.     //------------------------------------End ST7735R Frame Rate-----------------------------------------//
  36.     write_command(0xB4);//Column inversion
  37.     write_data(0x07);
  38.     //------------------------------------ST7735R Power Sequence-----------------------------------------//
  39.     write_command(0xC0);
  40.     write_data(0xA2);
  41.     write_data(0x02);
  42.     write_data(0x84);
  43.     write_command(0xC1);
  44.     write_data(0xC5);
  45.     write_command(0xC2);
  46.     write_data(0x0A);
  47.     write_data(0x00);
  48.     write_command(0xC3);
  49.     write_data(0x8A);
  50.     write_data(0x2A);
  51.     write_command(0xC4);
  52.     write_data(0x8A);
  53.     write_data(0xEE);
  54.     //---------------------------------End ST7735R Power Sequence-------------------------------------//
  55.     write_command(0xC5);//VCOM
  56.     write_data(0x0E);
  57.     write_command(0x36);//MX, MY, RGB mode
  58.     write_data(0xC8);
  59.     //------------------------------------ST7735R Gamma Sequence-----------------------------------------//
  60.     write_command(0xe0);
  61.     write_data(0x02);
  62.     write_data(0x1c);
  63.     write_data(0x07);
  64.     write_data(0x12);
  65.     write_data(0x37);
  66.     write_data(0x32);
  67.     write_data(0x29);
  68.     write_data(0x2d);
  69.     write_data(0x29);
  70.     write_data(0x25);
  71.     write_data(0x2b);
  72.     write_data(0x39);
  73.     write_data(0x00);
  74.     write_data(0x01);
  75.     write_data(0x03);
  76.     write_data(0x10);
  77.     write_command(0xe1);
  78.     write_data(0x03);
  79.     write_data(0x1d);
  80.     write_data(0x07);
  81.     write_data(0x06);
  82.     write_data(0x2e);
  83.     write_data(0x2c);
  84.     write_data(0x29);
  85.     write_data(0x2d);
  86.     write_data(0x2e);
  87.     write_data(0x2e);
  88.     write_data(0x37);
  89.     write_data(0x3f);
  90.     write_data(0x00);
  91.     write_data(0x00);
  92.     write_data(0x02);
  93.     write_data(0x10);
  94.     write_command(0x2A);
  95.     write_data(0x00);
  96.     write_data(0x02);
  97.     write_data(0x00);
  98.     write_data(0x81);
  99.     
  100.     write_command(0x2B);
  101.     write_data(0x00);
  102.     write_data(0x01);
  103.     write_data(0x00);
  104.     write_data(0xA0);
  105.     //------------------------------------End ST7735R Gamma Sequence-----------------------------------------//
  106.     
  107.     write_command(0x3A);
  108.     write_data(0x05);
  109.     write_command(0x29);//Display on
  110.     
  111.     delay_ms(10);
  112.     
  113. //    Background_color_H = 0xFF; // 指定背景色为白色
  114. //    Background_color_L = 0xFF;
  115.     
  116. //    Text_color_H = 0x00; // 指定文字颜色为红色
  117. //    Text_color_L = 0x00;
  118.     
  119. //    Disp_Transparent = 0;
  120. }

  121. void LCD18_DataWrite_IC(u8 dat)
  122. {
  123.     u8 i=8;
  124.     Clr_Cs;
  125.     Set_Rs;
  126.     while(i--)
  127.     {
  128.         Clr_Clk;
  129.         if(dat & 0x80)
  130.         {
  131.             Set_Dat;
  132.         }/* MSB first */
  133.         else
  134.         {
  135.             Clr_Dat;
  136.         }
  137.         Set_Clk;
  138.         dat <<= 1; /* Data shift */
  139.     }
  140.     Set_Cs;
  141. }

  142. void LCD18_DataWrite(u8 LCD_DataH,u8 LCD_DataL)
  143. {
  144.     LCD18_DataWrite_IC(LCD_DataH);
  145.     LCD18_DataWrite_IC(LCD_DataL);
  146. }

  147. void LCD18_Dsp_Single_Colour(u8 DH, u8 DL)
  148. {
  149.  u8 i,j;
  150.  //RamAdressSet();
  151.  for (i=0;i<160;i++)
  152.     for (j=0;j<128;j++)
  153.         LCD18_DataWrite(DH,DL);
  154. }
  155. void write_command (u8 cmd)
  156. {
  157.     u8 i=8;
  158.     Clr_Cs;
  159.     Clr_Rs;
  160.     while (i--)
  161.     {
  162.         Clr_Clk;
  163.         if(cmd & 0x80)
  164.         {
  165.             Set_Dat;
  166.         }/* MSB first */
  167.         else
  168.         {
  169.             Clr_Dat;
  170.         }
  171.         Set_Clk;
  172.         cmd <<= 1; /* Data shift */
  173.     }
  174.     Set_Cs;
  175. }

  176. void write_data (u8 data)
  177. {
  178.     u8 i=8;
  179.     Clr_Cs;
  180.     Set_Rs;
  181.     while(i--)
  182.     {
  183.         Clr_Clk;
  184.         if(data & 0x80)
  185.         {
  186.             Set_Dat;
  187.         }/* MSB first */
  188.         else
  189.         {
  190.             Clr_Dat;
  191.         }
  192.         Set_Clk;
  193.         data <<= 1; /* Data shift */
  194.     }
  195.     Set_Cs;
  196. }

  1. int main()
  2. {    
  3.     RCC_Configuration();
  4.     delay_init();
  5. //    LED_Init();
  6.     USART1_GPIO_Configuration();
  7.     USART1_Configuration();
  8.         
  9.     LCD18_Init();

  10.     delay_s(2);//usart 发送显示开始
  11.     usart1_sendchar(65);//A字符 asicc码65


  12.     while(1)
  13.     {
  14.         write_command(0x2C);

  15.         LCD18_Dsp_Single_Colour(0x00,0x00);//黑色        
  16.         delay_ms(500);

  17.         LCD18_Dsp_Single_Colour(0xf8,0x00);//红色
  18.         delay_ms(500);

  19.         LCD18_Dsp_Single_Colour(0xff,0xff);//白色
  20.           delay_ms(500);
  21.          
  22.      LCD18_Dsp_Single_Colour(0x07,0xe0);//绿色
  23.      delay_ms(500);    
  24.          
  25.      LCD18_Dsp_Single_Colour(0x00,0x1f);//蓝色
  26.      delay_ms(500);    
  27.     }
  28.     return 0;
  29. }








阅读(1058) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~