[RPI2]wiringPi驱动5110

本文介绍如何使用树莓派驱动诺基亚5110的LCD显示屏,包括通过SSH和Samba连接树莓派,以及使用C语言编写的详细驱动程序代码,实现文字和数字的显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天闲来无事,翻箱倒柜的找出了诺基亚5110的显示屏,心想,闲着也是闲着,干脆驱动下吧,于是就有了这个帖子

首先呢,看到这个帖子的朋友们应该手上都有了树莓派,下面就来发挥他的光和热吧(话说发热量真不小)

  1. ssh连接树莓派
  2. samba连接树莓派
  3. 在windows下登陆samba服务器
  4. 新建5110.c文件(代码和文件都放在附件里了)

#include <stdio.h>
#include <wiringPi.h>
#include  "font.h"

#define uint unsigned int
#define uchar unsigned char



#define LCD_CLK 8
#define LCD_DIN 9
#define LCD_DC 7
#define LCD_CE  0
#define LCD_RST 2
  


/*
********************************************************** 
   函数声明区
**********************************************************
*/
void LCD_Init(void);
void LCD_WriteByte(unsigned char dat, unsigned char command);
void LCD_Set_XY(unsigned char X, unsigned char Y);
void LCD_Clear(void);
void LCD_WriteChar(unsigned char x,unsigned char y,unsigned char c);
void LCD_WriteString(unsigned char X,unsigned char Y,char *s);
void LCD_WriteNum(unsigned char X,unsigned char Y,unsigned int num);
void LCD_Write_12X16Font(unsigned char x,unsigned char y,unsigned char c[2]);
void LCD_DrawPicture(unsigned char X,unsigned char Y,unsigned char const *map,
  unsigned char Pix_x,unsigned char Pix_y);

/*
********************************************************** 
*函数名:LCD_Init
*功能:初始化LCD
*参数:无
  
*返回值:无
*备 注: 
**********************************************************
*/
void LCD_Init(void)
{
  unsigned char i;
  digitalWrite (LCD_RST, LOW) ; // Off
  for(i=0;i<150;i++);

  digitalWrite (LCD_RST, HIGH) ;  // On 
  LCD_WriteByte(0x21, 0);	// 使用扩展命令设置LCD模式
  LCD_WriteByte(0x06, 0);
  LCD_WriteByte(0x13, 0);
  LCD_WriteByte(0xc8, 0);

  LCD_WriteByte(0xc0, 0);	// 设置对比度,修改可改变5110点阵显示的亮度

  LCD_WriteByte(0x20, 0);	// 使用基本命令。并设置V=0,水平寻址
  LCD_WriteByte(0x0c, 0); 	// 设定显示模式,正常显示(普通显示)
  LCD_Clear();	// 清屏
  // digitalWrite (LCD_CE, LOW) ; // Off	  
}
 
/*
********************************************************** 
*函数名:LCD_WriteByte
*功能:模拟SPI接口时序写数据/命令LCD
*参数:data:写入的数据;
  command :写数据(1)/命令选择(0);
*返回值:无
*备 注: 
**********************************************************
*/
void LCD_WriteByte(unsigned char dat, unsigned char command)
{
  unsigned char i;
  digitalWrite (LCD_CE, LOW) ;
  if (command == 0)				//写命令
digitalWrite (LCD_DC, LOW) ;			  
  else
digitalWrite (LCD_DC, HIGH) ; //写数据  			   
  for(i=0;i<8;i++)				//传送8bit数据
  { 
  if(dat&0x80)
digitalWrite (LCD_DIN, HIGH) ;
  else
digitalWrite (LCD_DIN, LOW) ;
  digitalWrite (LCD_CLK, LOW) ;
  dat = dat << 1;
  digitalWrite (LCD_CLK, HIGH) ; 
  }
  digitalWrite (LCD_CE, HIGH) ;
}

/*
********************************************************** 
*函数名:LCD_Set_XY
*功能: 设置LCD坐标 
*参数: X:0-83 Y:0-5   
*返回值:无
*备 注: 
**********************************************************
*/
void LCD_Set_XY(unsigned char X, unsigned char Y)
{
  LCD_WriteByte(0x40 | Y, 0);// column  列
  LCD_WriteByte(0x80 | X, 0);// row	   行
} 


