微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > PIC16F917 NOKIA5110液晶测试程序

PIC16F917 NOKIA5110液晶测试程序

时间:11-18 来源:互联网 点击:

/*************PIC16F917单片机程序******************************/
/*****File Function : LCD NOKIA5110测试程序*****/
/*****Program Author : ZhengWen(ClimberWin) *****/
/*****MCU : PIC16F917 内部晶振 *****/
/*****Compile Date : 2010/08/18 *****/
/*****Edition Info : V1.0 *****/
/*****************************************************************/
//
//引脚定义:PORTD=8LED,KEY=RB0(INT) RA5(AN4)作为AD输入
/*修改日期: */

/************************************/
#include
#include "english_6x8_pixel.h"
#define uchar unsigned char
#define uint unsigned int
void Init(void); //初始化子程序
void LCD_init(void); //LCD初始化程序
void LCD_clear(void);
void LCD_write_english_string(unsigned char X,unsigned char Y,const char *s);
void LCD_write_byte(unsigned char data, unsigned char command);
void delayms(unsigned int count);

#define KEY RB0
#define SPI_CLK RD0
#define SPI_MOSI RD1
#define LCD_DC RD2
#define LCD_CE RD3
#define LCD_RST RD4
/***********************************************/

const unsigned char mask_table[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};

/*********************************************/
void delayms(unsigned int count)
{
uint i,j;
for(i=0;ifor(j=0;j<120;j++);
}
/*********************************************/
void Init(void)
{
PORTA = 0B00000000;
PORTB = 0B00000000;
PORTD = 0B00000000;

TRISA = 0B00100010;//设置RA5(AN4) RA1作为输入
TRISB = 0B00100001;//设置RB0为输入,作为按键口
TRISD = 0B00000000;//设置PORTD口为输出,作为LCD/LED显示口
RD5=1;//关闭LED
RD6=1;
RD7=1;
LCD_init(); //初始化液晶

}

void LCD_init(void)
{
LCD_RST=0; //LCD复位
NOP();
LCD_RST=1;

LCD_CE=0 ;// 关闭LCD
NOP();
LCD_CE=1;// 使能LCD
NOP();

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清屏程序/////////////
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(0x00, 1);//清零
}

///////////设置LCD坐标///////////////////
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0);
LCD_write_byte(0x80 | X, 0);
}

////////////////字符显示程序/////////////////////
void LCD_write_char(unsigned char c)
{
uint line;
c=c-32;
for (line=0; line<6; line++)
LCD_write_byte( FONT6x8[c][line], 1);
}

/////////////////打印字符串/////////////////////////
void LCD_write_english_string(unsigned char X,unsigned char Y, const unsigned char *s)
{
uchar i = 0;
LCD_set_XY(X,Y);
while(*s) {LCD_write_char(*s++);}
}

////////////写数据到LCD//////////////////////
void LCD_write_byte(unsigned char data, unsigned char command)
{
uchar i;
LCD_CE=0 ; // 使能LCD

if (command == 0)
{LCD_DC=0 ;} // 传送命令
else
{LCD_DC=1 ;} // 传送数据

for(i=0;i<8;i++)
{
if(data&mask_table[i])
{SPI_MOSI=1;}
else
{SPI_MOSI=0;}
SPI_CLK=0;
NOP();
SPI_CLK=1;
}

LCD_CE=1 ;// 关闭LCD
}

////////////主程序/////////////////////////
void main (void)
{
Init();//初始化程序
LCD_clear(); //LCD清屏
delayms(1000);
LCD_write_english_string(0,0,"Nokia5110 LCD" );
LCD_write_english_string(0,1,"MCU:PIC16F917" );
LCD_write_english_string(0,2,"Version: V1.0" );
LCD_write_english_string(0,3,"Test OK! " );
LCD_write_english_string(0,4,"By ClimberWin" );
LCD_write_english_string(0,5,"2010.08.18 " );

while(1);

}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top