|
发表于 2012-6-6 12:52:50
|
显示全部楼层
#include <iom8.h>
#include "SPI595.h"
__flash unsigned char Table[]={
0x03, //"0"
0x9F, //"1"
0x25, //"2"
0x0D, //"3"
0x99, //"4"
0x49, //"5"
0x41, //"6"
0x1F, //"7"
0x01, //"8"
0x09, //"9"
0x11, //"A"
0xC1, //"B"
0x63, //"C"
0x85, //"D"
0x61, //"E"
0x71, //"F"
0x91, //"H"
0xE3, //"L"
0x13, //"n"
0x83, //"u"
0x31, //"P"
0xC5, //"o"
0xFD, //"-"
0xFF, //close
};
__flash unsigned char Bit_Tab[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //NPN
unsigned char DisBuffer[8] = {1,2,3,4,5,6,7,8};
#pragma vector = SPI_STC_vect
__interrupt void SPI_isr(void)
{
volatile static unsigned char Loop=0,LedCycle=0;
_CLI();
if(Loop == 0)
{
SPDR = Bit_Tab[LedCycle];
Loop = 1;
}
else
{
if(Loop == 1)
{
SPDR = Table[DisBuffer[LedCycle]];
Loop = 3;
}
else
{
Loop = 0;
ST_CLKHigh;
_NOP();
_NOP();
_NOP();
_NOP();
ST_CLKLow;
SPDR = 0x00;
LedCycle++;
LedCycle &= 0x7;
}
}
_SEI();
}
void SPI_MasterInit(void)
{
PORTB|= (1<<PB2) | (1<<PB5) | (1<<PB7);
DDRB |= (1<<PB2) | (1<<PB5) | (1<<PB7);
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 2*2000.000 kHz
// SPI Clock Phase: Cycle Start
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0xD1;
SPSR=0x00;
_NOP();
_NOP();
SPDR = 0xff;
}
在中断里调 用的,用M8
|
|