/*
********************************************************** 
*函数名:LCD_Clear
*功能: LCD清屏函数 
*参数:无  
*返回值:无
*备 注: 
**********************************************************
*/
void LCD_Clear(void)
{
  unsigned char t;
  unsigned char k;
  LCD_Set_XY(0, 0);//设置RAM起始地址
  for(t=0;t<6;t++)
  { 
for(k=0;k<84;k++)
{ 
  LCD_WriteByte(0x00,1); 
} 
  }
}

/*
********************************************************** 
*函数名:LCD_WriteChar
*功能: LCD写一个6X8的字符 
*参数:c  
*返回值:无
备 注: 
**********************************************************
*/
void LCD_WriteChar(unsigned char x,unsigned char y,unsigned char c)
{
unsigned char i;
c -= 32;   //数组的行号
LCD_Set_XY(x,y);
for(i=0; i<12; i++)
{
   LCD_WriteByte(font6x12[c][i], 1);
   if(i==5)
   {
  y++;
  LCD_Set_XY(x,y);
   }
}

}

/*
********************************************************** 
*函数名:LCD_WriteString
*功能: LCD写6X8的字符串 
*参数:X , Y , S
*返回值:无
备 注: 
**********************************************************
*/
void LCD_WriteString(unsigned char X,unsigned char Y,char *s)
{
  while(*s) 
  {
 LCD_WriteChar(X,Y,*s);
 s++;
 X += 6;
  }
}

/*
***************************************************************
*函数名:LCD_WriteNum(unsigned int num)
*功能:写入数字
*参数:num  
*返回值:无
****************************************************************
*/
void LCD_WriteNum(unsigned char X,unsigned char Y,unsigned int num)
{
  unsigned char str[8],i=0,len=0;
  unsigned int temp;
  temp = num;
  while(temp)
  {
temp /=10;
len++;
  }
  if(!num)
  {
 len++;
 str[0]=0x30;
  }  
  str[len] = 0;
  while(num)
  {
str[len-i-1] = num%10 + 0x30;
num /=10;
i++;
  }
  LCD_WriteString(X,Y,(char *)str);
}

/*
********************************************************** 
*函数名:LCD_Write_16X16Font
*功能: 写一个16X16的汉字 
*参数:x , y , c[2]  x:0-83 y:0-5  
*返回值:无
*备 注: 
**********************************************************
*/
void LCD_Write_12X16Font(unsigned char x,unsigned char y,unsigned char c[2])
{
unsigned char i,k;
LCD_Set_XY(x,y);
for(k=0; k<25; k++)//K的值表示汉字库最多存放的字的数量(可改大)
{
  if((font12x16[k].Index[0]==c[0])&&(font12x16[k].Index[1]==c[1]))
  {
  for(i=0; i<24; i++)
  {
 LCD_WriteByte(font12x16[k].Msk[i], 1);
 if(i==11)
 {
y++;
LCD_Set_XY(x,y);
 }
  }
  }
}
}
/*
********************************************************** 
*函数名:LCD_DrawPicture
*功能: 绘图 
*参数:	  X、Y:位图绘制的起始X、Y坐标; 

  *map:位图点阵数据; 

  Pix_x   :位图像素(长) <=84

  Pix_y   :位图像素(宽) <=48  
*返回值:无
*备 注: 
**********************************************************
*/
void LCD_DrawPicture(unsigned char X,unsigned char Y,unsigned char const *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;  //如果为位图所占行数不是整数 

	

	LCD_Set_XY(X,Y); 

	for (n=0;n<row;n++)  //换行 

	{  

		for(i=0;i<Pix_x;i++) 

		{  

			LCD_Set_XY(X+i,Y+n); 

			LCD_WriteByte(map[i+n*Pix_x], 1); 

		}  

	} 
}

/*
********************************************************** 

				-------main函数--------

*函数名:主函数
*备 注: 
**********************************************************
*/
void main()
{
  printf ("Raspberry Pi 5110 test\n") ;

  wiringPiSetup () ;
  pinMode (LCD_CLK, OUTPUT) ;
  pinMode (LCD_DIN, OUTPUT) ;
  pinMode (LCD_DC, OUTPUT) ;
  pinMode (LCD_CE, OUTPUT) ;
  pinMode (LCD_RST, OUTPUT) ;

  LCD_Init(); 
	while(1)
	{
							  
	LCD_WriteString(0,0,"Temp:");//写6X8的字符串
  LCD_WriteNum(40,0,123); // 写入数字 int型的 		  
	}
}
  1. make一下
  2. ./5110 运行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山猫Show

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值