锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

XS128单片机实验:诺基亚5110液晶显示

时间:2024-05-13 22:07:11

/*********包含的头文件*****************************/
#include /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "WQ.h"
#include "Font6_8.h"
#include "Bitmap.h"
#include "Font16_16.h"
#include "Font8_16.h"
/****************宏定义*****************************/
#define SCLK PTM_PTM4
#define SDIN PTM_PTM3
#define _ PTM_PTM5
#define LCD_CE PTM_PTM2
#define LCD_RES PTM_PTM1
#define LED PTM_PTM0
/****************函数申明***************************/
void LCD_int(void);
void LCD_write_byte(uchar dt,uchar command);
void LCD_write_char(uchar *font);
void LCD_set_XY(uchar x,uchar y);
void LCD_clear(void);
/*1.**************************************************/
// LCD_write_byte: 使用spi写数据到LCD
// 输入参数:dt 写入的数据
// 使用I/o口模拟I总线通讯发送一个字节数据到LCD显示
// Command : 写数据/命令选择
// Data : 2013、4、26
/***************************************************/
void LCD_write_byte(uchar dt,uchar command) {
uchar i;
LCD_CE=0; //使能LCD
delay_us(40); //延时30us;
if(command==0) //判断发送数据还是发送命令
LCD_DC=0;
else
LCD_DC=1;
delay_us(40); //延时30us;


for(i=0;i<8;i++){
if(dt&0x80)
SDIN=1; // 发送高位
else
SDIN=0;
delay_us(40); //延时30us;
SCLK=0;
dt=dt<<1;
SCLK=1;
}
LCD_CE=1; //关闭LCD
}
/*2.*************************************************/
// 函 数 :LCD_set_xy
// 功 能 :设置LCD坐标函数
// 说 明 :x:横坐标 Y纵坐标
// Date: 2013/4/26
/*************************************************/
void LCD_set_XY(uchar x,uchar y){
LCD_write_byte(0x40|y,0); //列 按位或设置y坐标
LCD_write_byte(0x80|x,0); //行 按位或 设置x坐标
}
/*3.********************************************/
// LCD_write_char() ;显示英文字符
// 输入参数:C :显示的字符
// Date: 2013/4/26
/********************************************/
void LCD_write_char (uchar *font) {
uint i;
for(i=0;i<6;i++)
LCD_write_byte(font[i],1);

}
/*4.*********************************************/
// 函数:LCD_clear
// 功能:清屏
// 参数:无
// Date:2013/4/26
/************************************************/
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_init: LCD初始化
// 输入参数无
// Date :2013、4、26
/************************************************/
void LCD_int(void) {
LCD_RES=0;
delay_ms(2);
LCD_RES=1;
LCD_write_byte(0x21,0);//初始化LCD,功能设定使用扩充指令
LCD_write_byte(0xd0,0);//设定液晶偏置电压;
LCD_write_byte(0x20,0);//使用基本指令
LCD_write_byte(0x0c,0);//设定显示模式,正常显示
}

/****************************************************/
// 主函数:void mian
// 功 能:在诺基亚5110液晶屏上显示字符
// 作 者:wangqi
// 时 间;2013、4、26
/****************************************************/
void main(){
unsigned char A[6]={0x00,0x7c,0x12,0x11,0x12,0x7c};
unsigned char B[6]={0x00,0x7f,0x49,0x49,0x49,0x36};
M = 0xFF;
LCD_int();
LCD_clear();
LED=1;
delay_s(5);
LED=0;
while(1){

LCD_set_XY(0,1);
LCD_write_char(A);
delay_ms(100);
LCD_set_XY(10,1);
LCD_write_char(A);
delay_ms(100);
LCD_set_XY(0,3);
LCD_write_char(B);
delay_ms(100);
LCD_set_XY(10,4) ;
LCD_write_char(B);
}
}


-电子元器件采购网(www.ruidan.com)是本土元器件目录分销商,采用“小批量、现货、样品”销售模式,致力于满足客户多型号、高质量、快速交付的采购需求。 自建高效智能仓储,拥有自营库存超过50,000种,提供一站式正品现货采购、个性化解决方案、选型替代等多元化服务。
锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章