工程下载地址:http://blog.chinaunix.net/u3/106835/showart_2390102.html
#include "config.h"
#define HC595_CS (1 << 7)
#define NixieTube_CS (1<< 11) void DelayMS(uint32 dly){ uint32i; for(; dly> 0; dly--) { for(i = 0; i < 50000; i++); }}void MSPI_Init(void)
{ PINSEL0 =(PINSEL0 & 0xFFFF00FF) | 0x00001500;SPCCR =0x52; // 设置SPI时钟分频
SPCR = (0<< 3)| // CPHA = 0, 数据在SCK 的第一个时钟沿采样 (1 << 4)| // CPOL = 1, SCK 为低有效 (1 << 5)| // MSTR = 1, SPI 处于主模式 (0 << 6)| // LSBF = 0, SPI 数据传输MSB (位7)在先 (0 <<7); // SPIE = 0, SPI 中断被禁止}void MSPI_SendData(uint8 data)
{ IOCLR =HC595_CS; // 片选74HC595 SPI_SPDR =data; while( 0 ==(SPI_SPSR &0x80)); // 等待SPIF置位,即等待数据发送完毕 IOSET =HC595_CS;}
uint8 const DISP_TAB[19] = {
// 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,// L P C 0xC7, 0x8C,0xC6 }; int main (void){ uint8i; PINSEL0 =0x00001500; // 设置SPI管脚连接 IODIR =HC595_CS|NixieTube_CS; IOSET =IOSET|NixieTube_CS; MSPI_Init();// 初始化SPI接口 while(1) { for(i = 0; i < 16; i++) { MSPI_SendData(DISP_TAB[i]); // 发送显示数据 DelayMS(80); } } return0;}