|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 cjsb37 于 2013-4-29 09:08 编辑
void LcdObj:cdSpiSetup(void)
{
#if (ccsdebug == 0)
/*-----------------------------------------------------------
硬件McBSP模块配置为SPI接口
实验目的:
演练硬件McBSP模块配置为SPI接口的应用。
------------------------------------------------------------*/
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = 0;
// McBSP1->SPSD &= ~(1 << SPCR1_RRST);//禁止串口接收
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR2;
McBSP1->SPSD = 0;
// McBSP1->SPSD &= ~(1 << SPCR2_XRST);//禁止串口发送
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = (0x02 << SPCR1_CLKSTP);//CLKSTP=10b
_delay_loop_(1);//延时等待
McBSP1->SPSA = PCR;
McBSP1->SPSD = (1 << PCR_FSXM) //设置FSX引脚为输出,控制LCD12864的片选信号SS
| (0 << PCR_FSXP) //FSX引脚平时输出低电平(LCD12864的片选信号SS无效)
| (1 << PCR_CLKXM) //设置CLKX引脚为输出
| (1 << PCR_CLKXP);//CLKXP引脚平时输出高电平
_delay_loop_(1);//延时等待
McBSP1->SPSA = SRGR1;
McBSP1->SPSD = (0x07 << SRGR1_FWID) //0x00~0x07~0xff
| (0x80 << SRGR1_CLKGDV);//速率0x80
_delay_loop_(1);//延时等待
McBSP1->SPSA = SRGR2;
McBSP1->SPSD = (1 << SRGR2_CLKSM);//
_delay_loop_(1);//延时等待
McBSP1->SPSA = RCR1;
McBSP1->SPSD = (0x00 << RCR1_RFRLEN1);//8BIT
_delay_loop_(1);//延时等待
McBSP1->SPSA = XCR1;//延时等待
McBSP1->SPSD = (0x00 << XCR1_RFRLEN1);//8BIT
_delay_loop_(1);//延时等待
McBSP1->SPSA = RCR2;
McBSP1->SPSD = (0x02 << RCR2_RDATDLY);//0x01
_delay_loop_(1);//延时等待
McBSP1->SPSA = XCR2;
McBSP1->SPSD = (0x02 << XCR2_RDATDLY);//0x01
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR2;
McBSP1->SPSD |= (1 << SPCR2_GRST) | (1 << SPCR2_XRST) | (1 << SPCR2_FRST);
_delay_loop_(1);//延时等待
#else
/*-----------------------------------------------------------
硬件McBSP模块配置为普通IO软件模拟SPI时序
实验目的:
演练硬件McBSP模块配置为普通IO的应用.以备IO紧缺时急用。
------------------------------------------------------------*/
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = 0;
McBSP1->SPSD &= ~(1 << SPCR1_RRST);//禁止串口接收
McBSP1->SPSA = SPCR2;
McBSP1->SPSD = 0;
McBSP1->SPSD &= ~(1 << SPCR2_XRST);//禁止串口发送
McBSP1->SPSA = PCR;
McBSP1->SPSD = (1 << PCR_XIOEN) | (1 << PCR_RIOEN);//设置收发为IO接口,DX输出,DR,CLKS输入
McBSP1->SPSD |= (1 << PCR_FSXM) | (1 << PCR_CLKXM);//设置FSX,CLKX可做IO输出
McBSP1->SPSD |= (1 << PCR_FSRM) | (1 << PCR_CLKRM);//设置FSR,CLKR可做IO输出
McBSP1->SPSD &= ~(1 << PCR_FSXP);//FSX信号=0
McBSP1->SPSD |= (1 << PCR_CLKXP);//CLKX信号=1
McBSP1->SPSD |= (1 << PCR_DX_STAT);//DX信号=1
#endif
}
void LcdObj:cdSend(unsigned char cData)
{
cData &= 0xff;
#if (ccsdebug == 0)
McBSP1->DXR1 = cData;//发送串行数据或命令
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR2;
while((McBSP1->SPSD & (1 << SPCR2_XRDY)) == 0) {//等待发送结束
__nop();
__nop();
}
_delay_loop_(1);//延时等待
#else
unsigned int i;
McBSP1->SPSA = PCR;
for (i = 0; i < 8; i ++) {
McBSP1->SPSD &= ~(1 << PCR_CLKXP);//CLKX信号=0
_delay_loop_(1);//延时等待
if (cData & 0x80) {//MSB最高位为1时
McBSP1->SPSD |= (1 << PCR_DX_STAT);//DX信号=1
}
else {
McBSP1->SPSD &= ~(1 << PCR_DX_STAT);//DX信号=0
}
cData <<= 1;
_delay_loop_(1);//延时等待
McBSP1->SPSD |= (1 << PCR_CLKXP);//CLKX信号=1
_delay_loop_(1);//延时等待
}
McBSP1->SPSD |= (1 << PCR_DX_STAT);//DX信号=1
_delay_loop_(1);//延时等待
#endif
}
|
|