|
我现在在做lcd的上电过程,其中板子是pxa270的,我使用23 24 25 26管脚设置spi,来实现lcd的上电过程。其程序如下:(那位大哥能帮我看看错误在那里,谢谢)
const unsigned short LCD_REGS_VAL[19]={
0x409D,0x0204,0x0100,0x3000,0x4003,0x000A,0x0021,0x0C00,
0x0000,/*reg 9 at Instruction Setting not set */
0x0103,0x0301,0x1F0F,0x1F0F,0x0707,0x0307,0x0707,0x0000,0x0004,0x0000
};
//先高位后低位
void LCD_SEL_REG(unsigned char REGX)
{
volatile SSP_REGS *g_pSSPRegs = (volatile SSP_REGS *)SSP1_BASE_U_VIRTUAL;
while(!(g_pSSPRegs->ssr&0x10)); /*wait tx ready*/
g_pSSPRegs->ssdr=0x2e;
while(!(g_pSSPRegs->ssr&0x10));
g_pSSPRegs->ssdr=0x00;
while(!(g_pSSPRegs->ssr&0x10));
g_pSSPRegs->ssdr=REGX;
}
//先高位后低位!!!
LCD_SET_DATA(unsigned short SVAL)
{
volatile SSP_REGS *g_pSSPRegs = (volatile SSP_REGS *)SSP1_BASE_U_VIRTUAL;
while(!(g_pSSPRegs->ssr&0x10)); /*wait tx ready*/
g_pSSPRegs->ssdr=0x6e;
while(!(g_pSSPRegs->ssr&0x10));
g_pSSPRegs->ssdr=(SVAL&0xff00)>>8;
while(!(g_pSSPRegs->ssr&0x10));
g_pSSPRegs->ssdr=SVAL&0x00ff;
}
void SetupSPI(void)
{
volatile XLLP_GPIO_T *g_pGPIORegs = (volatile XLLP_GPIO_T *)GPIO_BASE_U_VIRTUAL;
volatile XLLP_CLKMGR_T *g_pClockRegs =(volatile XLLP_CLKMGR_T*)CLK_BASE_U_VIRTUAL;
volatile SSP_REGS *g_pSSPRegs = (volatile SSP_REGS *)SSP1_BASE_U_VIRTUAL;
while(!g_pGPIORegs)
{
EdbgOutputDebugString("GPIO FAILED\r\n");
}
while(!g_pClockRegs)
{
EdbgOutputDebugString("CLOCK FAILED\r\n");
}
while(!g_pSSPRegs)
{
EdbgOutputDebugString("SSP FAILED\r\n");
}
// disable Unit clock
g_pClockRegs->cken &= ~XLLP_CLKEN_SSP1;
// disable SSP1
g_pSSPRegs->sscr0 &= ~SSE_ENABLE;
// Set up the GPIO24=SFRM = 1 (GPSR0)
//g_pGPIORegs->GPSR0 |= (GPIO_24_SFRM );
// Program direction of the GPIOs (GPDR0)
// (GPIO23/24/25 as outputs)
g_pGPIORegs->GPDR0 |= GPIO_23_SCLK;
g_pGPIORegs->GPDR0 |= GPIO_24_SFRM;
g_pGPIORegs->GPDR0 |= GPIO_25_MOSI;
g_pGPIORegs->GPDR0 &= ~GPIO_26_MISO;
// Program GPIO alternate function register (GAFR0_U)
g_pGPIORegs->GAFR0_U &= 0xFFC03FFF;
g_pGPIORegs->GAFR0_U |= GPIO_23_AF2_SSPSCLK;
// GPIO24 is used here as GPO
//可以设置GPIO24
g_pGPIORegs->GAFR0_U |=GPIO_24_AF2_SSPSFRM;
g_pGPIORegs->GAFR0_U |= GPIO_25_AF2_SSPTXD;
g_pGPIORegs->GAFR0_U |= GPIO_26_AF1_SSPRXD;
// Set up SSP registers (when disabled SSP)
// set up SSP control register 0 and 1
g_pSSPRegs->sscr0 = (SCR_7_KHZ | SSE_DISABLE | ECS_INTERNAL |FRF_MOTOROLA | DSS_16_BIT );
g_pSSPRegs->sscr1 = (RFT_SEVEN | TFT_ZERO | MWDS_8_BIT | SPH_HALF_DELAY |SPO_IDLE_LOW | LBM_DISABLE | TIE_DISABLE | RIE_DISABLE );
// Enable SSP last
//g_pGPIORegs->GPCR0 |= (GPIO_24_SFRM );
g_pSSPRegs->sscr0 |= SSE_ENABLE;
// enable SPI1 Unit clock
g_pClockRegs->cken |= XLLP_CLKEN_SSP1;
// DumpRegsGPIO();
// DumpRegsSSP();
// DumpRegsClock();
}
void lcdPowerUp(void)
{
int i;
volatile SSP_REGS *g_pSSPRegs = (volatile SSP_REGS *)SSP1_BASE_U_VIRTUAL;
volatile XLLP_GPIO_T *g_pGPIORegs = (volatile XLLP_GPIO_T *)GPIO_BASE_U_VIRTUAL;
SetupSPI(true); //spi init
g_pGPIORegs->GPCR0&=(0x01<<24); //set cs Low
//2.delay 5ms ->R09 = 0000h
msWait(5); //delay 5ms
LCD_SEL_REG(9);
LCD_SET_DATA(0x0);
//3.delay More than 10ms ->Power Setting Function 1 ->(R09 ← 4000h R0A ← 2000h)
msWait(10); //delay 10ms
LCD_SEL_REG(9);
LCD_SET_DATA(0x4000);
LCD_SEL_REG(10);
LCD_SET_DATA(0x2000);
//4. Power Setting Function 2 -> R09 ← 4055h
LCD_SEL_REG(9);
LCD_SET_DATA(0x4055);
//5.delay more than 50ms Instruction Setting
msWait(50); //delay 50ms
for(i=0;i<sizeof(LCD_REGS_VAL);i++){
if(i!=8){
LCD_SEL_REG(i+1);
LCD_SET_DATA(LCD_REGS_VAL);
}
}
//6.Wait more than 2 Frames
msWait(27); //delay 27ms
//7.Display On Sequence ->R09 ← 4A55h R05 ← 5003h
LCD_SEL_REG(9);
LCD_SET_DATA(0x4A55);
LCD_SEL_REG(5);
LCD_SET_DATA(0x5003);
g_pGPIORegs->GPCR0&=0x000000;
} |
|