1. 程式人生 > >CCS5.4+Proteus8的F28027實踐課四、並行驅動LCD12864

CCS5.4+Proteus8的F28027實踐課四、並行驅動LCD12864

趁著時間早,晚上九點四十,我們整理下12864的驅動程式,爭取也弄成一個跟TI提供的類似原始檔,然後共享給大家。
既然是12864,那最重要的肯定是12864時序的解讀,在大學時期,12864還玩的真的很多,有並行驅動和序列驅動兩種方式,今晚主要講的是並行驅動,如果整理完了,時間還充足,我們也順便一起把序列也整理了,畢竟F28027總共才22個GPIO埠,能省則省。
來,那我們再來囉嗦一把,一起看下12864相關資料。
首先看下它的管腳圖:
12864
12864
很容易看懂管腳作用吧,我們就不廢話了,直接看時序圖了。
先看寫操作時序:
寫時序
看完了寫時序,我們應該順便把寫LCD資料和指令的子函式寫出來

//---------------------------------------------------------------------------
// WRITEDATA_LCD12864:
//---------------------------------------------------------------------------
// This function writes data to LCD12864
void WRITEDATA_LCD12864(unsigned char data)
{
    GpioDataRegs.GPADAT.bit.GPIO16=1;
    GpioDataRegs.GPADAT
.bit.GPIO17=1; GpioDataRegs.GPADAT.bit.GPIO18=0; DELAY_US(100); GpioDataRegs.GPADAT.bit.GPIO17=0; GpioDataRegs.GPADAT.bit.GPIO18=1; DELAY_US(1); GpioDataRegs.GPADAT.all=GpioDataRegs.GPADAT.all&0xffffff00; GpioDataRegs.GPADAT.all=GpioDataRegs.GPADAT.all|data; DELAY_US(1);
GpioDataRegs.GPADAT.bit.GPIO17=1; GpioDataRegs.GPADAT.bit.GPIO18=0; DELAY_US(1000); } //--------------------------------------------------------------------------- // WRITECMD_LCD12864: //--------------------------------------------------------------------------- // This function writes cmd to LCD12864 void WRITECMD_LCD12864(unsigned char cmd) { GpioDataRegs.GPADAT.bit.GPIO16=0; GpioDataRegs.GPADAT.bit.GPIO17=1; GpioDataRegs.GPADAT.bit.GPIO18=0; DELAY_US(100); GpioDataRegs.GPADAT.bit.GPIO17=0; GpioDataRegs.GPADAT.bit.GPIO18=1; DELAY_US(1); GpioDataRegs.GPADAT.all=GpioDataRegs.GPADAT.all&0xffffff00; GpioDataRegs.GPADAT.all=GpioDataRegs.GPADAT.all|cmd; DELAY_US(1); GpioDataRegs.GPADAT.bit.GPIO17=1; GpioDataRegs.GPADAT.bit.GPIO18=0; DELAY_US(1000); }

再看讀時序:
讀時序
好,看完了時序圖,我們緊接著就去看它的基本操作指令集:
CLEAR
HOME
SET
SET
STATUS
DSIPLAY
FUNCTION
CGRAM
DDRAM
BUSY
WTRAM
RFRAM
基本操作指令集就到這了,我們現在來了解下如何寫12864驅動程式。
首先是LCD的初始化
INIT
根據上面的寫函式,LCD的初始化就比較簡單了

//---------------------------------------------------------------------------
// InitLCD12864:
//---------------------------------------------------------------------------
// This function initializes the LCD12864 to a known (default) state.
// such as FUNCTION SET,DSIPLAY SET,CLEAR SCREEN

void InitLCD12864(void)
{
    DELAY_US(10000);
    WRITECMD_LCD12864(0x30);
    DELAY_US(1000);
    WRITECMD_LCD12864(0x30);
    DELAY_US(100);
    WRITECMD_LCD12864(0x0c);
    DELAY_US(1000);
    WRITECMD_LCD12864(0x01);
    DELAY_US(10000);
    WRITECMD_LCD12864(0x06);
    DELAY_US(10000);
}

12864相關程式寫完了,就可以直接去寫主函數了,我這裡比較簡單,只讓它顯示一個字元而已

void main(void)
{

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2802x_SysCtrl.c file.
   InitSysCtrl();

// Step 2. Initalize GPIO:
// This example function is found in the DSP2802x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
   InitGpio();

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
   DINT;

// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2802x_PieCtrl.c file.
   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP2802x_DefaultIsr.c.
// This function is found in DSP2802x_PieVect.c.
   InitPieVectTable();


// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2802x_InitPeripherals.c
// InitPeripherals(); // Not required for this example

// Step 5. User specific code:

   InitLCD12864();

   WRITECMD_LCD12864(0x80);
   WRITEDATA_LCD12864('a');

   while(1)
   {
//     GpioDataRegs.GPATOGGLE.all=0x000000ff;
//       DELAY_US(1000);
   }
}

到這裡,相關的程式已經全部寫完了,但是由於proteus沒有我們常用12864的模擬庫,所以打算明天直接用萬用板搭一個測試平臺出來,順便把我們之前那幾個實踐課程的程式都驗證下,期待我們明晚驗證除錯結果,除錯完沒問題後,就上傳原始碼,現在該洗洗睡了。
菜鳥交流qq群107691092