久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2908|回復: 0
打印 上一主題 下一主題
收起左側

stm32 9328彩色26萬色液晶驅動

[復制鏈接]
跳轉到指定樓層
樓主
ID:82781 發表于 2015-6-14 01:30 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
  1. #include "stm32f10x.h"
  2. #define SET_CS GPIOD->BSRR=0x00001000
  3. #define CLR_CS GPIOD->BRR=0x00001000
  4. #define SET_WR GPIOD->BSRR=0x00004000
  5. #define CLR_WR GPIOD->BRR=0x00004000
  6. #define SET_RD GPIOD->BSRR=0x00008000
  7. #define CLR_RD GPIOD->BRR=0x00008000
  8. #define SET_RS GPIOD->BSRR=0x00002000
  9. #define CLR_RS GPIOD->BRR=0x00002000

  10. GPIO_InitTypeDef GPIO_InitStructure;
  11. void mysysinit(void);//系統時鐘初始
  12. void my_USART_init(void);//初始化
  13. void my_send_byte(unsigned char send_date); //發送一個字節
  14. void delay1us(uint32_t);//延時1微秒程序
  15. void init_STM32(void); //開機初始化
  16. uint16_t read_LCD_register(uint16_t reg);//讀出指定的液晶寄存器,
  17. void wr_cmd_date(uint16_t reg,uint16_t date); //寫入指定的寄存器值
  18. void LCD9328_init(void);//9328初始化
  19. void lcm_coordinate(uint16_t x1,uint16_t y1 );//掃描地
  20. int main(void)
  21. {
  22. uint32_t numb;
  23.       uint16_t  x,y,buff_sd_tft;
  24.    init_STM32();///開機初始化時鐘,初始化串口
  25.   // delay1us(20000);
  26.   LCD9328_init();
  27. // delay1us(10000);
  28.    buff_sd_tft=0x0000;
  29.    y=0;x=0;//lcm_coordinate(x,y);
  30.   while(1)
  31.   {

  32.    
  33.         
  34.     //lcm_coordinate(x,y);
  35.          wr_cmd_date(0x22,buff_sd_tft);
  36.          
  37.          //delay1us(200);                     
  38.       numb++;
  39.     if(numb==76800){numb=0;buff_sd_tft=(buff_sd_tft+215);}
  40.    

  41.   }


  42. /* d=read_LCD_register(0x20); //讀液晶的00寄存器,判斷是9525(9328)|9320
  43.     e=d;
  44.    a=e;
  45.    c=(d>>8);
  46.    my_send_byte(c);
  47.    my_send_byte(a);
  48.     while(1);*/




  49. }
  50. void lcm_coordinate(uint16_t x1,uint16_t y1 )//掃描地
  51. {

  52.   wr_cmd_date(0x0050,x1);
  53.   wr_cmd_date(0x0051,x1);
  54.   wr_cmd_date(0x0052,y1);
  55.   wr_cmd_date(0x0053,y1);
  56.   wr_cmd_date(0x0020,x1);
  57.   wr_cmd_date(0x0021,y1);

  58. }
  59. void LCD9328_init()//橫屏初始
  60. {

  61. delay1us(150000);
  62.   wr_cmd_date(0x0001,0x0100); //s1-s720
  63.   wr_cmd_date(0x0002,0x0700);
  64.   wr_cmd_date(0x0003,0x1030);
  65. wr_cmd_date(0x0004,0x0000);
  66.   wr_cmd_date(0x0008,0x0207);
  67.   wr_cmd_date(0x0009,0x0000);
  68.   wr_cmd_date(0x000A,0x0000);
  69.   wr_cmd_date(0x000C,0x0000);
  70.   wr_cmd_date(0x000D,0x0000);
  71. wr_cmd_date(0x000F,0x0000);
  72. //power on sequence VGHVGL
  73.   wr_cmd_date(0x0010,0x0000);  
  74.   wr_cmd_date(0x0011,0x0007);
  75.   wr_cmd_date(0x0012,0x0000);
  76.   wr_cmd_date(0x0013,0x0000);
  77. //vgh
  78.   wr_cmd_date(0x0010,0x1290);  
  79.   wr_cmd_date(0x0011,0x0227);
  80. delay1us(800000);
  81. //vregiout
  82.   wr_cmd_date(0x0012,0x001d); //0x001b
  83. delay1us(800000);
  84. //vom amplitude
  85.   wr_cmd_date(0x0013,0x1500);
  86. delay1us(800000);
  87. //vom H
  88.   wr_cmd_date(0x0029,0x0018);
  89.   wr_cmd_date(0x002B,0x000D);

  90. //gamma
  91.   wr_cmd_date(0x0030,0x0004);
  92.   wr_cmd_date(0x0031,0x0307);
  93.   wr_cmd_date(0x0032,0x0002);// 0006
  94.   wr_cmd_date(0x0035,0x0206);
  95.   wr_cmd_date(0x0036,0x0408);
  96.   wr_cmd_date(0x0037,0x0507);
  97.   wr_cmd_date(0x0038,0x0204);//0200
  98.   wr_cmd_date(0x0039,0x0707);
  99.   wr_cmd_date(0x003C,0x0405);// 0504
  100.   wr_cmd_date(0x003D,0x0F02);
  101. //ram
  102.   wr_cmd_date(0x0050,0x0000);
  103.   wr_cmd_date(0x0051,0x00EF);
  104.   wr_cmd_date(0x0052,0x0000);
  105.   wr_cmd_date(0x0053,0x013F);
  106.   wr_cmd_date(0x0060,0xA700);
  107.   wr_cmd_date(0x0061,0x0001);
  108.   wr_cmd_date(0x006A,0x0000);
  109. //
  110.   wr_cmd_date(0x0080,0x0000);
  111.   wr_cmd_date(0x0081,0x0000);
  112.   wr_cmd_date(0x0082,0x0000);
  113.   wr_cmd_date(0x0083,0x0000);
  114.   wr_cmd_date(0x0084,0x0000);
  115.   wr_cmd_date(0x0085,0x0000);
  116. //
  117.   wr_cmd_date(0x0090,0x0010);
  118.   wr_cmd_date(0x0093,0x0003);
  119.   wr_cmd_date(0x0095,0x0110);
  120.   wr_cmd_date(0x0097,0x0000);
  121.   wr_cmd_date(0x0098,0x0000);
  122.   wr_cmd_date(0x0007,0x0133);
  123. }
  124. void wr_cmd_date(uint16_t reg,uint16_t date)
  125. {

  126.   GPIOE->CRL=0x33333333; //數據口轉換成輸出
  127.   GPIOE->CRH=0x33333333; //數據口轉換成輸出

  128.   CLR_CS;
  129.   CLR_RS;
  130.   SET_RD;
  131.   CLR_WR;
  132.   GPIOE->ODR=reg;//GPIO_Write(GPIOE, reg);// //寫入命令
  133.   SET_WR;
  134.   SET_RS;
  135.   //delay_1us(1);
  136.   CLR_WR;
  137. GPIOE->ODR=date;//GPIO_Write(GPIOE, date); // //寫入命令
  138.   SET_WR;
  139.   SET_CS;

  140. }
  141. uint16_t read_LCD_register(uint16_t reg)
  142. {
  143.    uint16_t date;
  144. GPIOE->CRL=0x33333333; //數據口轉換成輸出
  145. GPIOE->CRH=0x33333333; //數據口轉換成輸出
  146.    CLR_CS;
  147.    //delay_1us(1);
  148.    CLR_RS;
  149.    //delay_1us(1);
  150.    SET_RD;
  151.    CLR_WR;
  152.    GPIO_Write(GPIOE, reg); //寫入命令
  153.    SET_WR;
  154.    //delay_1us(1);
  155.    CLR_RD;
  156.    GPIOE->CRL=0x88888888; //數據口轉換成輸入
  157.    GPIOE->CRH=0x88888888; //數據口轉換成輸入
  158.   // for(n=200;n;n--);
  159.    date=(GPIOE->IDR);//讀出數據
  160.    SET_RD;
  161.    SET_CS;
  162.   

  163.   return (date);


  164. }
  165. void init_STM32()
  166. {
  167.   mysysinit();//RCC初始化,系統時鐘設置72MHZ
  168.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);//使能APB2的GPIO_A時鐘
  169.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);//使能APB2的GPIO_D時鐘
  170.    // RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//使能APB2的GPIO_B時鐘
  171. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);//使能APB2的GPIO_E時鐘
  172. //RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);//使能APB2的GPIO_E時鐘
  173.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//使能APB1的USART2時鐘
  174. /* 設置PD口用于控制LCD的為輸出 */
  175.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15| GPIO_Pin_8|
  176.                                  GPIO_Pin_9 | GPIO_Pin_10| GPIO_Pin_11;
  177.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  178.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  179.   GPIO_Init(GPIOD, &GPIO_InitStructure);
  180. /* 設置PE口用于控制LCD的為輸出 */
  181.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1| GPIO_Pin_2| GPIO_Pin_3| GPIO_Pin_4|
  182.                                 GPIO_Pin_5 | GPIO_Pin_6| GPIO_Pin_7| GPIO_Pin_8| GPIO_Pin_9|
  183.                                 GPIO_Pin_10 | GPIO_Pin_11| GPIO_Pin_12| GPIO_Pin_13| GPIO_Pin_14|
  184.                                 GPIO_Pin_15 ;
  185.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  186.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  187.   GPIO_Init(GPIOD, &GPIO_InitStructure);
  188.   my_USART_init();

  189.              my_send_byte(0);
  190.           my_send_byte(1);
  191.        my_send_byte(2);
  192.     my_send_byte(3);

  193. }
  194. void delay1us(uint32_t time)
  195. {   uint32_t b,c;
  196.         for(c=time;c;c--) //定時=time*3*333.6=time*1000.8ns
  197.          {     
  198.    for(b=8;b;b--); //8*13.9*3= 333.6     
  199.          }



  200. }
  201. /***********************************

  202. 發送一個字節函數通過串口

  203. ************************************/
  204. void my_send_byte(unsigned char send_date )
  205. {

  206.   while( (USART1->SR&0x00000080)!=0x80);//發送寄存器為空
  207.    USART1->DR=send_date;


  208. }
  209. /**********************************
  210.           初始化串口

  211. **********************************/
  212. void my_USART_init()
  213. {

  214. /*USART2的優先級設為5*/
  215. NVIC->IP[37]=5;
  216. /*開啟38號中斷即USART2,關閉其他所有外部的中斷*/
  217. NVIC->ISER[1]=0x00000020;   
  218. /*設置復用模式下的引腳模式為全雙工:TX輸出推挽復用,RX為輸入上拉模式,速度50MHZ*/
  219.             GPIOA->CRH=0x000008b0;
  220.   /* 1.開啟USART,
  221. *
  222. */
  223. USART1->CR1=0x2000;
  224. /* 1.關閉局域網模式
  225. * 2.1個停止位
  226. * 3.CK引腳禁能
  227. */
  228. USART1->CR2=0;
  229. /* 1.關閉調制解調模式
  230. * 2.關閉DMA模式
  231. * 3.關閉智能卡、紅外模式
  232. *   4.關閉錯誤中斷

  233. */
  234. USART1->CR3=0;
  235. /*     波特率設置

  236.      2011年8月11日
  237.         王均偉
  238.          天津第四項目部宿舍

  239.     BRR中的第四位(DIV_Fraction)作為小數,高12位(DIV_MANtissa)作為整數部分,
  240.   
  241.     1,根據公式:波特率=fck/16*usardiv,其中usardivBRR寄存器的值,所以變形得:USARDIV=fck/16*波特率
  242.     2.算出來BRR寄存器的值后就要把這個值變成16進制數據寫入BRR寄存器中,
  243.       遵循以下規則:
  244.       小數部分*16=DIV_Fraction或者取近似的值
  245.       整數部分直接=DIV_MANtissa
  246.     3.把這個16進制值寫入BRR寄存器
  247.     例如我要算波特率設成9600bps的BRR寄存器值,
  248.     1.先求USARDIV=36000000/16*9600=234.375
  249.     2.換成十六進制:DIV_Fraction=16*0.375=0x6
  250.                     DIV_MANtissa=234=0xea
  251.     3.組合并寫入寄存器
  252.                      USART2->BRR=0x0ea6;值得注意的是這里是16位半字操作,所以不要以為是32位。

  253. */
  254. USART1->BRR=0x0ea6;

  255. /* 1.開啟USART
  256. * 2.開啟接收完畢中斷
  257. * 3.開啟發送功能
  258. *   4.開啟接收功能
  259. */
  260. USART1->CR1=0x202c;


  261. }


  262. void mysysinit()//系統初始化程序
  263. {
  264. ErrorStatus HSEStartUpStatus;//說明標志位
  265. RCC_DeInit();//所有外設全部缺省設置

  266. /* Enable HSE */
  267. RCC_HSEConfig(RCC_HSE_ON);
  268. /* Wait till HSE is ready and if Time out is reached exit */
  269. HSEStartUpStatus = RCC_WaitForHSEStartUp();
  270. if(HSEStartUpStatus == SUCCESS)//啟動成功
  271. {
  272. /*這兩條FLASH指令必須加上,不知為啥?不加上就運行幾秒后出錯,參照系統初始化*/
  273. /* Enable The Prefetch Buffer */
  274. FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);//FLASH緩存開啟
  275. /* Configure the Latency cycle: Set 2 Latency cycles */
  276.   FLASH_SetLatency(FLASH_Latency_2);  //設置FLASH這些位表示SYSCLK(系統時鐘)周期與閃存訪問時間的比例,為010:兩個等待狀態,當 48MHz < SYSCLK ≤ 72MHz
  277. /* Set PLL clock output to 72MHz using HSE (8MHz) as entry clock */
  278. RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);//外部時鐘為8M,PLL的輸入時鐘=8MHZ,倍頻系數9,

  279. /* Configure HCLK such as HCLK = SYSCLK */
  280. RCC_HCLKConfig(RCC_SYSCLK_Div1);//設置了啦AHB分頻器的分頻系數=1,即HCLK=SYSCLK=72MHZ
  281. /* Configure PCLK1 such as PCLK1 = HCLK/2 */
  282. RCC_PCLK1Config(RCC_HCLK_Div2);//設置了APB1外設的時鐘頻率最大是36M這里是APB1的分頻器設為2,PCLK1=HCLK/2=72/2=36MHZ正好是最大值
  283. /* Configure PCLK2 such as PCLK2 = HCLK */
  284. RCC_PCLK2Config(RCC_HCLK_Div1);//設置PLCK2=HCLK=72MHZ,的APB2分頻器=1
  285. /* Select the PLL as system clock source */
  286. RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//設置了SYSCLK的提供者為PLL,頻率由上面算出=72MHZ
  287. /* disable PLL Ready interrupt */
  288. RCC_ITConfig(RCC_IT_PLLRDY, DISABLE);//PLL中斷關閉
  289. /* disable PLL Ready interrupt */
  290. RCC_ITConfig(RCC_IT_HSERDY,DISABLE);//HSE中斷關閉
  291. /* disable PLL Ready interrupt */
  292. RCC_ITConfig(RCC_IT_HSIRDY, DISABLE); //HSI中斷關閉
  293. /* disable PLL Ready interrupt */
  294. RCC_ITConfig(RCC_IT_LSERDY, DISABLE); //LSE中斷關閉
  295. /* disable PLL Ready interrupt */
  296. RCC_ITConfig(RCC_IT_LSIRDY, DISABLE); //LSI中斷關閉

  297. /* PLL clock divided by 1.5 used as USB clock source */
  298. RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);//設置USB的時鐘為=72、1.5=48mhz
  299. /* Configure ADCCLK such as ADCCLK = PCLK2/2 */
  300. RCC_ADCCLKConfig(RCC_PCLK2_Div2);//設置ADC時鐘=PCLK2/2= 36MHZ
  301. /* disable the LSE */
  302. RCC_LSEConfig(RCC_LSE_OFF);//外部低速晶振關閉

  303. /*DISable the RTC clock */
  304. RCC_RTCCLKCmd(DISABLE);
  305. /* DISable the Clock Security System */
  306. RCC_ClockSecuritySystemCmd(DISABLE);
  307. /* Enable the PLL */
  308. RCC_PLLCmd(ENABLE);//使能PLL







  309. /* PLL ans system clock config */
  310. }
  311. else
  312. {
  313. /* Add here some code to deal with this error */
  314. }
  315. }
