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

📄 can

📁 can通信源码
💻
字号:
/***********************************************************************
程序名称: nokia.c
程序功能: nokia5110驱动程序
程序说明:           
/**********************************************************************/
#include <iom128v.h>
#include <macros.h>
#include <BIT.h>
#include"code_table.c"

#define uchar unsigned char
#define uint unsigned int

//位操作定义
#define SCLK _PA5
#define SDIN _PA4
#define LCD_DC _PA3 
#define LCD_CE _PA2
#define LCD_RST _PA1

//函数声明
void delay_us(uint t);
void delay_ms(uint t);
void LCD_init(void);
void LCD_clear(void);
void LCD_write_english_string(uchar X,uchar Y,char *s); 
void LCD_write_char(uchar c);
void LCD_write_byte(uchar dat, uchar dc);
void LCD_set_XY(uchar X, uchar Y);      

/***********************************************************************
* 函数名称:delay_us()
* 函数功能:16M晶振,延时t微秒
* 入口参数:t    延时t微秒
* 出口参数:无
***********************************************************************/
void delay_us(uint t)
{ 
 	 uint i,j;
	 for(i=t;i>0;i--)	
	     for(j=1;j>0;j--);
} 

/**********************************************************************
* 函数名称:delay_ms()
* 函数功能:16M晶振,延时t毫秒
* 入口参数:t   延时t毫秒
* 出口参数:无
***********************************************************************/
void delay_ms(uint t)
{
 	 uint i,j;
	 for(i=t;i>0;i--)
	 	for(j=2670;j>0;j--);
}

/**********************************************************************
* 函数名称:LCD_init()		
* 函数功能:初始化nokia5110
* 入口参数:无
* 出口参数:无
**********************************************************************/
void LCD_init(void)
  {           
    LCD_RST = 0; // 产生一个让LCD复位的低电平脉冲
    delay_us(1);
    LCD_RST = 1;
    LCD_CE = 0;// 关闭LCD  
    delay_us(1);		
    LCD_CE = 1;// 使能LCD
    delay_us(1);
    LCD_write_byte(0x21, 0);	// 使用扩展命令设置LCD模式
    LCD_write_byte(0xc8, 0);	// 设置偏置电压
    LCD_write_byte(0x06, 0);	// 温度校正
    LCD_write_byte(0x13, 0);	// 1:48
    LCD_write_byte(0x20, 0);	// 使用基本命令
    LCD_clear();	                   // 清屏
    LCD_write_byte(0x0c, 0);	// 设定显示模式,正常显示        
    LCD_CE = 0;                      // 关闭LCD  
  }
  
 /**********************************************************************
* 函数名称:LCD_clear()		
* 函数功能:液晶清屏
* 入口参数:无
* 出口参数:无
**********************************************************************/
void LCD_clear(void)
  {
    uint i;
    LCD_write_byte(0x0c, 0);			
    LCD_write_byte(0x80, 0);	
    for (i=0; i<504; i++)
      LCD_write_byte(0, 1);			
  }

/**********************************************************************
* 函数名称:LCD_set_XY()
* 函数功能:光标定位x行y列
* 入口参数:X,Y   x行y列
* 出口参数:无
**********************************************************************/
void LCD_set_XY(uchar X, uchar Y)
  {
    LCD_write_byte(0x40 | Y, 0);		// column
    LCD_write_byte(0x80 | X, 0);        // row
  }
  
 /***********************************************************************
* 函数名称:LCD_write_char()
* 函数功能:写入1个字符
* 入口参数:c   要写入的数据
* 出口参数:无
**********************************************************************/
void LCD_write_char(uchar c)
  {
    uchar line;
    c -= 32;
    for (line=0; line<6; line++)
      LCD_write_byte(font6x8[c][line], 1);//从ACSII码表中读取字节,然后写入液晶
  }

/***********************************************************************
* 函数名称

⌨️ 快捷键说明

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