// auther: wangdingfa// Checkin $Date: July 31, 2016 22:45:31 $//###########################################################################//// FILE: F2802x_LCD12864.h//// TITLE: LCD12864 Initialization & Support Functions.//#ifndef F2802x_LCD12864_H#define F2802x_LCD12864_H#define CS GpioDataRegs.GPADAT.bit.GPIO16#define SID GpioDataRegs.GPADAT.bit.GPIO17#define SCLK GpioDataRegs.GPADAT.bit.GPIO18void SendByte_LCD12864(unsigned charbyte);
void WRITEDATA_LCD12864(unsigned char data);
void WRITECMD_LCD12864(unsigned char cmd);
void InitLCD12864(void);
#endif // end of F2802x_LCD12864_H definition//===========================================================================// End of file.//===========================================================================
再写F2802x_LCD12864.c文件
// auther: wangdingfa// Checkin $Date: July 31, 2016 22:45:31 $//###########################################################################//// FILE: F2802x_LCD12864.c//// TITLE: LCD12864 Initialization & Support Functions.//#include "F2802x_Device.h" // Headerfile Include File#include "F2802x_Examples.h" // Examples Include Filevoid SendByte_LCD12864(unsignedchar byte)
{
char i;
CS=1;
for(i = 0;i < 8;i ++)
{
if((byte<<i) & 0x80)
{
SID = 1;
}
else
{
SID = 0;
}
DELAY_US(1);
SCLK = 1;
DELAY_US(1);
SCLK = 0;
DELAY_US(1);
}
DELAY_US(10);
}
//---------------------------------------------------------------------------// WRITEDATA_LCD12864://---------------------------------------------------------------------------// This function writes data to LCD12864void WRITEDATA_LCD12864(unsignedchar data)
{
CS = 1; //打开片选
DELAY_US(10);
SendByte_LCD12864(0xfa);//第一字节
DELAY_US(10);
SendByte_LCD12864(data & 0xf0); //第二字节
DELAY_US(10);
SendByte_LCD12864((data << 4) & 0xf0);//第三字节
DELAY_US(10);
CS = 0;
DELAY_US(100);
}
//---------------------------------------------------------------------------// WRITECMD_LCD12864://---------------------------------------------------------------------------// This function writes cmd to LCD12864void WRITECMD_LCD12864(unsignedchar cmd)
{
CS = 1;//打开片选,高电平有效
DELAY_US(10);
SendByte_LCD12864(0xf8); //第一字节
DELAY_US(10);
SendByte_LCD12864(cmd & 0xf0); //第二字节
DELAY_US(10);
SendByte_LCD12864((cmd << 4) & 0xf0);//第三字节
DELAY_US(10);
CS = 0;
DELAY_US(100);
}
//---------------------------------------------------------------------------// InitLCD12864://---------------------------------------------------------------------------// This function initializes the LCD12864 to a known (default) state.// such as FUNCTION SET,DSIPLAY SET,CLEAR SCREENvoid 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);
}
//===========================================================================// End of file.//===========================================================================
最后还是主函数,这个主函数跟上次并行的一样,都是测试语句而已
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example functionisfoundintheDSP2802x_SysCtrl.cfile.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example functionisfoundintheDSP2802x_Gpio.cfileand
// illustrateshowtosettheGPIOtoit'sdefaultstate.
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 functionisfoundintheDSP2802x_PieCtrl.cfile.
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 fordebug purposes.
// The shell ISR routines are found in DSP2802x_DefaultIsr.c.
// This functionisfoundinDSP2802x_PieVect.c.
InitPieVectTable();
// Step 4. Initialize all the Device Peripherals:
// This functionisfoundinDSP2802x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
// Step 5. User specific code:
InitLCD12864();
WRITECMD_LCD12864(0x80);
WRITEDATA_LCD12864('a');
WRITEDATA_LCD12864('b');
WRITEDATA_LCD12864('c');
WRITECMD_LCD12864(0x90);
WRITEDATA_LCD12864('1');
WRITEDATA_LCD12864('2');
WRITEDATA_LCD12864('3');
WRITECMD_LCD12864(0x88);
WRITEDATA_LCD12864('x');
WRITEDATA_LCD12864('y');
WRITEDATA_LCD12864('z');
WRITECMD_LCD12864(0x98);
WRITEDATA_LCD12864('7');
WRITEDATA_LCD12864('8');
WRITEDATA_LCD12864('9');
while(1)
{
// GpioDataRegs.GPATOGGLE.all=0x000000ff;
// DELAY_US(1000);
}
}