EDABOSS电子论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 698|回复: 0

[资料共享] msp430单片机12864液晶打点画线 画圆 画曲线反白 效果驱动程...

[复制链接]

69

主题

0

回帖

243

E币

技术员

Rank: 2

积分
138
发表于 2017-5-2 14:46:05 | 显示全部楼层 |阅读模式
msp430单片机12864液晶打点画线 画圆 画曲线 反白 效果驱动程序集
捕获.PNG
驱动下载:
12864并行驱动 函数集.rar (5.13 KB, 下载次数: 0)


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


  3. /**************************************************
  4. 函数名称:lcd_delay_n
  5. 功    能:大致延时 只要满足正常显示即可 根据实际调节
  6. 参    数: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. 函数名称:my_abs
  16. 功    能:求绝对值   调用math。h中的abs总是有警告 于是自己写
  17. 参    数:a
  18. 返回值  :无
  19. **************************************************/
  20. unsigned int my_abs(int a)
  21. {
  22.     if(a<0)
  23.         a=-a;
  24.     return a;
  25. }



  26. /**************************************************
  27. 函数名称:write_cmd
  28. 功    能:向液晶中写控制命令
  29. 参    数: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. 函数名称:write_data
  58. 功    能:向液晶中写数据
  59. 参    数:dat--显示数据
  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. 函数名称:lcd_read_data
  87. 功    能:读取12864中一个字节的数据
  88. 参    数:无
  89. 返回值  :显示的数据
  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. 函数名称:lcd_setxy
  120. 功    能:设置显示位置   
  121. 参    数: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. 函数名称:display_line
  141. 功    能:在指定位置显示字符串   
  142. 参    数:坐标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. 函数名称:display_3digit
  158. 功    能:在指定位置开始显示三位数字   
  159. 参    数:坐标x y 数字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. 函数名称:display_2digit
  178. 功    能:在指定位置开始显示两位数字   
  179. 参    数:坐标x y 数字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. 函数名称:display_float
  197. 功    能:在指定位置开始显示浮点数   
  198. 参    数:坐标x y 数字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中间的数字可改变保留几位小数
  205.     display_line(x,y,a);
  206.    
  207. }




  208. /**************************************************
  209. 函数名称:display_float
  210. 功    能:清除显示   
  211. 参    数:无
  212. 返回值  :无
  213. **************************************************/
  214. void clr_screen(void)
  215. {
  216.     write_cmd(0x01);
  217.     //delay_ms(15);
  218. }




  219. /**************************************************
  220. 函数名称:display_page
  221. 功    能:显示一页字符   
  222. 参    数:字符数组s
  223. 返回值  :无

  224. 格式const  char   *Page1[]=
  225. {
  226.      {"**【>>菜单<<】**"},
  227.      {"拨号  通讯   QQ "},
  228.      {"信息  设置  相机"},
  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. 函数名称:init12864
  243. 功    能:初始化液晶模块
  244. 参    数:无
  245. 返回值  :无
  246. **************************************************/
  247. void init12864(void)
  248. {
  249.     LCD_DataOut;
  250.     LCD_CMDOut;                  //液晶控制端口设置为输出
  251.    
  252.     lcd_delay_n(50);
  253.     write_cmd(0x30);            //基本指令集
  254.     lcd_delay_n(50);
  255.     write_cmd(0x30);            //选择8bit数据流
  256.     lcd_delay_n(50);
  257.     write_cmd(0x02);            //地址归位
  258.     lcd_delay_n(50);
  259.     write_cmd(0x0c);            //整体显示打开,游标关闭
  260.     lcd_delay_n(50);
  261.     write_cmd(0x01);            //清除显示
  262.     lcd_delay_n(50);
  263.     write_cmd(0x06);            //游标右移
  264.     lcd_delay_n(50);
  265.     write_cmd(0x80);            //设定显示的起始地址
  266.     lcd_delay_n(2000);
  267. }





  268. /**************************************************
  269. 函数名称:Clear_GDRAM
  270. 功    能:清除液晶GDRAM中的随机数据
  271. 参    数:无
  272. 返回值  :无
  273. **************************************************/
  274. void clear_GDRAM(void)
  275. {
  276.     unsigned char i,j,k;
  277.    
  278.     write_cmd(0x34);               //打开扩展指令集
  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. 函数名称:draw_picture
  303. 功    能:在整个液晶屏幕上画图
  304. 参    数:图片数组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);        //打开扩展指令集
  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. 函数名称:set_white
  406. 功    能:任意位置反白   
  407. 参    数:行数y 起始x 结束end_x  模式clear 0反白 1复原
  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)                     //要反白时,先将整行的液晶全部清成不反白(此处行指y)
  445.     {
  446.         for(i=0;i<16;i++ )                //16行
  447.         {
  448.             write_cmd(clr_y++);                 //设置绘图区的Y地址坐标0
  449.             write_cmd(clr_x);                 //设置绘图区的X地址坐标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行,因为是16*16汉字
  459.     {
  460.         write_cmd(white_y++);                //设置绘图区的Y地址坐标0
  461.         write_cmd(white_x);                //设置绘图区的X地址坐标0
  462.         for(j=0;j<white_end_x;j++)        //
  463.         {
  464.             if(clear==1)
  465.             {
  466.                 write_data(0x00);       //取消这一行的8个点的反白,液晶地址自动加1
  467.                 //(此处行指一个一个液晶点所组成的行)
  468.             }
  469.             else
  470.             {
  471.                 write_data(0xff);       //反白这一行的8个点,液晶地址自动加1
  472.                 //(此处行指一个一个液晶点所组成的行)
  473.             }
  474.             // nop();
  475.         }
  476.     }
  477.     write_cmd(0x30);                   //回到基本模式
  478. }




  479. /**************************************************
  480. 函数名称:draw_dot
  481. 功    能:任意位置打点   
  482. 参    数:坐标xy  color 0反白 1复原
  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. 函数名称:draw_level_line
  540. 功    能:水平线   
  541. 参    数:起始x0 x1 和y坐标  color 0反白 1复原
  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. 函数名称:draw_vertical_line
  561. 功    能:垂直线   
  562. 参    数:起始y0 y1 和x坐标  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. 函数名称:draw_line
  579. 功    能:画任意直线   
  580. 参    数: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. 函数名称:contin_line
  650. 功    能:连续输入Y 连成线,Y为0-63注意输入进来时做转换  线从startx至endx 0-127为最大范围   
  651. 参    数: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连线开始坐标
  657.      if(f)                                     //用于将startx只在第一次传递给i
  658.      {
  659.           f=0;
  660.         i = startx;
  661.      }
  662.     // x0=i;
  663.      y1=Y;                              //画该函数的图形,完全连接了,
  664.      if(i!=startx)                      //保证不与00坐标连到一起
  665.           draw_line(i-1,y0,i,y1,1);
  666.      //x1=x0;
  667.      y0=y1;
  668.       
  669.      if(i++>=endx)  //连线结束坐标
  670.      {
  671.          
  672.           i=startx;
  673.           clear_GDRAM();
  674.      }
  675. }




  676. /**************************************************
  677. 函数名称:draw_curve
  678. 功    能:将一系列无符号字符数组str的数 大小0-63注意传递前做处理,曲线开始位置 xstart 数组大小size   
  679. 参    数:起点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. 函数名称:draw_circle
  707. 功    能:画任意圆   
  708. 参    数:圆心坐标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;  //控制打点间隔
  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. }
复制代码


积分规则
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|EDABOSS电子论坛

GMT+8, 2024-4-24 06:53 , Processed in 0.041054 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表