Easy2812开发板SPI接口的液晶控制(ST7920,128*64)例子:
void InitLcd(void);
void DSP28x_usDelay(unsigned long t);
void LcdSendCommand(unsigned char cCommand);
void LcdSendData(unsigned char cData);
void SecondPage(void);
void DisplayCgrom(unsigned char *hz);
void main(void)
{
/*初始化系统*/
InitSysCtrl();
/* 关中断 */
DINT;
IER = 0x0000;
IFR = 0x0000;
InitSpi();
InitGpio();
InitLcd();
/* 初始化PIE控制寄存器 */
InitPieCtrl();
/* 初始化PIE参数表 */
InitPieVectTable();
/* 初始化外设寄存器 */
InitPeripherals();
/*设置CPU*/
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
SecondPage();
for(;;)
{
}
}
//液晶显示屏初始化
void InitLcd(void)
{
DSP28x_usDelay(1000);
LcdSendCommand(0x20);
LcdSendCommand(0x02);
LcdSendCommand(0x0c);
LcdSendCommand(0x04);
LcdSendCommand(0x01);
LcdSendCommand(0x80);
DSP28x_usDelay(1000);
}
//延时
void DSP28x_usDelay(unsigned long t)
{
while(t>0)
t--;
}
//写命令
void LcdSendCommand(unsigned char cCommand)
{
GpioDataRegs.GPFSET.bit.GPIOF3 = 1;
DSP28x_usDelay(300);
SpiaRegs.SPIDAT = (0x00F8) << 8;
DSP28x_usDelay(300);
SpiaRegs.SPIDAT = (0x00F0&cCommand) << 8;
DSP28x_usDelay(300);
SpiaRegs.SPIDAT = (cCommand) << 12;
if (cCommand == 0x01) {DSP28x_usDelay(100000);}
DSP28x_usDelay(50000);
GpioDataRegs.GPFCLEAR.bit.GPIOF3 = 1;
DSP28x_usDelay(300);
}
//写数据
void LcdSendData(unsigned char cData)
{
GpioDataRegs.GPFSET.bit.GPIOF3 = 1;
DSP28x_usDelay(300);
SpiaRegs.SPIDAT = (0x00Fa) << 8;
DSP28x_usDelay(300);
SpiaRegs.SPIDAT = (0x00F0&cData) << 8;
DSP28x_usDelay(300);
SpiaRegs.SPIDAT = (cData) << 12;
DSP28x_usDelay(300);
GpioDataRegs.GPFCLEAR.bit.GPIOF3 = 1;
DSP28x_usDelay(300);
}
//显示一页
void SecondPage(void)
{
LcdSendCommand(0x01);
LcdSendCommand(0x80);
DSP28x_usDelay(1000);
DisplayCgrom("TMS320F2812 SPI ");
LcdSendCommand(0x90);
DSP28x_usDelay(1000);
DisplayCgrom("接口的液晶控制!");
LcdSendCommand(0x88);
DSP28x_usDelay(1000);
DisplayCgrom("(ST7920,128*64)");
LcdSendCommand(0x98);
DSP28x_usDelay(1000);
LcdSendData(0XB0);
LcdSendData(0XB0);
LcdSendData(0XB0);
LcdSendData(0XB1);
LcdSendData(0XB0);
LcdSendData(0XB2);
}
//显示一串汉字跟字符
void DisplayCgrom(unsigned char *hz)
{
while(*hz != '\0')
{
LcdSendData (*hz);
hz++;
}
} |
|