显示的程序如何用结构体封装起来呢?
- //==========================================================================
- //程序功能: 1Lcd初始化
- // 2Lcd清屏
- // 3Lcd满屏
- // 4Lcd显示一行
- // 5Lcd画一个点
- // 6lcd指定位置显示一个字
- // 7Lcd指定位置显示一串汉字
- // 8Lcd指定位置写一串英文字符串,每行最多可写21个字符
- // 9lcd指定位置显示特定大小的图片
- // 10lcd整屏显示128x64点阵图片,要求图片长128、宽64个像素点
- // 11lcd指定位置写一串英文字符串,每行最多可写21个字符
- //void Disp_Img(unsigned char code *img)
- // 程序接口:void Lcd_Init(void);
- // void Lcd_Clr(void);
- // void Lcd_Full(void);
- // void Lcd_DispOneRow(unsigned char x, unsigned char y, unsigned char *buf, unsigned char len);
- // void DrawDot_12864(unsigned char y,unsigned char x,unsigned char type);
- // void Lcd_WriteChinese(unsigned char x, unsigned char y, unsigned char *img)
- // void Lcd_WriteChineseString(unsigned char x, unsigned char y, unsigned char *img, unsigned char len);
- // void Lcd_WriteEnglishString(unsigned char x,unsigned char y,unsigned char *s)
- // void Lcd_DispImg(unsigned char x, unsigned char y, unsigned char wid, unsigned char lon, unsigned char code *img)
- // void Disp_Img(unsigned char code *img)/void Lcd_DispFullImg(unsigned char *img)
- // void Lcd_WriteEnglishString(unsigned char x,unsigned char y,unsigned char *s)
- // 编写时间: 2015-07-26
- //==========================================================================
- /**************************************************************************
- 1. void Lcd_DispFullImg(unsigned char *img);//显示一幅全屏图像,图像像素点满足128x64,单位:像素点
- 2. void Lcd_DispImg(unsigned char x, unsigned char y, unsigned char lon, unsigned char wid, unsigned char *img); //指定位置显示特定大小的图片
- (2)屏蔽了未使用到的接口函数。
- ****************************************************************************/
- #include "Global.h"
- //#include "lcd595.h"
- #include "LCD12864.h"
- #include "english_8x16_ASCII.h"
- #include "intrins.h"
- //==========================================================================
- // 函数功能: Lcd的接02口信号(逻辑管脚与物理管脚的对应表)
- //==========================================================================
- sbit LCD_BL = P0^0;
- sbit LCD_RST = P0^1;
- sbit LCD_CS2 = P0^2;
- sbit LCD_CS1 = P0^3;
- sbit LCD_E = P0^4;
- sbit LCD_RW = P0^5;
- sbit LCD_RS = P0^6;
- #define LCD_DATA P2
- //==========================================================================
- // 函数功能: 本地变量及常量的定义
- //==========================================================================
- #ifdef FREQ_24M
- #define NOP Delay_uS(4)
- #else
- #define NOP Delay_uS(1)
- #endif
-
- /*100us延时*/
- void delay100us(void) //误差 -0.234375us
- {
- unsigned char i;
- _nop_();
- i = 43;
- while (--i);
- }
- //==========================================================================
- // 函数功能: 1微秒延时函数
- //==========================================================================
- //void Delay_uS(unsigned char us_value)
- //{
- // unsigned char i;
- //
- // while(us_value--)
- // {
- // for(i=0; i<16; i++);
- // }
- //}
- //==========================================================================
- // 函数功能: 1毫秒延时函数
- //==========================================================================
- extern void Delay_mS(unsigned int ms_value)
- {
- unsigned int k;
-
- #ifdef FREQ_24M
- for(k=0; k<(4*ms_value); k++)
- #else
- for(k=0; k<(ms_value); k++)
- #endif
- {
- Delay_uS(200);
- }
- }
- //==========================================================================
- // 函数功能: 检测是否空闲
- //==========================================================================
- void BusycChk_12864(void)
- {
- unsigned int timeout = 0;
-
- LCD_E = 0;
- LCD_RS = 0;
- LCD_RW = 1;
- LCD_E = 1;
- while((LCD_DATA & 0x80) && ++timeout != 0); //忙状态检测, 等待超时时间为60ms
- LCD_E = 0;
- }
- //==========================================================================
- // 函数功能: 往12864读数据
- //==========================================================================
- unsigned char LCD_RdData(void)
- {
- unsigned char temp;
-
- BusycChk_12864();
- LCD_E = 0;
- LCD_DATA = 0xFF; //IO口置高电平, 以便读引脚
- LCD_RS = 1;
- LCD_RW = 1;
- LCD_E = 1;
- NOP; //使能延时, 如果是较快的CPU应该延时久一些
- NOP;
- NOP;
- temp = LCD_DATA ;
-
- return temp;
- }
- //==========================================================================
- // 函数功能: 往12864写命令
- //==========================================================================
- void Lcd_WrCmd(unsigned char cmd)
- {
- LCD_RS = 0;
- LCD_RW = 0;
- //lcdhc595(cmd);
- LCD_DATA =cmd;
- LCD_E = 1;
- NOP;
- LCD_E = 0;
- }
- //==========================================================================
- // 函数功能: 往12864写数据
- //==========================================================================
- void Lcd_WrData(unsigned char wdata)
- {
- LCD_RS = 1;
- LCD_RW = 0;
- //lcdhc595(wata);
- LCD_DATA=wdata;
- LCD_E = 1;
- NOP;
- LCD_E = 0;
- }
- //==========================================================================
- // 函数功能: 地址转换
- //==========================================================================
- void Lcd_Select(unsigned char x, unsigned char y)
- {
- if( y>=64 )
- {
- LCD_CS2 = 1; //选中左屏
- LCD_CS1 = 0;
- }
- else
- {
- LCD_CS1 = 1; //选中右屏
- LCD_CS2 = 0;
- }
-
- Lcd_WrCmd(0xC0);
- Lcd_WrCmd(0x40 + (y&0x3F)); //列地址
- Lcd_WrCmd(0xB8 + (x&7)); //行
- }
- //==========================================================================
- // 函数功能: Lcd清屏
- // 函数接口: void Lcd_Clr(void);
- //==========================================================================
- void Lcd_Clr(void)
- {
- unsigned char i, x=0;
-
- for(x=0; x<8; x++)
- {
- Lcd_Select(x, 0); //选中左屏
- for(i=0; i<64; i++)
- {
- Lcd_WrData(0);
- }
-
- Lcd_Select(x, 64); //选中右屏
- for(i=0; i<64; i++)
- {
- Lcd_WrData(0);
- }
- }
- }
- //==========================================================================
- // 函数功能: Lcd初始化
- // 函数接口: void Lcd_Init(void);
- //==========================================================================
- void Lcd_Init (void)
- {
- LCD_BL = 0; //打开背光
- LCD_RST = 0;
- Delay_mS(100);
- LCD_RST = 1;
- Delay_mS(1);
-
- LCD_CS1 = 1;
- LCD_CS2 = 1;
- Lcd_WrCmd(0xC0); //设置显示起始行
- Lcd_WrCmd(0x3F); //显示打开
- Lcd_Clr(); //清屏
- }
- //==========================================================================
- // 函数功能: Lcd满屏
- // 函数接口: void Lcd_Full(void);
- //==========================================================================
- //void Lcd_Full(void)
- //{
- // unsigned char i, x=0;
- //
- // for(x=0; x<8; x++)
- // {
- // Lcd_Select(x, 0); //选中左屏
- // for(i=0; i<64; i++)
- // {
- // Lcd_WrData(0xFF);
- // }
- //
- // Lcd_Select(x, 64); //选中右屏
- // for(i=0; i<64; i++)
- // {
- // Lcd_WrData(0xFF);
- // }
- // }
- //}
- //==========================================================================
- // 函数功能: Lcd显示一行
- // 函数接口: void Lcd_DispOneRow(unsigned char x, unsigned char y, unsigned char *buf, unsigned char len);
- // 入口参数: unsigned char x, unsigned char y, unsigned char *buf, unsigned char len
- // x-显示行, 0~7(一行宽度为8个点)
- // y-显示起始列, 0~127, 超过列显示无效
- // buf-指向要显示的数组
- // len-要显示的数据长度
- //==========================================================================
- /*void Lcd_DispOneRow(unsigned char x, unsigned char y, unsigned char *buf, unsigned char len)
- {
- x = x&7;
-
- Lcd_Select(x, y);
- while(len--)
- {
- Lcd_WrData(*buf);
- buf++;
- y++;
- if( y == 64 )
- {
- Lcd_Select(x, y); //选中右屏
- }
- }
- }*/
- /*****************************************************************************
- * 函数功能: 整屏显示128x64点阵图片,要求图片长128、宽64个像素点
- * 函数接口: void Disp_Img(unsigned char code *img)
- * 入口参数: unsigned char code *img
- * img-指向待显示的图片
- *****************************************************************************/
- void Lcd_DispFullImg(unsigned char *img) //显示图片
- {
- unsigned char i=0,j=0;
- for(i=0;i<8;i++)
- {
- Lcd_Select(i, 0);
- for(j=0;j<128;j++)
- {
- if( j == 64 )
- {
- Lcd_Select(i, j); //选中右屏
- }
- Lcd_WrData(*img);
- img++;
- }
- }
- }
- /*****************************************************************************
- * 函数功能:指定位置显示特定大小的图片
- * 函数接口: void Lcd_DispImg(unsigned char x, unsigned char y, unsigned char wid, unsigned char lon, unsigned char code *img)
- * 入口参数: unsigned char x, unsigned char y, unsigned char wid, unsigned char lon, unsigned char code *img
- * x-显示起始行, 0~7(一行宽度为8个点)
- * y-显示起始列, 0~127, 超过列显示无效
- * wid-图片宽度,单位:像素点,最大值64
- * lon-图片长度,单位:像素点,最大值128
- * img-指针,指向待显示的图片
- *****************************************************************************/
- void Lcd_DispImg(unsigned char x, unsigned char y, unsigned char wid, unsigned char lon, unsigned char *img) //指定位置显示特定大小的图片
- {
- unsigned char i=0,j=0,k;
- k=wid/8;//16/8=2
- for(i=x;i<(k+x);i++)
- {
- Lcd_Select(i, y);
- for(j=y;j<(lon+y);j++)
- {
- if( j == 64 )
- {
- Lcd_Select(i, j); //选中右屏
- }
- Lcd_WrData(*img);
- img++;
- }
- }
- }
- /*****************************************************************************
- * 函数功能:在x行写一个字符,输入列计数初值,返回最终列计数的最后值,
- * 该列计数用于确定选中左OR右半屏幕
- * 函数接口: unsigned char Lcd_WriteCharData(unsigned char c,unsigned char x, unsigned char lineCount)
- * 入口参数: unsigned char c,unsigned char x, unsigned char lineCount
- * unsigned char c,要写入的字符
- * unsigned char x,要写入的行
- * unsigned char lineCount,列计数,用于确定选中左或右半屏幕
- *****************************************************************************/
- void Lcd_WriteEnglish(unsigned char x,unsigned char y, unsigned char c)
- {
- unsigned char i,line,temp;
- c -= 32;
- for(i=0;i<2;i++)
- {
- Lcd_Select(x+i,y);
- temp=i<<3;
- for(line=0; line<8; line++)
- {
- if((y+line)==64)
- {Lcd_Select(x+i,y+line);}//选中右半屏幕
- Lcd_WrData(font8x16[c][line+temp]);//此处的temp用于存放i*8的结果,
- }
- }
- }
- /*****************************************************************************
- * 函数功能:指定位置写一串英文字符串,每行最多可写21个字符
- * 函数接口: void Lcd_WriteEnglishString(unsigned char x,unsigned char y,unsigned char *s)
- * 入口参数: unsigned char x,unsigned char y,unsigned char *s
- * unsigned char x,行值,取值范围0~7
- * unsigned char y,列值,取值范围0~127
- * unsigned char *s,s指向待写入的字符串
- *****************************************************************************/
- void Lcd_WriteEnglishString(unsigned char x,unsigned char y,unsigned char *s)
- {
- unsigned char lineCount=0;
- while(*s)
- {
-
- Lcd_WriteEnglish( x, y+lineCount, *s);
- lineCount+=8;//每个英文字符占用8列
- s++;
- }
- }
- /*****************************************************************************
- * 函数功能:指定位置显示一串汉字
- * 函数接口: void Lcd_DispImg(unsigned char x, unsigned char y, unsigned char wid, unsigned char lon, unsigned char code *img)
- * 入口参数: unsigned char x, unsigned char y, unsigned char wid, unsigned char lon, unsigned char code *img
- * x-显示起始行, 0~7(一行宽度为8个点)
- * y-显示起始列, 0~127, 超过列显示无效
- * wid-图片宽度,单位:像素点,最大值64
- * lon-图片长度,单位:像素点,最大值128
- * img-指针,指向待显示的图片
- *****************************************************************************/
- void Lcd_WriteChinese(unsigned char x, unsigned char y, unsigned char *img) //显示1个汉字
- {
- Lcd_DispImg( x, y, 16, 16, (unsigned char *)img);
- }
- void Lcd_WriteChineseString(unsigned char x, unsigned char y, unsigned char *img, unsigned char len) //显示一串汉字
- {
- unsigned char i;
-
- for(i=0;i<len;i++)
- {
- Lcd_WriteChinese(x, y, (unsigned char *)img);
- y += 16;
- img += 32;
-
- }
- }
- //==========================================================================
- // 函数功能: Lcd画点
- // 函数接口: void DrawDot_12864(unsigned char x, unsigned char y, unsigned char type);
- // 出口参数: unsigned char x, unsigned char y, unsigned char type
- // x-显示行, 0~63
- // y-显示起始列, 0~127, 超过列显示无效
- //==========================================================================
- /*void DrawDot_12864(unsigned char x, unsigned char y, unsigned char type)
- {
- unsigned char X, Y; //X存储行地址, Y存储列地址
- unsigned char dat, temp;
-
- if( x >= 0 && x < 64 )
- {
- X = x/8;
- Y = y;
- }
- Lcd_Select(X, Y); //地址转换
-
- dat = LCD_RdData(); //假读
- dat = LCD_RdData();
-
- temp = x % 8; //余数为点在字中的位置
-
- switch(type) //画点类型, 0白, 1黑, 2取反
- {
- case 0:
- dat &= ~(0x01 << temp);; //修改该点同时保持其他位不变
- break;
- case 1:
- dat |= (0x01 << temp); //修改该点同时保持其他位不变
- break;
- case 2:
- dat ^= (0x01 << temp);; //修改该点同时保持其他位不变
- break;
- default:
- break;
- }
- Lcd_Select(X, Y);
- Lcd_WrData(dat); //将字节数据写回
- }*/
复制代码
|