#include "common.h"
void LcdInit(void);
void SPIInit(void);
void WriteCommandLCM(int WCLCM);
void WriteDataLCM(int WDLCM);
void display_x(int row ,char* dispx);
void spiTX(SPI_MemMapPtr SPI,unsigned char ucData);
void Send_byte(unsigned char Byte) ;
void delay(unsigned long counnt);
unsigned char szTemp[16] = "";
char dispx[]={" ´ºÃß²»¾õÏþ, "} ;
char dispy[]={" ´¦´¦ÎÅÌäÄñ¡£ "} ;
char dispz[]={" Ò¹À´·çÓêÉù£¬ "} ;
char dispw[]={" »¨ÂäÖª¶àÉÙ¡£ "} ;
/********************************************************************/
int main (void)
{
SystemCoreClockUpdate ();
SPIInit();
LcdInit();
display_x(0x80,dispx);
display_x(0x88,dispy);
display_x(0x90,dispz);
display_x(0x98,dispw);
while(1)
{
}
}
/********************************************************************/
void LcdInit(void)
{
WriteCommandLCM(0x30);
WriteCommandLCM(0x02);
WriteCommandLCM(0x06);
WriteCommandLCM(0x0c);
WriteCommandLCM(0x01);
WriteCommandLCM(0x80);
}
void SPIInit(void)
{
SIM->SCGC5 |=3U<<10; //使能端口B、C</FONT></P>
<P><FONT size=3 face=宋体>SIM->SCGC4 |=1U<<22; //使能SPI0
/* 初始化SPI管脚*/
PORTC_PCR5 |= PORT_PCR_MUX(2); /* 开启PTC5复用功能2 SPI0 SCK */
PORTC_PCR6 |= PORT_PCR_MUX(2); /* 开启PTC6复用功能2 SPI0 MOSI*/
SPI0->C1|=0x58; //使能主SPI CPOL=1 CPHA=1
SPI0->C2|=0x00; // 8bit 禁止中断,采用查询方式
SPI0->BR|=0x40; //波特率500K
}
void spiTX(SPI_MemMapPtr SPI,unsigned char ucData)
{
while((SPI->S & SPI_S_SPTEF_MASK) != SPI_S_SPTEF_MASK); /* 发送前查询发送空标志是否置位 */
SPI->DL = ucData;
}
void WriteCommandLCM(int WCLCM)
{
unsigned char Hdata,Ldata;
Hdata = WCLCM&0xf0; // È¡¸ß4λ
Ldata = ( WCLCM << 4) & 0xf0; // È¡µÍ4λ
Send_byte(0xF8); // ´ÓMCUµ½LCDдָÁî
Send_byte(Hdata); // ·¢Ë͸ß4λ
Send_byte(Ldata); // ·¢Ë͵Í4λ
}
void WriteDataLCM(int WDLCM)
{
unsigned char Hdata,Ldata;
Hdata = WDLCM & 0xf0; // È¡¸ß4λ
Ldata = ( WDLCM << 4) & 0xf0; // È¡µÍ4λ
Send_byte(0xFa); //´ÓMCUµ½LCDдÊý¾Ý
Send_byte(Hdata); // ·¢ËÍ
Send_byte(Ldata);
}
void display_x(int row ,char* dispx)
{
unsigned char a;
WriteCommandLCM(row);
for(a=0;a<16;a++)
{
WriteDataLCM(*dispx++);
}
}
void Send_byte(unsigned char Byte)
{
// while((SPI0_S & SPI_S_SPTEF_MASK) != SPI_S_SPTEF_MASK);
spiTX( SPI0_BASE_PTR,Byte);
delay(10000);
}
void delay(unsigned long counnt){
volatile int i;
for(i=0; i < counnt; i++){
}
} |