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

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 5261|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

msp430單片機(jī)12864液晶打點(diǎn)畫線 畫圓 畫曲線 反白 效果驅(qū)動(dòng)程序集

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:140725 發(fā)表于 2016-11-15 12:30 | 只看該作者 |只看大圖 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式

驅(qū)動(dòng)下載:
12864并行驅(qū)動(dòng) 函數(shù)集.rar (5.13 KB, 下載次數(shù): 35)


源程序:
  1. #include<msp430f149.h>
  2. #include "p_lcd12864.h"


  3. /**************************************************
  4. 函數(shù)名稱:lcd_delay_n
  5. 功    能:大致延時(shí) 只要滿足正常顯示即可 根據(jù)實(shí)際調(diào)節(jié)
  6. 參    數(shù):n
  7. 返回值  :無
  8. **************************************************/
  9. void lcd_delay_n(unsigned int n)
  10. {
  11.     unsigned int i;
  12.     for(i=n;i>0;i--)  _NOP();
  13. }



  14. /**************************************************
  15. 函數(shù)名稱:my_abs
  16. 功    能:求絕對(duì)值   調(diào)用math。h中的abs總是有警告 于是自己寫
  17. 參    數(shù):a
  18. 返回值  :無
  19. **************************************************/
  20. unsigned int my_abs(int a)
  21. {
  22.     if(a<0)
  23.         a=-a;
  24.     return a;
  25. }



  26. /**************************************************
  27. 函數(shù)名稱:write_cmd
  28. 功    能:向液晶中寫控制命令
  29. 參    數(shù):cmd--控制命令
  30. 返回值  :無
  31. **************************************************/
  32. void write_cmd(unsigned char cmd)
  33. {
  34.     unsigned char lcdtemp = 0;
  35.     LCD_RS_L;
  36.     LCD_RW_H;
  37.     LCD_DataIn;
  38.     do
  39.     {
  40.         LCD_EN_H;
  41.         _NOP();
  42.         lcdtemp = LCD2MCU_Data;
  43.         LCD_EN_L;
  44.     }
  45.     while(lcdtemp&0x80);
  46.    
  47.     LCD_DataOut;
  48.     LCD_RS_L;
  49.     LCD_RW_L;
  50.     MCU2LCD_Data = cmd;
  51.    
  52.     LCD_EN_H;
  53.     _NOP();
  54.     LCD_EN_L;
  55. }



  56. /**************************************************
  57. 函數(shù)名稱:write_data
  58. 功    能:向液晶中寫數(shù)據(jù)
  59. 參    數(shù):dat--顯示數(shù)據(jù)
  60. 返回值  :無
  61. **************************************************/
  62. void write_data(unsigned char dat)
  63. {
  64.     unsigned char lcdtemp;
  65.     LCD_RS_L;
  66.     LCD_RW_H;
  67.     LCD_DataIn;
  68.     do
  69.     {
  70.         LCD_EN_H;
  71.         _NOP();
  72.         lcdtemp = LCD2MCU_Data;
  73.         LCD_EN_L;
  74.     }
  75.     while(lcdtemp&0x80);
  76.    
  77.     LCD_RS_H;
  78.     LCD_RW_L;
  79.     LCD_DataOut;
  80.     MCU2LCD_Data = dat;
  81.     LCD_EN_H;
  82.     _NOP();
  83.     LCD_EN_L;
  84. }




  85. /**************************************************
  86. 函數(shù)名稱:lcd_read_data
  87. 功    能:讀取12864中一個(gè)字節(jié)的數(shù)據(jù)
  88. 參    數(shù):無
  89. 返回值  :顯示的數(shù)據(jù)
  90. **************************************************/
  91. unsigned char lcd_read_data(void)
  92. {
  93.     unsigned char Data_Temp;
  94.     unsigned char lcdtemp;
  95.     LCD_RS_L;
  96.     LCD_RW_H;
  97.     LCD_DataIn;
  98.     do
  99.     {
  100.         LCD_EN_H;
  101.         _NOP();
  102.         lcdtemp = LCD2MCU_Data;
  103.         LCD_EN_L;
  104.     }
  105.     while(lcdtemp&0x80);
  106.    
  107.     LCD_RS_H;
  108.     LCD_RW_H;
  109.     LCD_DataIn;
  110.    
  111.     LCD_EN_H;
  112.     _NOP();
  113.     Data_Temp = LCD2MCU_Data;
  114.     LCD_EN_L;
  115.    
  116.     return Data_Temp;
  117. }




  118. /**************************************************
  119. 函數(shù)名稱:lcd_setxy
  120. 功    能:設(shè)置顯示位置   
  121. 參    數(shù):X(1~16),Y(1~4)
  122. 返回值  :無
  123. **************************************************/
  124. void lcd_setxy(unsigned char x,unsigned char y)
  125. {
  126.     switch(y)
  127.     {
  128.         case 1:
  129.         write_cmd(0x7F+x);break;
  130.         case 2:
  131.         write_cmd(0x8F+x);break;
  132.         case 3:
  133.         write_cmd(0x87+x);break;
  134.         case 4:
  135.         write_cmd(0x97+x);break;
  136.         default:break;
  137.     }
  138. }




  139. /**************************************************
  140. 函數(shù)名稱:display_line
  141. 功    能:在指定位置顯示字符串   
  142. 參    數(shù):坐標(biāo)x y 字符串str
  143. 返回值  :無
  144. **************************************************/
  145. void display_line(unsigned char x,unsigned char y,const char* str)
  146. {
  147.     unsigned char LCD_temp;
  148.     lcd_setxy(x,y);
  149.     LCD_temp=*str;
  150.     while(LCD_temp != 0x00)
  151.     {
  152.         write_data(LCD_temp);
  153.         LCD_temp=*(++str);
  154.     }
  155. }




  156. /**************************************************
  157. 函數(shù)名稱:display_3digit
  158. 功    能:在指定位置開始顯示三位數(shù)字   
  159. 參    數(shù):坐標(biāo)x y 數(shù)字d
  160. 返回值  :無
  161. **************************************************/
  162. void display_3digit(unsigned char x,unsigned char y,unsigned int d)
  163. {
  164.     unsigned char a[3],i;
  165.     a[0]=d/100;
  166.     a[1]=(d%100)/10;
  167.     a[2]=d%10;
  168.     lcd_setxy(x,y);
  169.     for(i=0;i<3;i++)
  170.     {
  171.         write_data(0x30+a[i]);
  172.         //DelayUs2x(15);
  173.         lcd_delay_n(1);
  174.     }
  175. }




  176. /**************************************************
  177. 函數(shù)名稱:display_2digit
  178. 功    能:在指定位置開始顯示兩位數(shù)字   
  179. 參    數(shù):坐標(biāo)x y 數(shù)字d
  180. 返回值  :無
  181. **************************************************/
  182. void display_2digit(unsigned char x,unsigned char y,unsigned int d)
  183. {
  184.     unsigned char a[2],i;
  185.     a[0]=d/10;
  186.     a[1]=d%10;
  187.     lcd_setxy(x,y);
  188.     for(i=0;i<2;i++)
  189.     {
  190.         write_data(0x30+a[i]);
  191.         //DelayUs2x(15);
  192.         lcd_delay_n(1);
  193.     }
  194. }




  195. /**************************************************
  196. 函數(shù)名稱:display_float
  197. 功    能:在指定位置開始顯示浮點(diǎn)數(shù)   
  198. 參    數(shù):坐標(biāo)x y 數(shù)字d
  199. 返回值  :無
  200. **************************************************/
  201. void display_float(unsigned char x,unsigned char y,float d)
  202. {
  203.     char a[15];           
  204.     sprintf(a,"%.2f",d);  //修改.f中間的數(shù)字可改變保留幾位小數(shù)
  205.     display_line(x,y,a);
  206.    
  207. }




  208. /**************************************************
  209. 函數(shù)名稱:display_float
  210. 功    能:清除顯示   
  211. 參    數(shù):無
  212. 返回值  :無
  213. **************************************************/
  214. void clr_screen(void)
  215. {
  216.     write_cmd(0x01);
  217.     //delay_ms(15);
  218. }




  219. /**************************************************
  220. 函數(shù)名稱:display_page
  221. 功    能:顯示一頁字符   
  222. 參    數(shù):字符數(shù)組s
  223. 返回值  :無

  224. 格式const  char   *Page1[]=
  225. {
  226.      {"**【>>菜單<<】**"},
  227.      {"撥號(hào)  通訊   QQ "},
  228.      {"信息  設(shè)置  相機(jī)"},
  229.      {"娛樂  備忘   UC "}
  230.      
  231. };
  232. **************************************************/
  233. void display_page( const char **s)
  234. {
  235.     unsigned char  i;
  236.     clr_screen();
  237.     for(i=1;i<5;i++)
  238.         display_line(1,i,s[i-1]);
  239.    
  240. }




  241. /**************************************************
  242. 函數(shù)名稱:init12864
  243. 功    能:初始化液晶模塊
  244. 參    數(shù):無
  245. 返回值  :無
  246. **************************************************/
  247. void init12864(void)
  248. {
  249.     LCD_DataOut;
  250.     LCD_CMDOut;                  //液晶控制端口設(shè)置為輸出
  251.    
  252.     lcd_delay_n(50);
  253.     write_cmd(0x30);            //基本指令集
  254.     lcd_delay_n(50);
  255.     write_cmd(0x30);            //選擇8bit數(shù)據(jù)流
  256.     lcd_delay_n(50);
  257.     write_cmd(0x02);            //地址歸位
  258.     lcd_delay_n(50);
  259.     write_cmd(0x0c);            //整體顯示打開,游標(biāo)關(guān)閉
  260.     lcd_delay_n(50);
  261.     write_cmd(0x01);            //清除顯示
  262.     lcd_delay_n(50);
  263.     write_cmd(0x06);            //游標(biāo)右移
  264.     lcd_delay_n(50);
  265.     write_cmd(0x80);            //設(shè)定顯示的起始地址
  266.     lcd_delay_n(2000);
  267. }





  268. /**************************************************
  269. 函數(shù)名稱:Clear_GDRAM
  270. 功    能:清除液晶GDRAM中的隨機(jī)數(shù)據(jù)
  271. 參    數(shù):無
  272. 返回值  :無
  273. **************************************************/
  274. void clear_GDRAM(void)
  275. {
  276.     unsigned char i,j,k;
  277.    
  278.     write_cmd(0x34);               //打開擴(kuò)展指令集
  279.     i = 0x80;            
  280.     for(j = 0;j < 32;j++)
  281.     {
  282.         write_cmd(i++);
  283.         write_cmd(0x80);
  284.         for(k = 0;k < 16;k++)
  285.         {
  286.             write_data(0x00);
  287.         }
  288.     }
  289.     i = 0x80;
  290.     for(j = 0;j < 32;j++)
  291.     {
  292.         write_cmd(i++);
  293.         write_cmd(0x88);          
  294.         for(k = 0;k < 16;k++)
  295.         {
  296.             write_data(0x00);
  297.         }
  298.     }   
  299.     write_cmd(0x30);                  //回到基本指令集
  300. }




  301. /*******************************************
  302. 函數(shù)名稱:draw_picture
  303. 功    能:在整個(gè)液晶屏幕上畫圖
  304. 參    數(shù):圖片數(shù)組ptr
  305. 返回值  :無
  306. 格    式: 寬度x高度=128x64
  307. unsigned char const logo[]={
  308.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  309.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  310.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  311.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  312.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  313.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  314.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  315.     0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  316.     0x00,0x00,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  317.     0x00,0x00,0x3F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  318.     0x00,0x00,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  319.     0x00,0x01,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x7F,0x80,0x00,0x00,0x7F,0x80,0x00,0x00,
  320.     0x00,0x03,0xFF,0xFF,0xFE,0x00,0x00,0x01,0xFF,0xE0,0x00,0x01,0xFF,0xE0,0x00,0x00,
  321.     0x00,0x07,0xFF,0xFF,0xFE,0x00,0x00,0x07,0xFF,0xF0,0x00,0x07,0xFF,0xF0,0x00,0x00,
  322.     0x00,0x0F,0xF9,0xFD,0xFF,0x00,0x00,0x0F,0xFF,0xF8,0x00,0x0F,0xFF,0xF8,0x00,0x00,
  323.     0x00,0x0F,0xF0,0xF0,0xFF,0x80,0x00,0x1F,0xFF,0xFC,0x00,0x1F,0xFF,0xFC,0x00,0x00,
  324.     0x00,0x1F,0xF0,0x70,0x7F,0x80,0x00,0x3F,0xFF,0xFC,0x00,0x3F,0xFF,0xFC,0x00,0x00,
  325.     0x00,0x1F,0xE1,0x70,0x7F,0x80,0x00,0x7F,0xFF,0xFE,0x00,0x7F,0xFF,0xFE,0x00,0x00,
  326.     0x00,0x3F,0xE1,0x66,0x7F,0xC0,0x00,0xFF,0xFF,0xFE,0x00,0xFF,0xFF,0xFE,0x00,0x00,
  327.     0x00,0x3F,0xE3,0xE0,0x7F,0xC0,0x01,0xFF,0xFF,0xFE,0x01,0xFF,0xFF,0xFE,0x00,0x00,
  328.     0x00,0x3F,0xE0,0x60,0x7F,0xE0,0x01,0xFF,0xEF,0xFF,0x01,0xFF,0xEF,0xFF,0x00,0x00,
  329.     0x00,0x7F,0xF0,0xF0,0x7F,0xC0,0x03,0xFF,0x87,0xFF,0x03,0xFF,0x87,0xFF,0x00,0x00,
  330.     0x00,0x3F,0xF0,0xF8,0xFF,0xE0,0x03,0xFF,0x83,0xFF,0x83,0xFF,0x81,0xFF,0x80,0x00,
  331.     0x00,0x7F,0xFF,0xFF,0xFF,0xE0,0x07,0xFF,0x01,0xFF,0x07,0xFF,0x01,0xFF,0x00,0x00,
  332.     0x00,0x7F,0xFF,0xFF,0xFF,0xF0,0x07,0xFF,0x00,0xFF,0x87,0xFF,0x00,0xFF,0x80,0x00,
  333.     0x00,0x7F,0xE0,0x00,0xBF,0xF0,0x0F,0xFE,0x00,0xFF,0x8F,0xFE,0x00,0xFF,0x80,0x00,
  334.     0x00,0xFF,0x80,0x00,0x0F,0xF0,0x0F,0xFE,0x00,0xFF,0x8F,0xFE,0x00,0xFF,0x80,0x00,
  335.     0x00,0xFE,0x00,0x00,0x07,0xF0,0x1F,0xFC,0x00,0x7F,0x9F,0xFC,0x00,0x7F,0x80,0x00,
  336.     0x00,0xFF,0xB0,0x00,0x5F,0xF0,0x0F,0xFC,0x00,0xFF,0x8F,0xFC,0x00,0x7F,0x80,0x00,
  337.     0x01,0xFF,0xF8,0x01,0xFF,0xF0,0x1F,0xF8,0x3D,0xFF,0x9F,0xFC,0x3D,0xFF,0x80,0x00,
  338.     0x01,0xFF,0xFF,0xDF,0xFF,0xF8,0x0F,0xFC,0x37,0x0F,0x8F,0xFC,0x37,0x9F,0x80,0x00,
  339.     0x07,0xFF,0xFF,0xFF,0xFF,0xF8,0x1F,0xF8,0x66,0x07,0x1F,0xF8,0x26,0x0F,0x80,0x00,
  340.     0x07,0xFF,0xFF,0xFF,0xFF,0xFC,0x0F,0xFC,0x6C,0x63,0x8F,0xFC,0x66,0x63,0x80,0x00,
  341.     0x1F,0xC7,0xFF,0xFF,0xFC,0xFE,0x0F,0xFE,0xEC,0x80,0x8F,0xFE,0xED,0x80,0x80,0x00,
  342.     0x1F,0xC3,0xFF,0xFF,0xF0,0x7E,0x07,0xFF,0xFC,0x00,0x07,0xFF,0xFE,0x80,0x00,0x00,
  343.     0x3F,0xC7,0xFF,0xFF,0x80,0x7F,0x07,0xFF,0xFE,0x00,0x07,0xFF,0xFE,0x00,0x00,0x00,
  344.     0x3F,0xC3,0xFD,0xFA,0x00,0x3F,0x01,0xFF,0xFF,0x00,0x21,0xFF,0xFF,0x00,0x20,0x00,
  345.     0x3F,0x87,0xF0,0x00,0x00,0x3F,0x00,0xFF,0xFF,0x00,0x40,0xFF,0xFF,0x00,0x40,0x00,
  346.     0x7F,0x83,0xF8,0x00,0x00,0x3F,0x00,0x1F,0xFF,0x80,0x40,0x1F,0xFF,0xC0,0xC0,0x00,
  347.     0x7F,0x87,0xF0,0x00,0x00,0x3F,0x00,0x00,0x00,0xC1,0x80,0x00,0x00,0xE3,0x80,0x00,
  348.     0x7F,0xC3,0xF8,0x00,0x00,0x3F,0x80,0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x00,0x00,
  349.     0x7B,0x83,0xF0,0x00,0x00,0x3F,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x1C,0x00,0x00,
  350.     0x79,0xC1,0xF0,0x00,0x00,0x27,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  351.     0x21,0xC0,0x00,0x00,0x00,0x67,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  352.     0x00,0xE0,0x00,0x00,0x00,0x40,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  353.     0x00,0xE0,0x00,0x00,0x00,0xC0,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  354.     0x00,0x30,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  355.     0x00,0x38,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  356.     0x00,0x9C,0x00,0x00,0x06,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  357.     0x01,0x07,0x00,0x00,0x0C,0x60,0x07,0xF8,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x70,
  358.     0x01,0x81,0xC0,0x00,0x38,0x10,0x03,0x30,0x00,0x00,0x00,0x03,0x60,0x00,0x00,0x30,
  359.     0x01,0x00,0xF8,0x00,0xE0,0x10,0x03,0x30,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x30,
  360.     0x01,0x00,0x03,0xAD,0x00,0x10,0x01,0xE1,0xE3,0xF7,0xF8,0x06,0x01,0xE1,0xE1,0xF0,
  361.     0x00,0xA0,0x0B,0x0E,0xA2,0xA0,0x01,0xE3,0x31,0xC3,0x30,0x06,0x03,0x33,0x33,0x30,
  362.     0x00,0x00,0x54,0x00,0x00,0x00,0x01,0xE3,0xF1,0x81,0xE0,0x06,0xF3,0x33,0x33,0x30,
  363.     0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE3,0x01,0x81,0xE0,0x06,0x63,0x33,0x33,0x30,
  364.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC3,0x31,0x80,0xC0,0x03,0x63,0x33,0x33,0x30,
  365.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC1,0xE3,0xE0,0xC0,0x01,0xC1,0xE1,0xE1,0xF8,
  366.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,
  367.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,
  368.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  369.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  370.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  371.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  372. };
  373. ********************************************/
  374. void draw_picture(const unsigned char *ptr)
  375. {
  376.     unsigned char i,j,k;
  377.    
  378.     clr_screen();
  379.    
  380.     write_cmd(0x34);        //打開擴(kuò)展指令集
  381.     i = 0x80;            
  382.     for(j = 0;j < 32;j++)
  383.     {
  384.         write_cmd(i++);
  385.         write_cmd(0x80);
  386.         for(k = 0;k < 16;k++)
  387.         {
  388.             write_data(*ptr++);
  389.         }
  390.     }
  391.     i = 0x80;
  392.     for(j = 0;j < 32;j++)
  393.     {
  394.         write_cmd(i++);
  395.         write_cmd(0x88);          
  396.         for(k = 0;k < 16;k++)
  397.         {
  398.             write_data(*ptr++);
  399.         }
  400.     }  
  401.     write_cmd(0x36);        //打開繪圖顯示
  402.     write_cmd(0x30);        //回到基本指令集
  403. }




  404. /**************************************************
  405. 函數(shù)名稱:set_white
  406. 功    能:任意位置反白   
  407. 參    數(shù):行數(shù)y 起始x 結(jié)束end_x  模式clear 0反白 1復(fù)原
  408. 返回值  :無
  409. **************************************************/
  410. void set_white(unsigned char y,unsigned char x,unsigned char end_x,unsigned char clear)
  411. {
  412.     unsigned char i, j, white_x, white_y,white_end_x,clr_x,clr_y;                //
  413.     white_end_x = (end_x-x+1);
  414.     white_end_x <<= 1;
  415.     write_cmd(0x36);                   //打開繪圖模式
  416.     if(y==1)
  417.     {
  418.         white_x = (0x80+x-1);
  419.         white_y = 0x80;
  420.         clr_x = 0x80;
  421.         clr_y = 0x80;
  422.     }
  423.     else if(y==2)
  424.     {
  425.         white_x = (0x80+x-1);
  426.         white_y = 0x90;
  427.         clr_x = 0x80;
  428.         clr_y = 0x90;
  429.     }
  430.     else if(y==3)
  431.     {
  432.         white_x = (0x88+x-1);
  433.         white_y = 0x80;
  434.         clr_x = 0x88;
  435.         clr_y = 0x80;
  436.     }
  437.     else if(y==4)
  438.     {
  439.         white_x = (0x88+x-1);
  440.         white_y = 0x90;
  441.         clr_x = 0x88;
  442.         clr_y = 0x90;
  443.     }
  444.     if(clear==0)                     //要反白時(shí),先將整行的液晶全部清成不反白(此處行指y)
  445.     {
  446.         for(i=0;i<16;i++ )                //16行
  447.         {
  448.             write_cmd(clr_y++);                 //設(shè)置繪圖區(qū)的Y地址坐標(biāo)0
  449.             write_cmd(clr_x);                 //設(shè)置繪圖區(qū)的X地址坐標(biāo)0
  450.             for(j=0;j<16;j++)                 //
  451.             {
  452.                 write_data(0x00);         //清成不反白
  453.                 //nop();
  454.             }
  455.         }
  456.     }
  457.     //nop();
  458.     for(i=0;i<16;i++ )                        //16行,因?yàn)槭?6*16漢字
  459.     {
  460.         write_cmd(white_y++);                //設(shè)置繪圖區(qū)的Y地址坐標(biāo)0
  461.         write_cmd(white_x);                //設(shè)置繪圖區(qū)的X地址坐標(biāo)0
  462.         for(j=0;j<white_end_x;j++)        //
  463.         {
  464.             if(clear==1)
  465.             {
  466.                 write_data(0x00);       //取消這一行的8個(gè)點(diǎn)的反白,液晶地址自動(dòng)加1
  467.                 //(此處行指一個(gè)一個(gè)液晶點(diǎn)所組成的行)
  468.             }
  469.             else
  470.             {
  471.                 write_data(0xff);       //反白這一行的8個(gè)點(diǎn),液晶地址自動(dòng)加1
  472.                 //(此處行指一個(gè)一個(gè)液晶點(diǎn)所組成的行)
  473.             }
  474.             // nop();
  475.         }
  476.     }
  477.     write_cmd(0x30);                   //回到基本模式
  478. }




  479. /**************************************************
  480. 函數(shù)名稱:draw_dot
  481. 功    能:任意位置打點(diǎn)   
  482. 參    數(shù):坐標(biāo)xy  color 0反白 1復(fù)原
  483. 返回值  :無
  484. **************************************************/
  485. void draw_dot(unsigned char x,unsigned char y,unsigned char color)
  486. {
  487.     unsigned char  row,tier,tier_bit;
  488.     unsigned char  read_old_h,read_old_l;
  489.     write_cmd(0x34);
  490.     write_cmd(0x36);
  491.     tier=x>>4;
  492.     tier_bit=x&0x0f;
  493.     if(y<32)
  494.         row=y;
  495.     else
  496.     {
  497.         row=y-32;
  498.         tier+=8;
  499.     }
  500.     write_cmd(row+0x80);
  501.     write_cmd(tier+0x80);
  502.     lcd_read_data();
  503.     read_old_h=lcd_read_data();
  504.     read_old_l=lcd_read_data();
  505.     write_cmd(row+0x80);
  506.     write_cmd(tier+0x80);
  507.    
  508.     if(tier_bit<8)
  509.     {
  510.         switch(color)
  511.         {
  512.             case 0:read_old_h&=(~(0x01<<(7-tier_bit)));break;
  513.             case 1:read_old_h|=(0x01<<(7-tier_bit))   ;break;
  514.             case 2:read_old_h^=(0x01<<(7-tier_bit))   ;break;
  515.             default:break;
  516.         }
  517.         write_data(read_old_h);
  518.         write_data(read_old_l);
  519.         
  520.     }
  521.     else
  522.     {
  523.         switch(color)
  524.         {
  525.             case 0:read_old_l&=(~(0x01<<(15-tier_bit)));break;
  526.             case 1:read_old_l|=(0x01<<(15-tier_bit))   ;break;
  527.             case 2:read_old_l^=(0x01<<(15-tier_bit))   ;break;
  528.             default:break;
  529.         }
  530.         
  531.         write_data(read_old_h);
  532.         write_data(read_old_l);
  533.     }
  534.    
  535.     write_cmd(0x30);
  536.    
  537. }




  538. /**************************************************
  539. 函數(shù)名稱:draw_level_line
  540. 功    能:水平線   
  541. 參    數(shù):起始x0 x1 和y坐標(biāo)  color 0反白 1復(fù)原
  542. 返回值  :無
  543. **************************************************/
  544. void draw_level_line(unsigned char x0,unsigned char x1,unsigned char y,unsigned char color)
  545. {
  546.     unsigned char temp;
  547.     if(x0>x1)
  548.     {
  549.         temp=x1;
  550.         x1=x0;
  551.         x0=temp;
  552.     }
  553.     for(;x0<=x1;x0++)
  554.     {
  555.         draw_dot(x0,y,color);
  556.     }
  557.    
  558. }



  559. /**************************************************
  560. 函數(shù)名稱:draw_vertical_line
  561. 功    能:垂直線   
  562. 參    數(shù):起始y0 y1 和x坐標(biāo)  color 0 1
  563. 返回值  :無
  564. **************************************************/
  565. void draw_vertical_line(unsigned char y0,unsigned char y1,unsigned char x,unsigned char color)
  566. {
  567.     unsigned char temp;
  568.     if(y0>y1)
  569.     {
  570.         temp=y1;
  571.         y1=y0;
  572.         y0=temp;
  573.     }
  574.     for(;y0<=y1;y0++)
  575.         draw_dot(x,y0,color);
  576. }




  577. /**************************************************
  578. 函數(shù)名稱:draw_line
  579. 功    能:畫任意直線   
  580. 參    數(shù):startx starty endx endy    color
  581. 返回值  :無
  582. **************************************************/
  583. void draw_line(unsigned char startx,unsigned char starty
  584.                ,unsigned char endx,unsigned char endy,unsigned char color)
  585. {
  586.     int t,distance;
  587.     int x=0,y=0,delta_x,delta_y;
  588.     int incx,incy;
  589.     delta_x=endx-startx;
  590.     delta_y=endy-starty;
  591.    
  592.     if(delta_x>0)
  593.     {
  594.         incx=1;
  595.     }
  596.     else if(delta_x==0)
  597.     {
  598.         draw_vertical_line(startx,starty,endy,color);
  599.         return;
  600.     }
  601.     else
  602.     {
  603.         incx= -1;
  604.     }
  605.     if(delta_y>0)
  606.     {
  607.         incy=1;
  608.     }
  609.     else if(delta_y==0)
  610.     {
  611.         draw_level_line(startx,endx,starty,color);
  612.         return;
  613.     }
  614.     else
  615.     {
  616.         incy=-1;
  617.     }
  618.     delta_x=my_abs(delta_x);
  619.     delta_y=my_abs(delta_y);
  620.     if(delta_x>delta_y)
  621.     {
  622.         distance=delta_x;
  623.     }
  624.     else
  625.     {
  626.         distance=delta_y;
  627.     }
  628.     draw_dot(startx,starty,color);
  629.     for(t=0;t<=distance+1;t++)
  630.     {
  631.         draw_dot(startx,starty,color);
  632.         x+=delta_x;
  633.         y+=delta_y;
  634.         if(x>distance)
  635.         {
  636.             x-=distance;
  637.             startx+=incx;
  638.         }
  639.         if(y>distance)
  640.         {
  641.             y-=distance;
  642.             starty+=incy;
  643.         }
  644.         
  645.     }
  646.    
  647. }




  648. /**************************************************
  649. 函數(shù)名稱:contin_line
  650. 功    能:連續(xù)輸入Y 連成線,Y為0-63注意輸入進(jìn)來時(shí)做轉(zhuǎn)換  線從startx至endx 0-127為最大范圍   
  651. 參    數(shù):startx  endx endy    color
  652. 返回值  :無
  653. **************************************************/
  654. void contin_line(unsigned char startx ,unsigned char endx ,unsigned char Y)
  655. {
  656.      static unsigned char i=0,y0=0,y1=0,f=1; //i連線開始坐標(biāo)
  657.      if(f)                                     //用于將startx只在第一次傳遞給i
  658.      {
  659.           f=0;
  660.         i = startx;
  661.      }
  662.     // x0=i;
  663.      y1=Y;                              //畫該函數(shù)的圖形,完全連接了,
  664.      if(i!=startx)                      //保證不與00坐標(biāo)連到一起
  665.           draw_line(i-1,y0,i,y1,1);
  666.      //x1=x0;
  667.      y0=y1;
  668.       
  669.      if(i++>=endx)  //連線結(jié)束坐標(biāo)
  670.      {
  671.          
  672.           i=startx;
  673.           clear_GDRAM();
  674.      }
  675. }




  676. /**************************************************
  677. 函數(shù)名稱:draw_curve
  678. 功    能:將一系列無符號(hào)字符數(shù)組str的數(shù) 大小0-63注意傳遞前做處理,曲線開始位置 xstart 數(shù)組大小size   
  679. 參    數(shù):起點(diǎn)startx    size  *str
  680. 返回值  :無
  681. **************************************************/
  682. void draw_curve(unsigned char xstart, unsigned char size ,unsigned char *str)
  683. {
  684.     static unsigned char i=0,endx=0,y0=0,y1=0,f=1;
  685.     if(f) //只傳遞一次
  686.     {
  687.         f=0;
  688.         i = xstart;
  689.     }
  690.    
  691.     endx = xstart + size;
  692.     if(endx>=128)  //保證圖形不溢出
  693.         endx =127;
  694.     for(;i<endx;i++)
  695.     {
  696.         y1 = str[i-xstart];
  697.         if(i!=xstart)
  698.             draw_line(i-1,y0,i,y1,1);
  699.         y0 = y1;
  700.     }
  701.     i = xstart;  
  702.     //Clear_GDRAM();
  703.    
  704. }





  705. /**************************************************
  706. 函數(shù)名稱:draw_circle
  707. 功    能:畫任意圓   
  708. 參    數(shù):圓心坐標(biāo)xy 半徑r    color
  709. 返回值  :無
  710. **************************************************/
  711. void draw_circle(unsigned char x,unsigned char y,unsigned char r,unsigned char color)
  712. {
  713.     unsigned char a,b;
  714.     float c;
  715.     a = 0;
  716.     b = r;
  717.     //  c = 1.25 - r;
  718.     c = 3 - 2*r;
  719.     while(a < b)
  720.     {
  721.         draw_dot(x+a,y+b,color);
  722.         draw_dot(x-a,y+b,color);
  723.         draw_dot(x+a,y-b,color);
  724.         draw_dot(x-a,y-b,color);
  725.         
  726.         draw_dot(x+b,y+a,color);
  727.         draw_dot(x-b,y+a,color);
  728.         draw_dot(x+b,y-a,color);
  729.         draw_dot(x-b,y-a,color);
  730.         
  731.         if(c < 0)
  732.         {
  733.             c = c+4*a + 6;
  734.         }
  735.         else
  736.         {
  737.             c= c + 4*(a - b) + 10;
  738.             b-=1;
  739.         }
  740.         a = a + 1;  //控制打點(diǎn)間隔
  741.         
  742.     }
  743.     if(a == b)
  744.     {
  745.         draw_dot(x+a,y+b,color);
  746.         draw_dot(x-a,y+b,color);
  747.         draw_dot(x+a,y-b,color);
  748.         draw_dot(x-a,y+b,color);
  749.         
  750.         draw_dot(x+b,y+a,color);
  751.         draw_dot(x-b,y+a,color);
  752.         draw_dot(x+b,y-a,color);
  753.         draw_dot(x-b,y-a,color);
  754.         
  755.     }
  756. }
