專注電子技術(shù)學習與研究
當前位置:單片機教程網(wǎng) >> MCU設(shè)計實例 >> 瀏覽文章

XS128單片機實驗:諾基亞5110液晶顯示

作者:韓冰   來源:本站原創(chuàng)   點擊數(shù):  更新時間:2013年11月29日   【字體:

 /*********包含的頭文件*****************************/
  #include <hidef.h>           /* 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ā)送一個字節(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);         //延時30us;
    if(command==0)        //判斷發(fā)送數(shù)據(jù)還是發(fā)送命令
         LCD_DC=0;
    else
         LCD_DC=1;
    delay_us(40);          //延時30us;
  
 
    for(i=0;i<8;i++){
      if(dt&0x80)
          SDIN=1;          // 發(fā)送高位
      else
          SDIN=0;
      delay_us(40);        //延時30us;
      SCLK=0;
      dt=dt<<1;
      SCLK=1;
    }   
     LCD_CE=1;             //關(guān)閉LCD
    }
/*2.*************************************************/
// 函  數(shù) :LCD_set_xy
// 功  能 :設(shè)置LCD坐標函數(shù)
// 說  明 :x:橫坐標 Y縱坐標
// Date:   2013/4/26
/*************************************************/
void LCD_set_XY(uchar x,uchar y){
LCD_write_byte(0x40|y,0);   //列  按位或設(shè)置y坐標
LCD_write_byte(0x80|x,0);   //行 按位或 設(shè)置x坐標
}
/*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è)定使用擴充指令
    LCD_write_byte(0xd0,0);//設(shè)定液晶偏置電壓;
    LCD_write_byte(0x20,0);//使用基本指令
    LCD_write_byte(0x0c,0);//設(shè)定顯示模式,正常顯示
    }
 
/****************************************************/
// 主函數(shù):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};
      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);
      }
}
 

關(guān)閉窗口

相關(guān)文章