0.png (70.81 KB, 下載次數(shù): 71)
下載附件
2016-11-15 12:29 上傳
驅(qū)動(dòng)下載:
12864并行驅(qū)動(dòng) 函數(shù)集.rar
(5.13 KB, 下載次數(shù): 35)
2016-11-15 12:30 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
源程序:
- #include<msp430f149.h>
- #include "p_lcd12864.h"
- /**************************************************
- 函數(shù)名稱:lcd_delay_n
- 功 能:大致延時(shí) 只要滿足正常顯示即可 根據(jù)實(shí)際調(diào)節(jié)
- 參 數(shù):n
- 返回值 :無
- **************************************************/
- void lcd_delay_n(unsigned int n)
- {
- unsigned int i;
- for(i=n;i>0;i--) _NOP();
- }
- /**************************************************
- 函數(shù)名稱:my_abs
- 功 能:求絕對(duì)值 調(diào)用math。h中的abs總是有警告 于是自己寫
- 參 數(shù):a
- 返回值 :無
- **************************************************/
- unsigned int my_abs(int a)
- {
- if(a<0)
- a=-a;
- return a;
- }
- /**************************************************
- 函數(shù)名稱:write_cmd
- 功 能:向液晶中寫控制命令
- 參 數(shù):cmd--控制命令
- 返回值 :無
- **************************************************/
- void write_cmd(unsigned char cmd)
- {
- unsigned char lcdtemp = 0;
- LCD_RS_L;
- LCD_RW_H;
- LCD_DataIn;
- do
- {
- LCD_EN_H;
- _NOP();
- lcdtemp = LCD2MCU_Data;
- LCD_EN_L;
- }
- while(lcdtemp&0x80);
-
- LCD_DataOut;
- LCD_RS_L;
- LCD_RW_L;
- MCU2LCD_Data = cmd;
-
- LCD_EN_H;
- _NOP();
- LCD_EN_L;
- }
- /**************************************************
- 函數(shù)名稱:write_data
- 功 能:向液晶中寫數(shù)據(jù)
- 參 數(shù):dat--顯示數(shù)據(jù)
- 返回值 :無
- **************************************************/
- void write_data(unsigned char dat)
- {
- unsigned char lcdtemp;
- LCD_RS_L;
- LCD_RW_H;
- LCD_DataIn;
- do
- {
- LCD_EN_H;
- _NOP();
- lcdtemp = LCD2MCU_Data;
- LCD_EN_L;
- }
- while(lcdtemp&0x80);
-
- LCD_RS_H;
- LCD_RW_L;
- LCD_DataOut;
- MCU2LCD_Data = dat;
- LCD_EN_H;
- _NOP();
- LCD_EN_L;
- }
- /**************************************************
- 函數(shù)名稱:lcd_read_data
- 功 能:讀取12864中一個(gè)字節(jié)的數(shù)據(jù)
- 參 數(shù):無
- 返回值 :顯示的數(shù)據(jù)
- **************************************************/
- unsigned char lcd_read_data(void)
- {
- unsigned char Data_Temp;
- unsigned char lcdtemp;
- LCD_RS_L;
- LCD_RW_H;
- LCD_DataIn;
- do
- {
- LCD_EN_H;
- _NOP();
- lcdtemp = LCD2MCU_Data;
- LCD_EN_L;
- }
- while(lcdtemp&0x80);
-
- LCD_RS_H;
- LCD_RW_H;
- LCD_DataIn;
-
- LCD_EN_H;
- _NOP();
- Data_Temp = LCD2MCU_Data;
- LCD_EN_L;
-
- return Data_Temp;
- }
- /**************************************************
- 函數(shù)名稱:lcd_setxy
- 功 能:設(shè)置顯示位置
- 參 數(shù):X(1~16),Y(1~4)
- 返回值 :無
- **************************************************/
- void lcd_setxy(unsigned char x,unsigned char y)
- {
- switch(y)
- {
- case 1:
- write_cmd(0x7F+x);break;
- case 2:
- write_cmd(0x8F+x);break;
- case 3:
- write_cmd(0x87+x);break;
- case 4:
- write_cmd(0x97+x);break;
- default:break;
- }
- }
- /**************************************************
- 函數(shù)名稱:display_line
- 功 能:在指定位置顯示字符串
- 參 數(shù):坐標(biāo)x y 字符串str
- 返回值 :無
- **************************************************/
- void display_line(unsigned char x,unsigned char y,const char* str)
- {
- unsigned char LCD_temp;
- lcd_setxy(x,y);
- LCD_temp=*str;
- while(LCD_temp != 0x00)
- {
- write_data(LCD_temp);
- LCD_temp=*(++str);
- }
- }
- /**************************************************
- 函數(shù)名稱:display_3digit
- 功 能:在指定位置開始顯示三位數(shù)字
- 參 數(shù):坐標(biāo)x y 數(shù)字d
- 返回值 :無
- **************************************************/
- void display_3digit(unsigned char x,unsigned char y,unsigned int d)
- {
- unsigned char a[3],i;
- a[0]=d/100;
- a[1]=(d%100)/10;
- a[2]=d%10;
- lcd_setxy(x,y);
- for(i=0;i<3;i++)
- {
- write_data(0x30+a[i]);
- //DelayUs2x(15);
- lcd_delay_n(1);
- }
- }
- /**************************************************
- 函數(shù)名稱:display_2digit
- 功 能:在指定位置開始顯示兩位數(shù)字
- 參 數(shù):坐標(biāo)x y 數(shù)字d
- 返回值 :無
- **************************************************/
- void display_2digit(unsigned char x,unsigned char y,unsigned int d)
- {
- unsigned char a[2],i;
- a[0]=d/10;
- a[1]=d%10;
- lcd_setxy(x,y);
- for(i=0;i<2;i++)
- {
- write_data(0x30+a[i]);
- //DelayUs2x(15);
- lcd_delay_n(1);
- }
- }
- /**************************************************
- 函數(shù)名稱:display_float
- 功 能:在指定位置開始顯示浮點(diǎn)數(shù)
- 參 數(shù):坐標(biāo)x y 數(shù)字d
- 返回值 :無
- **************************************************/
- void display_float(unsigned char x,unsigned char y,float d)
- {
- char a[15];
- sprintf(a,"%.2f",d); //修改.f中間的數(shù)字可改變保留幾位小數(shù)
- display_line(x,y,a);
-
- }
- /**************************************************
- 函數(shù)名稱:display_float
- 功 能:清除顯示
- 參 數(shù):無
- 返回值 :無
- **************************************************/
- void clr_screen(void)
- {
- write_cmd(0x01);
- //delay_ms(15);
- }
- /**************************************************
- 函數(shù)名稱:display_page
- 功 能:顯示一頁字符
- 參 數(shù):字符數(shù)組s
- 返回值 :無
- 格式const char *Page1[]=
- {
- {"**【>>菜單<<】**"},
- {"撥號(hào) 通訊 QQ "},
- {"信息 設(shè)置 相機(jī)"},
- {"娛樂 備忘 UC "}
-
- };
- **************************************************/
- void display_page( const char **s)
- {
- unsigned char i;
- clr_screen();
- for(i=1;i<5;i++)
- display_line(1,i,s[i-1]);
-
- }
- /**************************************************
- 函數(shù)名稱:init12864
- 功 能:初始化液晶模塊
- 參 數(shù):無
- 返回值 :無
- **************************************************/
- void init12864(void)
- {
- LCD_DataOut;
- LCD_CMDOut; //液晶控制端口設(shè)置為輸出
-
- lcd_delay_n(50);
- write_cmd(0x30); //基本指令集
- lcd_delay_n(50);
- write_cmd(0x30); //選擇8bit數(shù)據(jù)流
- lcd_delay_n(50);
- write_cmd(0x02); //地址歸位
- lcd_delay_n(50);
- write_cmd(0x0c); //整體顯示打開,游標(biāo)關(guān)閉
- lcd_delay_n(50);
- write_cmd(0x01); //清除顯示
- lcd_delay_n(50);
- write_cmd(0x06); //游標(biāo)右移
- lcd_delay_n(50);
- write_cmd(0x80); //設(shè)定顯示的起始地址
- lcd_delay_n(2000);
- }
- /**************************************************
- 函數(shù)名稱:Clear_GDRAM
- 功 能:清除液晶GDRAM中的隨機(jī)數(shù)據(jù)
- 參 數(shù):無
- 返回值 :無
- **************************************************/
- void clear_GDRAM(void)
- {
- unsigned char i,j,k;
-
- write_cmd(0x34); //打開擴(kuò)展指令集
- i = 0x80;
- for(j = 0;j < 32;j++)
- {
- write_cmd(i++);
- write_cmd(0x80);
- for(k = 0;k < 16;k++)
- {
- write_data(0x00);
- }
- }
- i = 0x80;
- for(j = 0;j < 32;j++)
- {
- write_cmd(i++);
- write_cmd(0x88);
- for(k = 0;k < 16;k++)
- {
- write_data(0x00);
- }
- }
- write_cmd(0x30); //回到基本指令集
- }
- /*******************************************
- 函數(shù)名稱:draw_picture
- 功 能:在整個(gè)液晶屏幕上畫圖
- 參 數(shù):圖片數(shù)組ptr
- 返回值 :無
- 格 式: 寬度x高度=128x64
- unsigned char const logo[]={
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x3F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x01,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x7F,0x80,0x00,0x00,0x7F,0x80,0x00,0x00,
- 0x00,0x03,0xFF,0xFF,0xFE,0x00,0x00,0x01,0xFF,0xE0,0x00,0x01,0xFF,0xE0,0x00,0x00,
- 0x00,0x07,0xFF,0xFF,0xFE,0x00,0x00,0x07,0xFF,0xF0,0x00,0x07,0xFF,0xF0,0x00,0x00,
- 0x00,0x0F,0xF9,0xFD,0xFF,0x00,0x00,0x0F,0xFF,0xF8,0x00,0x0F,0xFF,0xF8,0x00,0x00,
- 0x00,0x0F,0xF0,0xF0,0xFF,0x80,0x00,0x1F,0xFF,0xFC,0x00,0x1F,0xFF,0xFC,0x00,0x00,
- 0x00,0x1F,0xF0,0x70,0x7F,0x80,0x00,0x3F,0xFF,0xFC,0x00,0x3F,0xFF,0xFC,0x00,0x00,
- 0x00,0x1F,0xE1,0x70,0x7F,0x80,0x00,0x7F,0xFF,0xFE,0x00,0x7F,0xFF,0xFE,0x00,0x00,
- 0x00,0x3F,0xE1,0x66,0x7F,0xC0,0x00,0xFF,0xFF,0xFE,0x00,0xFF,0xFF,0xFE,0x00,0x00,
- 0x00,0x3F,0xE3,0xE0,0x7F,0xC0,0x01,0xFF,0xFF,0xFE,0x01,0xFF,0xFF,0xFE,0x00,0x00,
- 0x00,0x3F,0xE0,0x60,0x7F,0xE0,0x01,0xFF,0xEF,0xFF,0x01,0xFF,0xEF,0xFF,0x00,0x00,
- 0x00,0x7F,0xF0,0xF0,0x7F,0xC0,0x03,0xFF,0x87,0xFF,0x03,0xFF,0x87,0xFF,0x00,0x00,
- 0x00,0x3F,0xF0,0xF8,0xFF,0xE0,0x03,0xFF,0x83,0xFF,0x83,0xFF,0x81,0xFF,0x80,0x00,
- 0x00,0x7F,0xFF,0xFF,0xFF,0xE0,0x07,0xFF,0x01,0xFF,0x07,0xFF,0x01,0xFF,0x00,0x00,
- 0x00,0x7F,0xFF,0xFF,0xFF,0xF0,0x07,0xFF,0x00,0xFF,0x87,0xFF,0x00,0xFF,0x80,0x00,
- 0x00,0x7F,0xE0,0x00,0xBF,0xF0,0x0F,0xFE,0x00,0xFF,0x8F,0xFE,0x00,0xFF,0x80,0x00,
- 0x00,0xFF,0x80,0x00,0x0F,0xF0,0x0F,0xFE,0x00,0xFF,0x8F,0xFE,0x00,0xFF,0x80,0x00,
- 0x00,0xFE,0x00,0x00,0x07,0xF0,0x1F,0xFC,0x00,0x7F,0x9F,0xFC,0x00,0x7F,0x80,0x00,
- 0x00,0xFF,0xB0,0x00,0x5F,0xF0,0x0F,0xFC,0x00,0xFF,0x8F,0xFC,0x00,0x7F,0x80,0x00,
- 0x01,0xFF,0xF8,0x01,0xFF,0xF0,0x1F,0xF8,0x3D,0xFF,0x9F,0xFC,0x3D,0xFF,0x80,0x00,
- 0x01,0xFF,0xFF,0xDF,0xFF,0xF8,0x0F,0xFC,0x37,0x0F,0x8F,0xFC,0x37,0x9F,0x80,0x00,
- 0x07,0xFF,0xFF,0xFF,0xFF,0xF8,0x1F,0xF8,0x66,0x07,0x1F,0xF8,0x26,0x0F,0x80,0x00,
- 0x07,0xFF,0xFF,0xFF,0xFF,0xFC,0x0F,0xFC,0x6C,0x63,0x8F,0xFC,0x66,0x63,0x80,0x00,
- 0x1F,0xC7,0xFF,0xFF,0xFC,0xFE,0x0F,0xFE,0xEC,0x80,0x8F,0xFE,0xED,0x80,0x80,0x00,
- 0x1F,0xC3,0xFF,0xFF,0xF0,0x7E,0x07,0xFF,0xFC,0x00,0x07,0xFF,0xFE,0x80,0x00,0x00,
- 0x3F,0xC7,0xFF,0xFF,0x80,0x7F,0x07,0xFF,0xFE,0x00,0x07,0xFF,0xFE,0x00,0x00,0x00,
- 0x3F,0xC3,0xFD,0xFA,0x00,0x3F,0x01,0xFF,0xFF,0x00,0x21,0xFF,0xFF,0x00,0x20,0x00,
- 0x3F,0x87,0xF0,0x00,0x00,0x3F,0x00,0xFF,0xFF,0x00,0x40,0xFF,0xFF,0x00,0x40,0x00,
- 0x7F,0x83,0xF8,0x00,0x00,0x3F,0x00,0x1F,0xFF,0x80,0x40,0x1F,0xFF,0xC0,0xC0,0x00,
- 0x7F,0x87,0xF0,0x00,0x00,0x3F,0x00,0x00,0x00,0xC1,0x80,0x00,0x00,0xE3,0x80,0x00,
- 0x7F,0xC3,0xF8,0x00,0x00,0x3F,0x80,0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x00,0x00,
- 0x7B,0x83,0xF0,0x00,0x00,0x3F,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x1C,0x00,0x00,
- 0x79,0xC1,0xF0,0x00,0x00,0x27,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x21,0xC0,0x00,0x00,0x00,0x67,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0xE0,0x00,0x00,0x00,0x40,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0x00,0xE0,0x00,0x00,0x00,0xC0,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0x00,0x30,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x38,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x9C,0x00,0x00,0x06,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x01,0x07,0x00,0x00,0x0C,0x60,0x07,0xF8,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x70,
- 0x01,0x81,0xC0,0x00,0x38,0x10,0x03,0x30,0x00,0x00,0x00,0x03,0x60,0x00,0x00,0x30,
- 0x01,0x00,0xF8,0x00,0xE0,0x10,0x03,0x30,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x30,
- 0x01,0x00,0x03,0xAD,0x00,0x10,0x01,0xE1,0xE3,0xF7,0xF8,0x06,0x01,0xE1,0xE1,0xF0,
- 0x00,0xA0,0x0B,0x0E,0xA2,0xA0,0x01,0xE3,0x31,0xC3,0x30,0x06,0x03,0x33,0x33,0x30,
- 0x00,0x00,0x54,0x00,0x00,0x00,0x01,0xE3,0xF1,0x81,0xE0,0x06,0xF3,0x33,0x33,0x30,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE3,0x01,0x81,0xE0,0x06,0x63,0x33,0x33,0x30,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC3,0x31,0x80,0xC0,0x03,0x63,0x33,0x33,0x30,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC1,0xE3,0xE0,0xC0,0x01,0xC1,0xE1,0xE1,0xF8,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- ********************************************/
- void draw_picture(const unsigned char *ptr)
- {
- unsigned char i,j,k;
-
- clr_screen();
-
- write_cmd(0x34); //打開擴(kuò)展指令集
- i = 0x80;
- for(j = 0;j < 32;j++)
- {
- write_cmd(i++);
- write_cmd(0x80);
- for(k = 0;k < 16;k++)
- {
- write_data(*ptr++);
- }
- }
- i = 0x80;
- for(j = 0;j < 32;j++)
- {
- write_cmd(i++);
- write_cmd(0x88);
- for(k = 0;k < 16;k++)
- {
- write_data(*ptr++);
- }
- }
- write_cmd(0x36); //打開繪圖顯示
- write_cmd(0x30); //回到基本指令集
- }
- /**************************************************
- 函數(shù)名稱:set_white
- 功 能:任意位置反白
- 參 數(shù):行數(shù)y 起始x 結(jié)束end_x 模式clear 0反白 1復(fù)原
- 返回值 :無
- **************************************************/
- void set_white(unsigned char y,unsigned char x,unsigned char end_x,unsigned char clear)
- {
- unsigned char i, j, white_x, white_y,white_end_x,clr_x,clr_y; //
- white_end_x = (end_x-x+1);
- white_end_x <<= 1;
- write_cmd(0x36); //打開繪圖模式
- if(y==1)
- {
- white_x = (0x80+x-1);
- white_y = 0x80;
- clr_x = 0x80;
- clr_y = 0x80;
- }
- else if(y==2)
- {
- white_x = (0x80+x-1);
- white_y = 0x90;
- clr_x = 0x80;
- clr_y = 0x90;
- }
- else if(y==3)
- {
- white_x = (0x88+x-1);
- white_y = 0x80;
- clr_x = 0x88;
- clr_y = 0x80;
- }
- else if(y==4)
- {
- white_x = (0x88+x-1);
- white_y = 0x90;
- clr_x = 0x88;
- clr_y = 0x90;
- }
- if(clear==0) //要反白時(shí),先將整行的液晶全部清成不反白(此處行指y)
- {
- for(i=0;i<16;i++ ) //16行
- {
- write_cmd(clr_y++); //設(shè)置繪圖區(qū)的Y地址坐標(biāo)0
- write_cmd(clr_x); //設(shè)置繪圖區(qū)的X地址坐標(biāo)0
- for(j=0;j<16;j++) //
- {
- write_data(0x00); //清成不反白
- //nop();
- }
- }
- }
- //nop();
- for(i=0;i<16;i++ ) //16行,因?yàn)槭?6*16漢字
- {
- write_cmd(white_y++); //設(shè)置繪圖區(qū)的Y地址坐標(biāo)0
- write_cmd(white_x); //設(shè)置繪圖區(qū)的X地址坐標(biāo)0
- for(j=0;j<white_end_x;j++) //
- {
- if(clear==1)
- {
- write_data(0x00); //取消這一行的8個(gè)點(diǎn)的反白,液晶地址自動(dòng)加1
- //(此處行指一個(gè)一個(gè)液晶點(diǎn)所組成的行)
- }
- else
- {
- write_data(0xff); //反白這一行的8個(gè)點(diǎn),液晶地址自動(dòng)加1
- //(此處行指一個(gè)一個(gè)液晶點(diǎn)所組成的行)
- }
- // nop();
- }
- }
- write_cmd(0x30); //回到基本模式
- }
- /**************************************************
- 函數(shù)名稱:draw_dot
- 功 能:任意位置打點(diǎn)
- 參 數(shù):坐標(biāo)xy color 0反白 1復(fù)原
- 返回值 :無
- **************************************************/
- void draw_dot(unsigned char x,unsigned char y,unsigned char color)
- {
- unsigned char row,tier,tier_bit;
- unsigned char read_old_h,read_old_l;
- write_cmd(0x34);
- write_cmd(0x36);
- tier=x>>4;
- tier_bit=x&0x0f;
- if(y<32)
- row=y;
- else
- {
- row=y-32;
- tier+=8;
- }
- write_cmd(row+0x80);
- write_cmd(tier+0x80);
- lcd_read_data();
- read_old_h=lcd_read_data();
- read_old_l=lcd_read_data();
- write_cmd(row+0x80);
- write_cmd(tier+0x80);
-
- if(tier_bit<8)
- {
- switch(color)
- {
- case 0:read_old_h&=(~(0x01<<(7-tier_bit)));break;
- case 1:read_old_h|=(0x01<<(7-tier_bit)) ;break;
- case 2:read_old_h^=(0x01<<(7-tier_bit)) ;break;
- default:break;
- }
- write_data(read_old_h);
- write_data(read_old_l);
-
- }
- else
- {
- switch(color)
- {
- case 0:read_old_l&=(~(0x01<<(15-tier_bit)));break;
- case 1:read_old_l|=(0x01<<(15-tier_bit)) ;break;
- case 2:read_old_l^=(0x01<<(15-tier_bit)) ;break;
- default:break;
- }
-
- write_data(read_old_h);
- write_data(read_old_l);
- }
-
- write_cmd(0x30);
-
- }
- /**************************************************
- 函數(shù)名稱:draw_level_line
- 功 能:水平線
- 參 數(shù):起始x0 x1 和y坐標(biāo) color 0反白 1復(fù)原
- 返回值 :無
- **************************************************/
- void draw_level_line(unsigned char x0,unsigned char x1,unsigned char y,unsigned char color)
- {
- unsigned char temp;
- if(x0>x1)
- {
- temp=x1;
- x1=x0;
- x0=temp;
- }
- for(;x0<=x1;x0++)
- {
- draw_dot(x0,y,color);
- }
-
- }
- /**************************************************
- 函數(shù)名稱:draw_vertical_line
- 功 能:垂直線
- 參 數(shù):起始y0 y1 和x坐標(biāo) color 0 1
- 返回值 :無
- **************************************************/
- void draw_vertical_line(unsigned char y0,unsigned char y1,unsigned char x,unsigned char color)
- {
- unsigned char temp;
- if(y0>y1)
- {
- temp=y1;
- y1=y0;
- y0=temp;
- }
- for(;y0<=y1;y0++)
- draw_dot(x,y0,color);
- }
- /**************************************************
- 函數(shù)名稱:draw_line
- 功 能:畫任意直線
- 參 數(shù):startx starty endx endy color
- 返回值 :無
- **************************************************/
- void draw_line(unsigned char startx,unsigned char starty
- ,unsigned char endx,unsigned char endy,unsigned char color)
- {
- int t,distance;
- int x=0,y=0,delta_x,delta_y;
- int incx,incy;
- delta_x=endx-startx;
- delta_y=endy-starty;
-
- if(delta_x>0)
- {
- incx=1;
- }
- else if(delta_x==0)
- {
- draw_vertical_line(startx,starty,endy,color);
- return;
- }
- else
- {
- incx= -1;
- }
- if(delta_y>0)
- {
- incy=1;
- }
- else if(delta_y==0)
- {
- draw_level_line(startx,endx,starty,color);
- return;
- }
- else
- {
- incy=-1;
- }
- delta_x=my_abs(delta_x);
- delta_y=my_abs(delta_y);
- if(delta_x>delta_y)
- {
- distance=delta_x;
- }
- else
- {
- distance=delta_y;
- }
- draw_dot(startx,starty,color);
- for(t=0;t<=distance+1;t++)
- {
- draw_dot(startx,starty,color);
- x+=delta_x;
- y+=delta_y;
- if(x>distance)
- {
- x-=distance;
- startx+=incx;
- }
- if(y>distance)
- {
- y-=distance;
- starty+=incy;
- }
-
- }
-
- }
- /**************************************************
- 函數(shù)名稱:contin_line
- 功 能:連續(xù)輸入Y 連成線,Y為0-63注意輸入進(jìn)來時(shí)做轉(zhuǎn)換 線從startx至endx 0-127為最大范圍
- 參 數(shù):startx endx endy color
- 返回值 :無
- **************************************************/
- void contin_line(unsigned char startx ,unsigned char endx ,unsigned char Y)
- {
- static unsigned char i=0,y0=0,y1=0,f=1; //i連線開始坐標(biāo)
- if(f) //用于將startx只在第一次傳遞給i
- {
- f=0;
- i = startx;
- }
- // x0=i;
- y1=Y; //畫該函數(shù)的圖形,完全連接了,
- if(i!=startx) //保證不與00坐標(biāo)連到一起
- draw_line(i-1,y0,i,y1,1);
- //x1=x0;
- y0=y1;
-
- if(i++>=endx) //連線結(jié)束坐標(biāo)
- {
-
- i=startx;
- clear_GDRAM();
- }
- }
- /**************************************************
- 函數(shù)名稱:draw_curve
- 功 能:將一系列無符號(hào)字符數(shù)組str的數(shù) 大小0-63注意傳遞前做處理,曲線開始位置 xstart 數(shù)組大小size
- 參 數(shù):起點(diǎn)startx size *str
- 返回值 :無
- **************************************************/
- void draw_curve(unsigned char xstart, unsigned char size ,unsigned char *str)
- {
- static unsigned char i=0,endx=0,y0=0,y1=0,f=1;
- if(f) //只傳遞一次
- {
- f=0;
- i = xstart;
- }
-
- endx = xstart + size;
- if(endx>=128) //保證圖形不溢出
- endx =127;
- for(;i<endx;i++)
- {
- y1 = str[i-xstart];
- if(i!=xstart)
- draw_line(i-1,y0,i,y1,1);
- y0 = y1;
- }
- i = xstart;
- //Clear_GDRAM();
-
- }
- /**************************************************
- 函數(shù)名稱:draw_circle
- 功 能:畫任意圓
- 參 數(shù):圓心坐標(biāo)xy 半徑r color
- 返回值 :無
- **************************************************/
- void draw_circle(unsigned char x,unsigned char y,unsigned char r,unsigned char color)
- {
- unsigned char a,b;
- float c;
- a = 0;
- b = r;
- // c = 1.25 - r;
- c = 3 - 2*r;
- while(a < b)
- {
- draw_dot(x+a,y+b,color);
- draw_dot(x-a,y+b,color);
- draw_dot(x+a,y-b,color);
- draw_dot(x-a,y-b,color);
-
- draw_dot(x+b,y+a,color);
- draw_dot(x-b,y+a,color);
- draw_dot(x+b,y-a,color);
- draw_dot(x-b,y-a,color);
-
- if(c < 0)
- {
- c = c+4*a + 6;
- }
- else
- {
- c= c + 4*(a - b) + 10;
- b-=1;
- }
- a = a + 1; //控制打點(diǎn)間隔
-
- }
- if(a == b)
- {
- draw_dot(x+a,y+b,color);
- draw_dot(x-a,y+b,color);
- draw_dot(x+a,y-b,color);
- draw_dot(x-a,y+b,color);
-
- draw_dot(x+b,y+a,color);
- draw_dot(x-b,y+a,color);
- draw_dot(x+b,y-a,color);
- draw_dot(x-b,y-a,color);
-
- }
- }
復(fù)制代碼
|