復(fù)制代碼



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

使用道具 舉報(bào)

沙發(fā)
ID:147464 發(fā)表于 2016-11-17 09:57 | 只看該作者
學(xué)習(xí)了
回復(fù)

使用道具 舉報(bào)

板凳
ID:248500 發(fā)表于 2018-4-2 17:19 來自手機(jī) | 只看該作者
這真的厲害,12864感覺更透徹了
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 国产免费一区二区 | 91在线一区二区 | 日韩黄色小视频 | 中文字幕第5页 | 久久成人免费视频 | 亚洲国产成人精品女人久久久 | 久久久久九九九九 | 欧美一级在线视频 | 青青久草 | 欧美视频1| 国产伦精品一区二区三区精品视频 | 91亚洲一区 | 一区二区三区视频在线 | 亚洲一区二区三区桃乃木香奈 | 日韩欧美一区二区三区在线播放 | 女生羞羞网站 | 成人乱人乱一区二区三区软件 | 精品九九久久 | 精品一区二区在线观看 | 中文字幕一区在线观看视频 | 一区二区三区在线 | 精品一区二区免费视频 | 精品三级| 国产精品日韩高清伦字幕搜索 | 一区二区三区四区五区在线视频 | 三级视频国产 | 凹凸日日摸日日碰夜夜 | 国产精品毛片一区二区三区 | 亚洲国产精品第一区二区 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 福利精品 | 久久伊人免费视频 | 欧美精品一区二区三区四区五区 | 日韩一区二区黄色片 | 亚洲日韩中文字幕 | 免费一区二区三区 | 国产jizz女人多喷水99 | 在线亚洲电影 | 日日操夜夜操天天操 | 日韩在线小视频 | 一级黄色片在线免费观看 |