復制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美久久精品一级黑人c片 91免费在线视频 | 日韩一区二区在线视频 | 免费视频一区二区 | 亚洲黄色网址视频 | 黄色成人免费看 | 欧美在线一区二区三区 | 91 在线| 成人在线视频免费播放 | 岛国av免费看 | 成人免费观看男女羞羞视频 | 三级黄视频在线观看 | 免费观看一级特黄欧美大片 | 夜夜骑综合| 国产一区二区毛片 | 天堂在线网 | 在线观看亚 | 国产成人精品久久二区二区91 | 久久不射电影网 | 一区二区精品 | 亚洲一区二区电影网 | 国产一区二区视频在线 | 亚洲欧美精品在线观看 | 精品视频一区二区 | 欧美日韩综合视频 | 亚洲乱码国产乱码精品精的特点 | 中文字幕日韩av | 国产韩国精品一区二区三区 | 在线视频91| 91 视频网站 | 成人亚洲网 | 男女免费视频网站 | 综合色久 | 国产精品视频久久 | 亚洲高清在线观看 | 亚洲视频免费在线看 | 亚洲区一 | 中文字幕亚洲精品 | 蜜桃臀av一区二区三区 | 国产精品久久久久久久久久久久午夜片 | 天天插天天射天天干 | 欧美在线色视频 |