#define uchar unsigned char
#define uint unsigned int
uchar rebuf[11]
uchar tembuf[2]={28,20}
sbitsce = P0^0 //片选
sbitres = P0^1 //复位,0复位
sbitdc = P0^2 //1写数据,0写指令
sbitsdin = P0^3 //数据
sbitsclk = P0^4 //时钟
sbiten = P3^2
sbitkey1 = P1^0
sbitkey2 = P1^1
sbitkey3 = P1^2
sbitkey4 = P1^3
sbitkey5 = P1^4
sbitkey6 = P1^5
sbitalarm = P2^7
uchar dp=0,re_data,keynum = 0
bit full=0,f_alarm=0,m_alarm = 0
unsigned char code shuzi[]={
/*-- 文字: 0 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
/*-- 文字: 1 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
/*-- 文字: 2 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
/*-- 文字: 3 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
/*-- 文字: 4 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
/*-- 文字: 5 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
/*-- 文字: 6 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,
/*-- 文字: 7 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
/*-- 文字: 8 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
/*-- 文字: 9 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,
/*-- 文字: . --10*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: : --11*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,
/*-- 调入了一幅图像:这是您新建的图像 --12*/
/*-- 宽度x高度=8x16 --*/
0x0C,0x12,0x0C,0x80,0x40,0x20,0x20,0x20,0x00,0x00,0x00,0x0F,0x10,0x20,0x20,0x20,
}
unsigned char code hanzi[]=
{
/*-- 文字: 光 0--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x40,0x42,0x44,0x5C,0xC8,0x40,0x7F,0x40,0xC0,0x50,0x4E,0x44,0x60,0x40,0x00,
0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x78,0x00,
/*-- 空白 1--*/
/*-- 宽度x高度=16x16 --*/
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,
/*-- 一级光 2--*/
/*-- 宽度x高度=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xF0,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 二级光 3--*/
/*-- 宽度x高度=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xF0,0xF0,0xF0,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 三级光 4--*/
/*-- 宽度x高度=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,
0xF0,0xF0,0xF0,0x00,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
/*-- 四级光 5--*/
/*-- 宽度x高度=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0x00,0xFF,0xFF,0xFF,0x00,
0xF0,0xF0,0xF0,0x00,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0x00,
/*-- 文字: 报 6--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x08,0x08,0x88,0xFF,0x48,0x28,0x00,0xFF,0xC1,0x41,0x41,0x49,0x51,0xCF,0x00,0x00,
0x01,0x41,0x80,0x7F,0x00,0x00,0x00,0xFF,0x40,0x23,0x14,0x1C,0x33,0x60,0x20,0x00,
/*-- 文字: 警 7--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x1A,0xFA,0xAF,0xAA,0xEF,0x0A,0xFA,0x10,0x8F,0x54,0x24,0x5C,0x84,0x04,0x00,
0x02,0x02,0x02,0xEA,0xAA,0xAA,0xAB,0xAA,0xAB,0xAA,0xAA,0xEA,0x02,0x02,0x03,0x00,
/*-- 文字: 温 8--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00,
0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00,
/*-- 文字: 度 9--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00,
0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00,
/*-- 文字: 高 10--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x04,0x04,0x04,0x04,0x74,0x54,0x55,0x56,0x54,0x54,0x74,0x04,0x04,0x04,0x04,0x00,
0x00,0xFF,0x01,0x01,0x3D,0x25,0x25,0x25,0x25,0x25,0x3D,0x41,0x81,0x7F,0x00,0x00,
/*-- 文字: 低 11--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x20,0xF0,0x0C,0x07,0x02,0xFC,0x44,0x44,0x42,0xFE,0x43,0x43,0x42,0x40,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x20,0x10,0x28,0x43,0x0C,0x10,0x20,0x78,0x00,
}
/************************************************************
延迟函数
函数原型:void delay(uint z)
函数功能:延迟z毫秒
*************************************************************/
void delay(uint z)
{
uint x,y
for(x=zx>0x--)
for(y=110y>0y--)
}
/*--------------------------------------------
LCD_write_byte: 使用SPI接口写数据到LCD
输入参数:dt:写入的数据;
command :写数据/命令选择;
编写日期:20080918
----------------------------------------------*/
void LCD_write_byte(unsigned char dt, unsigned char command)
{
unsigned char i
sce=0
dc=command
for(i=0i<8i++)
{
if(dt&0x80)
sdin=1
else
sdin=0
dt=dt<<1
sclk=0
sclk=1
}
dc=1
sce=1
sdin=1
}
/*---------------------------------------
LCD_init: 3310LCD初始化
编写日期:20080918
----------------------------------------- */
void LCD_init(void)
{
res=0
delay(1)
res=1
LCD_write_byte(0x21,0)//初始化Lcd,功能设定使用扩充指令
LCD_write_byte(0xd0,0)//设定液晶偏置电压
LCD_write_byte(0x20,0)//使用基本指令
LCD_write_byte(0x0C,0)//设定显示模式,正常显示
}
/*-------------------------------------------
LCD_set_XY: 设置LCD坐标函数
输入参数:X:0-83 Y:0-5
编写日期:20080918
---------------------------------------------*/
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_clear: LCD清屏函数
编写日期:20080918
--------------------------------------------*/
void LCD_clear(void)
{
unsigned char t
unsigned char k
LCD_set_XY(0,0)
for(t=0t<6t++)
{
for(k=0k<84k++)
{
LCD_write_byte(0x00,1)
}
}
}
/*---------------------------------------------
LCD_write_shu: 显示8(宽)*16(高)点阵列数字字母符号等半角类
输入参数:c:显示的字符;
编写日期:20080918
-----------------------------------------------*/
void LCD_write_shu(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符
{
unsigned char i
LCD_set_XY(row*8, page)// 列,页
for(i=0i<8i++)
{
LCD_write_byte(shuzi[c*16+i],1)
}
LCD_set_XY(row*8, page+1)// 列,页
for(i=8i<16i++)
{
LCD_write_byte(shuzi[c*16+i],1)
}
}
/*---------------------------------------------
LCD_write_hanzi: 显示16(宽)*16(高)点阵列汉字等半角类
输入参数:c:显示的字符;
编写日期:20080918
-----------------------------------------------*/
void LCD_write_hanzi(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符
{
unsigned char i
LCD_set_XY(row*8, page)// 列,页
for(i=0i<16i++)
{
LCD_write_byte(hanzi[c*32+i],1)
}
LCD_set_XY(row*8, page+1)// 列,页
for(i=16i<32i++)
{
LCD_write_byte(hanzi[c*32+i],1)
}
}
/*---------------------------------------------
void display(): 显示函数
输入参数:无;
编写日期:2009,10
-----------------------------------------------*/
void display()
{
if(rebuf[10]==0xaa)
{
LCD_write_shu(1,0,rebuf[1]) //ID1
LCD_write_shu(2,0,rebuf[2]) //ID2
LCD_write_shu(3,0,rebuf[3]) //ID3
LCD_write_shu(0,2,rebuf[4]) //tem1
LCD_write_shu(1,2,rebuf[5]) //tem2
LCD_write_shu(2,2,10) //.
LCD_write_shu(3,2,rebuf[6]) //tem3
LCD_write_shu(4,2,12) //℃
LCD_write_hanzi(0,4,0) //光
LCD_write_shu(2,4,11) //:
LCD_write_hanzi(3,4,(rebuf[8]+1)) //
if((rebuf[4]>=(tembuf[0]/10))&&(rebuf[5]>=(tembuf[0]%10)))
f_alarm = 1
else
f_alarm = 0
if((rebuf[4]<=(tembuf[1]/10))&&(rebuf[5]<=(tembuf[1]%10)))
f_alarm = 1
else
f_alarm = 0
}
if(rebuf[10]==0xbb)
{
LCD_write_shu(6,0,rebuf[1]) //ID1
LCD_write_shu(7,0,rebuf[2]) //ID2
LCD_write_shu(8,0,rebuf[3]) //ID3
LCD_write_shu(5,2,rebuf[4]) //tem1
LCD_write_shu(6,2,rebuf[5]) //tem2
LCD_write_shu(7,2,10) //.
LCD_write_shu(8,2,rebuf[6]) //tem3
LCD_write_shu(9,2,12) //℃
LCD_write_hanzi(5,4,0) //光
LCD_write_shu(7,4,11) //:
LCD_write_hanzi(8,4,(rebuf[8]+1)) //
if((rebuf[4]>=(tembuf[0]/10))&&(rebuf[5]>=(tembuf[0]%10)))
m_alarm = 1
else
m_alarm = 0
if((rebuf[4]<=(tembuf[1]/10))&&(rebuf[5]<=(tembuf[1]%10)))
m_alarm = 1
else
m_alarm = 0
}
}
Nokia 5110可谓是相~ 当~ 经典了,你可以用它来打电话、砸核桃、挡子d、锤钉子,居家防身,良心佳品~= ̄ω ̄=它的屏幕因为某宝上只买八块八,八块八啊~ 物美价廉,受到广大青少年的追捧~
Nokia 5110的屏幕使用的是SPI协议,但使用我图片中的屏幕模块,除了需要连接SPI的4条信号线外,还需要另外连接一个RST(重置)和BL(背光)。
Nokia 5110屏幕模块有下列引脚:
上面的电路图太乱太难看,要理清的话,一半脑细胞都可以住进精神病院了。总之Nokia 5110的屏幕是SPI通信的,参考SPI的连接方法就对了。
上面的初始化流程中给出了一些默认值,在实际使用的过程中,因为模块的不同,这些参数可能需要重新调整才能获得理想的显示效果
我们使用Arduino的硬件SPI接口来和屏幕通信,所以我们需要使用Arduino内建的SPI库
我用过诺基亚5110显示屏,不会存在复位有时不显示,有时显示。出现你这个的情况很可能是因为复位质量太差,比如复位电压不高或者复位时电压毛刺太多,你可以试着复位时按键按下的时间长一些,看有无改善。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)