好久也没冒个泡,出差近两月,唉!没办法。今天泡一下!!!
LM3S811这个片子特点是便宜啊!我从淘宝查了好似10元左右吧!
外设极端丰富,用它开开发产品,错错有余。
我手头有智林的5110屏,考虑到LM3S811是3.3地所以用它,但智林的接口是小十针地,好在智林留出了引脚,我就
直接焊上引线。
刚开始发黑我调了下对比度,就是那个电压参数好了,由于像机没在家。还急于发贴只好用手机(奔迈600)
效果那叫一个差!
费话太多,上程序哈:
我显示的内容如下:
NOKIA 5110 LCD
Designed by :
DDLLXXRR
Very Good!
还有两个H文件打包下载
#include <LM3Sxxx.H>
#include "english_6x8_pixel.h"
#include "DriverLCD_Nokia5110.h"
#include "gpio.h"
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define true 1
#define flase 0
/*-----------------------------------------------------------------------
LCD_init : 3310LCD初始化
编写日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
#define LCD_DC GPIO_PIN_0 // PA
#define LCD_RST GPIO_PIN_7
#define LCD_SCLK GPIO_PIN_1 //PA时钟信号
#define LCD_SDIN GPIO_PIN_6 //数据输入
#define LCD_CE GPIO_PIN_5 //
#define c_Lcd_Max_x 84
#define c_Lcd_Max_y 6 //以字节为单位
#define c_LCD_Max_Dot_X 84
#define c_LCD_Max_Dot_Y 48
#define COM 0 //指令
#define DAT 1 //数据
//-------------------
#define STR 1 //字符
#define HAN 2 //汉字
//--------------------------LPH7366指令集---------------------------
#define Nokia5110_basic_fun_set 0x20 //基本功能设置
#define Nokia5110_expand_fun_set 0x21 //扩展功能设置
// D7 D6 D5 D4 D3 D2 D1 D0
// 0 0 1 0 0 PD V H
// | | |_______1->扩展指令集 0->基本指令集
// | |___________1->垂直寻址 0->水平寻址
// |_______________1->低功耗模式 0->正常模式
//-------------------------------------------------------------------
//基本指令集
#define Nokia5110_dis_set 0x0c//显示模式设置
#define Nokia5110_DispMode_AllLightOff 0x08
#define Nokia5110_DispMode_AllLightOn 0x09
#define Nokia5110_DispMode_Reverse 0x0d
// D7 D6 D5 D4 D3 D2 D1 D0
// 0 0 0 0 1 D 0 E
// | |_______0 0 1 1
// |_______________0 1 0 1
// 白屏 正常显示 全显 反转
//-------------------------------------------------------------------
#define Nokia5110_add_Yset 0x40 //设置Y地址
// D7 D6 D5 D4 D3 D2 D1 D0
// 0 1 0 0 0 Y1 Y2 Y3
//-------------------------------------------------------------------
#define Nokia5110_add_Xset 0x80 //设置X地址
// D7 D6 D5 D4 D3 D2 D1 D0
// 0 1 X6 X5 X4 X3 X2 X1
//-------------------------------------------------------------------
//扩展指令集
#define Nokia5110_tem_set 0x06 //温度系数设置
// D7 D6 D5 D4 D3 D2 D1 D0
// 0 0 0 0 0 1 TC1 TC0
//-------------------------------------------------------------------
#define Nokia5110_vot_set 0xBF //电压系数设置 0xD7
// D7 D6 D5 D4 D3 D2 D1 D0
// 1 vo6 vo5 vo4 vo3 vo2 vo1 vo0
//-------------------------------------------------------------------
//void Delay_1uS(void);
void delay_1us(void) //1us延时函数
{
unsigned int i;
for(i=0;i<1;i++);
}
//1ms Delayfunction
void Delay(uint uiDelayCount)
{
uint uiTempCount;
uchar uci;
for(uiTempCount=0; uiTempCount<uiDelayCount; uiTempCount++)
{
uci = 1000;
while(uci--)
{
delay_1us();
}
}
}
/*-----------------------------------------------------------------------
LCD_write_byte : 使用SPI接口写数据到LCD
输入参数:data :写入的数据;
command :写数据/命令选择;
编写日期 :2004-8-10
最后修改日期 :2004-8-13
-----------------------------------------------------------------------*/
void LCD_write_CMD(unsigned char ucWriteData)
{
unsigned char uci;
GPIOPinWrite(GPIO_PORTC_BASE, LCD_CE,~LCD_CE);
GPIOPinWrite(GPIO_PORTA_BASE, LCD_DC,~LCD_DC);
for(uci=0;uci<8;uci++)
{
if(ucWriteData & 0x80)
{
GPIOPinWrite(GPIO_PORTC_BASE, LCD_SDIN,LCD_SDIN);
}
else
{
GPIOPinWrite(GPIO_PORTC_BASE, LCD_SDIN,~LCD_SDIN);
}
GPIOPinWrite(GPIO_PORTA_BASE, LCD_SCLK,~LCD_SCLK);
ucWriteData = ucWriteData << 1;
GPIOPinWrite(GPIO_PORTA_BASE, LCD_SCLK,LCD_SCLK);
}
//LCD_CE = 1;
GPIOPinWrite(GPIO_PORTC_BASE, LCD_CE,LCD_CE);
}
/*-----------------------------------------------------------------------
LCD_write_byte : 使用SPI接口写数据到LCD
输入参数:data :写入的数据;
command :写数据/命令选择;
编写日期 :2004-8-10
最后修改日期 :2004-8-13
-----------------------------------------------------------------------*/
void LCD_write_Data(unsigned char ucWriteData)
{
unsigned char uci;
GPIOPinWrite(GPIO_PORTC_BASE, LCD_CE,~LCD_CE);
GPIOPinWrite(GPIO_PORTA_BASE, LCD_DC,LCD_DC);
for(uci=0;uci<8;uci++)
{
if(ucWriteData & 0x80)
{
GPIOPinWrite(GPIO_PORTC_BASE, LCD_SDIN,LCD_SDIN);
}
else
{
GPIOPinWrite(GPIO_PORTC_BASE, LCD_SDIN,~LCD_SDIN);
}
GPIOPinWrite(GPIO_PORTA_BASE, LCD_SCLK,~LCD_SCLK);
ucWriteData = ucWriteData << 1;
GPIOPinWrite(GPIO_PORTA_BASE, LCD_SCLK,LCD_SCLK);
}
GPIOPinWrite(GPIO_PORTC_BASE, LCD_CE,LCD_CE);
}
/*-----------------------------------------------------------------------
LCD_set_XY : 设置LCD坐标函数
输入参数:X -83
Y :0-5
编写日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_CMD(0x40 | (Y & 0X07)); // column
LCD_write_CMD(0x80 | (X & 0X7F)); // row
}
/*-----------------------------------------------------------------------
LCD_clear : LCD清屏函数
-----------------------------------------------------------------------*/
void LCD_Clear(void)
{
uint uii;
LCD_set_XY(0,0);
for(uii=0; uii<c_Lcd_Max_x * c_Lcd_Max_y; uii++)
{
LCD_write_Data(0x00);
}
}
void LCD_Init(void)
{
GPIOPinWrite(GPIO_PORTC_BASE, LCD_CE,~LCD_CE);
GPIOPinWrite(GPIO_PORTC_BASE, LCD_RST,~LCD_RST);
delay_1us();
GPIOPinWrite(GPIO_PORTC_BASE, LCD_RST,LCD_RST);
delay_1us();
delay_1us();
LCD_write_CMD(0x21); // 使用扩展命令设置LCD模式
LCD_write_CMD(Nokia5110_vot_set);
LCD_write_CMD(0x06); // 温度校正
LCD_write_CMD(0x13); // 1:48
LCD_write_CMD(0x20); // 使用基本命令
LCD_Clear(); // 清屏
LCD_write_CMD(0x0c); // 设定显示模式,正常显示
GPIOPinWrite(GPIO_PORTC_BASE, LCD_CE,LCD_CE);
}
/*-----------------------------------------------------------------------
LCD_write_char : 显示英文字符
输入参数:c :显示的字符;
编写日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_write_char(unsigned char c)
{
unsigned char line;
c -= 32;
for (line=0; line<6; line++)
{
LCD_write_Data(font6x8[c][line]);
}
}
/*-----------------------------------------------------------------------
LCD_write_english_String : 英文字符串显示函数
输入参数:*s :英文字符串指针;
X、Y : 显示字符串的位置,x 0-83 ,y 0-5
编写日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
{
LCD_set_XY(X,Y);
while (*s)
{
LCD_write_char(*s);
s++;
}
}
void TestLCD_Nokia5110(void)
{
LCD_Init(); //初始化液晶
LCD_Clear();
while(1)
{
LCD_write_english_string(0,0,"NOKIA 5110 LCD");
Delay(100);
LCD_write_english_string(0,2,"Designed by :");
Delay(100);
LCD_write_english_string(0,3," DDLLXXRR ");
Delay(100);
LCD_write_english_string(0,5," Very Good!");
Delay(1000);
LCD_Clear();
Delay(100);
}
}
void init(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_6MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 );
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
}
// 防止JTAG失效
void jtagWait(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); // 使能KEY所在的GPIO端口
GPIOPinTypeGPIOInput(GPIO_PORTC_BASE,GPIO_PIN_4); // 设置KEY所在管脚为输入
if (GPIOPinRead(GPIO_PORTC_BASE,GPIO_PIN_4) == 0x00) // 若复位时按下KEY,则进入
{
while(1); // 死循环,以等待JTAG连接
}
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOC); // 禁止KEY所在的GPIO端口
}
int main(void)
{
jtagWait();
init();
TestLCD_Nokia5110();
}
含H文件的程序包:
1602.zip
(2.16 KB, 下载次数: 54)