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

📄 nokia3310_5110液晶屏驱动m16.txt

📁 5110.rar
💻 TXT
字号:
/*所用CPU mega16     编译环境 GCC          中文资料下载http://rosibo12.bibidu.com/server85/380503217/LCD3310中文资料_LCD3310_CN.pdf*/


包含头文件 c文件   字库文件    AVR位操作头文件到我其他文章里看好了,自己写的时候搜了老半天没找到

一个合适的,有些还收费,气死人了,开源多好~~~


/*头文件lcd5110.h


#ifndef _lcd5110_h
#define _lcd5110_h

#include <avr/io.h>
#include <bit.h>

#define rst PORTABIT0
#define sce PORTABIT1
#define dc PORTABIT2
#define sdin PORTABIT3
#define sclk PORTABIT4

#define rst_out DDRABIT0=1
#define sce_out DDRABIT1=1
#define dc_out DDRABIT2=1
#define sdin_out DDRABIT3=1
#define sclk_out DDRABIT4=1

extern void write_byte(uchar byte,uchar cd_choice);
extern void lcd_init();
extern void setxy(uchar x,uchar y);
extern void clr_all();
extern void write_char(char char_write);
extern void disply_onechar(uchar x,uchar y,uchar char_disply);
extern void disply_listchar(uchar x ,uchar y,char *p);
extern void disply_number(uchar x,uchar y,unsigned long num);
extern void disply_float_number(unsigned char X,unsigned char Y,float NO);
#endif


//c文件


#include "lcd5110.h"
#include "font6x8.h"


void write_byte(uchar byte,uchar cd_choice)//写数据是1 写命令是0
{ 
uchar byte_cnt;
sce=0;              //芯片使能
if(cd_choice==1)dc=1;     //选择数据
else dc=0;
for(byte_cnt=0;byte_cnt<8;byte_cnt++)
{
   sclk=0;
   if(byte&(0x80>>byte_cnt))//高位先送
   sdin=1;
   else sdin=0;
   sclk=1;
}
sce=1;
}

void lcd_init()
{
rst_out;//将管脚设置为输出
sce_out;
dc_out;
sdin_out;
sclk_out;
sce=0;
rst=0;//复位
_nop_();
rst=1;
write_byte(0x23,0) ;         //设定芯片是活动的 水平寻址   扩展指令模式
write_byte(0xc8, 0);   // 设置偏置电压
    write_byte(0x06, 0);   // 温度校正
    write_byte(0x13, 0);   // 1:48
    write_byte(0x20, 0);   // 基本命令模式
write_byte(0x0c,0);         //正常显示
sce=1; 
clr_all();
}

void setxy(uchar x,uchar y)
{
x&=0x7f;                 //屏蔽高位
y&=0x07;
write_byte(x|0x80,0);
write_byte(y|0x40,0);
}

void clr_all()
{
uint data_cnt;
setxy(0,0);
for(data_cnt=0;data_cnt<504;data_cnt++)//一直连续写0
{
   write_byte(0,1);
}
}

void write_char(char char_write)
{
uchar byte_cnt;
for(byte_cnt=0;byte_cnt<6;byte_cnt++)//字库是6*8的
{
   write_byte(pgm_read_byte(font6x8[char_write-32]+byte_cnt),1);//将flash中的字库读取出来
}
}

void disply_onechar(uchar x,uchar y,uchar char_disply)
{
setxy(x,y);
write_char(char_disply);
}

void disply_listchar(uchar x ,uchar y,char *p)//将字符串的首地址给P
{
uchar cnt_temp;
setxy(x,y);
for(cnt_temp=0;*p!='\0';cnt_temp++)//未检测到字符串结束标志'\0'就一直写
{
   write_char(*(p++));
}
}

void disply_number(uchar x,uchar y,unsigned long num)
{
uchar number[8];
uchar k,j;
if(!num)
{
   disply_onechar(x,y,'0');
}
else
{
   for(k=0;num!=0;k++)
   {
    number[k]=(uchar)(num%10);
    num/=10;
   }
   setxy(x,y);
   for(j=k;j>0;j--)
   {
    write_char(number[j-1]+48); 
   }
}
}

//写浮点数
void disply_float_number(unsigned char X,unsigned char Y,float NO)
{
uchar i,length=0;
unsigned long int temp=(unsigned long int)NO;//取整数部分
disply_number(X,Y,temp);
    NO=NO-temp;//取小数部分

if(!NO)return;
else
{
   for(i=0;;i++)
   { 
    temp=temp/10;
    length++;
    if(temp==0) break;//判断整数的位数
   }
   disply_onechar(X+(length*6),Y,'.'); 
   temp=(unsigned long int)(NO*10000);//显示
   disply_number(X+(length+1)*6,Y,temp);
}
}



//字库font6x8.h

#ifndef _font6x8_h
#define _font6x8_h
#include <avr/pgmspace.h>

const prog_char font6x8[][6] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },// sp
{ 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 },// !
{ 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 },// "
{ 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 },// #
{ 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 },// $
{ 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 },// %
{ 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 },// &
{ 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 },// '
{ 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 },// (
{ 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 },// )
{ 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 },// *
{ 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 },// +
{ 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 },// ,
{ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 },// -
{ 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 },// .
{ 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 },// /
{ 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E },// 0
{ 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 },// 1
{ 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 },// 2
{ 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 },// 3
{ 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 },// 4
{ 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 },// 5
{ 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 },// 6
{ 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 },// 7
{ 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 },// 8
{ 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E },// 9
{ 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 },// :
{ 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 },// ;
{ 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 },// <
{ 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 },// =
{ 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 },// >
{ 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 },// ?
{ 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E },// @
{ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C },// A
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 },// B
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 },// C
{ 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C },// D
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 },// E
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 },// F
{ 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A },// G
{ 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F },// H
{ 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 },// I
{ 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 },// J
{ 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 },// K
{ 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 },// L
{ 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F },// M
{ 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F },// N
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E },// O
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 },// P
{ 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E },// Q
{ 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 },// R
{ 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 },// S
{ 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 },// T
{ 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F },// U
{ 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F },// V
{ 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F },// W
{ 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 },// X
{ 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 },// Y
{ 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 },// Z
{ 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 },// [
{ 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 },// 55
{ 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 },// ]
{ 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 },// ^
{ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 },// _
{ 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 },// '
{ 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 },// a
{ 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 },// b
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 },// c
{ 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F },// d
{ 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 },// e
{ 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 },// f
{ 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C },// g
{ 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 },// h
{ 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 },// i
{ 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 },// j
{ 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 },// k
{ 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 },// l
{ 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 },// m
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 },// n
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 },// o
{ 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 },// p
{ 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC },// q
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 },// r
{ 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 },// s
{ 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 },// t
{ 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C },// u
{ 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C },// v
{ 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C },// w
{ 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 },// x
{ 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C },// y
{ 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 },// z
{ 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 }// horiz lines
};
#endif

⌨️ 快捷键说明

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