⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3310xianshi.c

📁 NOKIA手机屏3310驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
}

/*---------------------------------------
LCD_init: 3310LCD初始化
编写日期:2004-8-10
最后修改日期:2004-8-10
-----------------------------------------  */
void LCD_init(void)
{
LCD_write_byte(0x21,0);//初始化Lcd,功能设定使用扩充指令
LCD_write_byte(0xe3,0);//设定液晶偏置电压(高--低)
LCD_write_byte(0x20,0);//使用基本指令
LCD_write_byte(0x0C,0);//设定显示模式,正常显示
}
/*------------------------------------------
LCD_clear: LCD清屏函数
编写日期:2004-8-10
最后修改日期:2004-8-10
--------------------------------------------*/
void LCD_clear(void)
{
uchar t;
uchar k;
uint d=0;
for(t=0;t<6;t++)
{
for(k=0;k<84;k++)
{
LCD_write_byte(0,1);
d=d+1;
}
}
}
/*-------------------------------------------
LCD_set_XY: 设置LCD坐标函数
输入参数:X:0-83
Y:0-5
编写日期:2004-8-10
最后修改日期:2004-8-10
---------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0);// column
LCD_write_byte(0x80 | X, 0);// row
}
/*---------------------------------------------
LCD_write_char: 显示英文字符
输入参数:c:显示的字符;
编写日期:2004-8-10
最后修改日期:2004-8-10
-----------------------------------------------*/
void LCD_write_char(unsigned char c)
{
unsigned char line;
c-= 32;
for (line=0; line<6; line++)
LCD_write_byte(font6x8[c][line], 1);
}
/*---------------------------------------------
LCD_write_string: 英文字符串显示函数
输入参数:*s:英文字符串指针;
X、Y: 显示字符串的位置
----------------------------------------------*/
void LCD_write_String(unsigned char X,unsigned char Y,char *s)
{
LCD_set_XY(X,Y);
while (*s)
{
LCD_write_char(*s);
s++;
}
}

/*--------------------------------------------
LCD_draw_map: 位图绘制函数
输入参数:X、Y:位图绘制的起始X、Y坐标;
*map:位图点阵数据;
Pix_x:位图像素(长)
Pix_y:位图像素(宽)
编写日期:2004-8-13
最后修改日期:2004-8-13
---------------------------------------------*/
void LCD_draw_map(unsigned char X,unsigned char Y,unsigned char *map,
unsigned char Pix_x,unsigned char Pix_y)
{
unsigned int i,n;
unsigned char row;
if (Pix_y%8==0) row=Pix_y/8;//计算位图所占行数
else
row=Pix_y/8+1;
for (n=0;n<row;n++)
{
LCD_set_XY(X,Y);
for(i=0; i<Pix_x; i++)
{
LCD_write_byte(map[i+n*Pix_x], 1);
}
Y++;//换行
}
}

/*********************************************************************************
** 函数名:void FLOAT_NUM_Display(float dd)***************************************
** 功能:显示浮点型数字(6位有效数字)********************************************
** 入口参数:float dd (dd 为调用这个子程序时传入的数据)*************************
** 出口参数:无 ******************************************************************
**注意各变量的数据类型,数的有效范围***********************************************
**实现方式:从小数点第六位 起往左逆向取数字,存入数组,再正向输出7位数字**********
**该函数的缺陷是:小数部分最多显示六位,如0.000020*********************************/
void FLOAT_NUM_Display(float dd,uchar x,uchar y)
{unsigned long frequency;  //显示整型定义
uchar code CHR[] = {'0','1','2','3','4','5','6','7','8','9'};
uchar LCDDisplaybuffer[32]={0};
  uchar i,j,k=0;
  frequency=(unsigned long)(dd*1000000);//取小数点后六位
  if(frequency>=10000000) //整数部分不为0
    {
      for (i=0;i<16;i++)
         {
          if(i==6)
             {
                LCDDisplaybuffer[i]='.';
             }
           else
             {
             LCDDisplaybuffer[i]=CHR[frequency%10];
              frequency/=10;
             }

          if(frequency==0)
                 {
                     i++;
                     break;
                 }
          }
      }
   else            //整数部分为0
      {
       for (i=0;i<8;i++)
         {
          if(i==6)
             {
                LCDDisplaybuffer[i]='.';
             }
           else
             {
              LCDDisplaybuffer[i]=CHR[frequency%10]	;
              frequency/=10;
             }
       }
    }
	    LCD_set_XY(x,y);
   for (j=0;j<7;j++)     //可以通过改变j的范围来增减显示的位数
       {

          LCD_write_char(LCDDisplaybuffer[i-1]);
          i--;

       }



}



/*------------------------------------------
LCD_write_chi: 在LCD上显示汉字
输入参数:X、Y:显示汉字的起始X、Y坐标;
ch_with :汉字点阵的宽度
num:显示汉字的个数;
line:汉字点阵数组中的起始行数
row:汉字显示的行间距
编写日期:2004-8-11
最后修改日期:2004-8-12
-------------------------------------------*/
void LCD_write_chi(unsigned char X, unsigned char Y,
unsigned char ch_with,unsigned char num,
unsigned char line,unsigned char row,uchar (*chi)[24])
{
unsigned char i,n;
LCD_set_XY(X,Y);//设置初始位置
for (i=0;i<num;)
{
for (n=0; n<ch_with*2; n++)//写一个汉字
{
if (n==ch_with)//写汉字的下半部分
{
if (i==0) LCD_set_XY(X,Y+1);
else
LCD_set_XY((X+(ch_with+row)*(i%7)),Y+1);
}
LCD_write_byte(chi[line+i][n],1);
}
i++;
if(i%7==0)
{Y+=2;
}
LCD_set_XY((X+(ch_with+row)*(i%7)),Y);

}
 }


//文件名delay.c
/*----------------------------------------------
延时函数
系统时钟:12M
------------------------------------------------*/
void delay_1us(void)//1us延时函数
{
_nop_();
}
void delay_nus(unsigned int n)//N us延时函数
{
unsigned int i=0;
for (i=0;i<n;i++)
delay_1us();
}
void delay_1ms(void)//1ms延时函数
{
unsigned int i;
for (i=0;i<1140;i++);
}
void delay_nms(unsigned int n)//N ms延时函数
{
unsigned int i=0;
for (i=0;i<n;i++)
delay_1ms();
}

/*********************************************************
******************************************************
**********************************************************/
void main()
{
LCD_init(); //初始化LCD模块

LCD_clear(); //清屏幕
LCD_write_String(0,0,"www.hdu.edu.cn"); //显示英文字符串”www.527dz.com“
LCD_draw_map(0,0,AVR_bmp,40,24); //显示“AVR”位图
LCD_draw_map(44,1,china_bmp,36,15); //显示”实验室“位图
FLOAT_NUM_Display(3.1415926,0,4);
LCD_write_chi(0,0,12,12,0,0,china_char);
while(1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -