/****************************************Copyright (c)**************************************************** ** Guangzhou ZHIYUAN electronics Co.,LTD. ** ** http://www.embedtools.com ** **--------------File Info--------------------------------------------------------------------------------- ** File name: main.c ** Last modified Date: 2010-02-04 ** Last Version: V1.0 ** Descriptions: The main() function example template ** **-------------------------------------------------------------------------------------------------------- ** Created by: Lanwuqiang ** Created date: 2010-02-05 ** Version: V1.0 ** Descriptions: 添加用户应用程序 ** **-------------------------------------------------------------------------------------------------------- ** Modified by: ZhangNingbo ** Modified date: 2010-02-25 ** Version: V1.0 ** Descriptions: SPI0主机示例程序 ** **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: ** Version: ** Descriptions: ** ** Rechecked by: *********************************************************************************************************/ #include "..\config.h" /********************************************************************************************************* 宏定义 *********************************************************************************************************/ /* 此表为LED0~F的字模 */ uint8 const DISP_TAB[16] = { /* 0 1 2 3 4 5 6 7 8 9 */ 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8, 0x80,0x90, /* A b C d E F */ 0x88, 0x83, 0xC6, 0xA1,0x86, 0x8E }; /********************************************************************************************************* ** Function name: myDelay ** Descriptions: 软件延时 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void myDelay (INT32U ulTime) { INT32U i; i = 0; while (ulTime--) { for (i = 0; i < 5000; i++); } } /********************************************************************************************************* ** Function name: SSP_Init() ** Descriptions: 将SSP控制器设置为主机SPI。 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void SSP_Init (void) { PRESETCTRL |= 0x01; /* 禁止SPI0复位 */ IOCON_SCKLOC = 0x02; /* P0.6配置为SCK */ SYSAHBCLKCTRL |= (1ul << 11); /* 打开SPI0外设 */ SSP0CLKDIV = 0x01; /* SSP时钟分频 */ SSP0CR0 = (0x01 << 8) | /* SCR 设置SPI时钟分频 */ (0x00 << 7) | /* CPHA 时钟输出相位, */ /* 仅SPI模式有效 */ (0x01 << 6) | /* CPOL 时钟输出极性, */ /* 仅SPI模式有效 */ (0x00 << 4) | /* FRF 帧格式 00=SPI,01=SSI, */ /* 10=Microwire,11=保留 */ (0x07 << 0); /* DSS 数据长度,0000-0010=保留*/ /* 0011=4位,0111=8位,1111=16位 */ SSP0CR1 = (0x00 << 3) | /* SOD 从机输出禁能,1=禁止 */ (0x00 << 2) | /* MS 主从选择,0=主机,1=从机 */ (0x01 << 1) | /* SSE SSP使能 */ (0x00 << 0); /* LBM 回写模式 */ SSP0CPSR = 2; /* PCLK分频值 */ SSP0ICR = 0x03; /* 中断清除寄存器 */ } /********************************************************************************************************* ** Function name: SSP_SendData() ** Descriptions: SSP接口向SPI总线发送数据。 ** input parameters: data 待发送的数据 ** output parameters: 返回值为读取的数据 ** Returned value: 无 *********************************************************************************************************/ uint8 SSP_SendData(uint8 data) { SSP0DR = data; while ((SSP0SR & 0x01) == 0) { /* 等待TFE置位,即发送FIFO空 */ } return(SSP0DR); } /********************************************************************************************************* ** Function name: main ** Descriptions: 硬件基于EasyARM2131,SPI0作主机,驱动595显示,需要连接P0.2与SSEL、P0.6与SCK、P0.8与 ** MISO、P0.9与MOSI。 ** 用户也可以根据自己的底板设计自行连接。 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ int main (void) { uint8 i; targetInit(); /* 初始化目标板,切勿删除 */ pinInit(); /* 引脚初始化 */ SSP_Init(); while (1) { for (i = 0; i < 16; i++) { SSP_SendData(DISP_TAB[i]); /* 发送显示数据 */ myDelay(300); /* 延时 */ } } } /********************************************************************************************************* End Of File *********************************************************************************************************/