新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > XS128單片機(jī)實(shí)驗(yàn):諾基亞5110液晶顯示

XS128單片機(jī)實(shí)驗(yàn):諾基亞5110液晶顯示

作者: 時(shí)間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
/*********包含的頭文件*****************************/
#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 LCD_DC PTM_PTM5
#define LCD_CE PTM_PTM2
#define LCD_RES PTM_PTM1
#define LED PTM_PTM0
/****************函數(shù)申明***************************/
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接口寫數(shù)據(jù)到LCD
// 輸入?yún)?shù):dt 寫入的數(shù)據(jù)
// 使用I/o口模擬SPI總線通訊發(fā)送一個(gè)字節(jié)數(shù)據(jù)到LCD顯示
// Command : 寫數(shù)據(jù)/命令選擇
// Data : 2013、4、26
/***************************************************/
void LCD_write_byte(uchar dt,uchar command) {
uchar i;
LCD_CE=0; //使能LCD
delay_us(40); //延時(shí)30us;
if(command==0) //判斷發(fā)送數(shù)據(jù)還是發(fā)送命令
LCD_DC=0;
else
LCD_DC=1;
delay_us(40); //延時(shí)30us;


for(i=0;i<8;i++){
if(dt&0x80)
SDIN=1; // 發(fā)送高位
else
SDIN=0;
delay_us(40); //延時(shí)30us;
SCLK=0;
dt=dt<<1;
SCLK=1;
}
LCD_CE=1; //關(guān)閉LCD
}
/*2.*************************************************/
// 函 數(shù) :LCD_set_xy
// 功 能 :設(shè)置LCD坐標(biāo)函數(shù)
// 說 明 :x:橫坐標(biāo) Y縱坐標(biāo)
// Date: 2013/4/26
/*************************************************/
void LCD_set_XY(uchar x,uchar y){
LCD_write_byte(0x40|y,0); //列 按位或設(shè)置y坐標(biāo)
LCD_write_byte(0x80|x,0); //行 按位或 設(shè)置x坐標(biāo)
}
/*3.********************************************/
// LCD_write_char() ;顯示英文字符
// 輸入?yún)?shù):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.*********************************************/
//函數(shù):LCD_clear
// 功能:清屏
// 參數(shù):無
// 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初始化
// 輸入?yún)?shù)無
// Date :2013、4、26
/************************************************/
void LCD_int(void) {
LCD_RES=0;
delay_ms(2);
LCD_RES=1;
LCD_write_byte(0x21,0);//初始化LCD,功能設(shè)定使用擴(kuò)充指令
LCD_write_byte(0xd0,0);//設(shè)定液晶偏置電壓;
LCD_write_byte(0x20,0);//使用基本指令
LCD_write_byte(0x0c,0);//設(shè)定顯示模式,正常顯示
}

/****************************************************/
// 主函數(shù):void mian
// 功 能:在諾基亞5110液晶屏上顯示字符
// 作 者:wangqi
// 時(shí) 間;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};
DDRM = 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);
}
}


評論


技術(shù)專區(qū)

關(guān)閉