我用keil的模拟仿真,设置断点,看到的SPI0DAT 一直是0,程序还会卡住,卡到等待SPIF置1,一直动不了,求大神们帮忙看一下程序,
我想问的是我的spi编程的思路是不是错的,还有c8051f020的nss是直接自己会随着传数据改变还是得自己编程设置,
void main(void )
{
Watchdog_Init (); // Disable the Watchdog Timer first
Oscillator_Init ();
PORT_Init ();
SPI0_Init ();
while(1)
{
lcdpoint1 = & NCDdata1;
lcdpoint2 = & NCDdata2;
Initialize_LCD();
Display_LCD_String(1,lcdpoint1,10) ;
ShowString(0,1,lcdpoint2,10) ;
DelayMS(50);
SPIF = 0;
SPI0DAT = NCDdata2[k]-0x30;
DelayMS(10);
while(SPIF ==0) ;
SPIF = 0;
k++;
if(k==10) k=0;
}
}
void Watchdog_Init (void)
{
WDTCN = 0xDE; // Disable the Watchdog Timer
WDTCN = 0xAD;
}
// This function initializes the system clock to use the internal oscillator
// at 16 MHz.
//
//-----------------------------------------------------------------------------
void Oscillator_Init (void)
{
OSCICN = 0x05; // // 系统时钟初始化为片内的 24.5MHz / 8
}
//
// P0.0 - SCK (SPI0), Push-Pull, Digital
// P0.1 - MISO (SPI0), Open-Drain, Digital
// P0.2 - MOSI (SPI0), Push-Pull, Digital
// P0.3 - NSS (SPI0), Open-Drain, Digital
//
// P0.7 - SLAVE_SEL, Push-Pull, Digital
void PORT_Init (void)
{
P0MDOUT = 0x0f; // Make SCK, MOSI, and SLAVE_SEL
// push-pull
// P1MDOUT = 0x40; // Make the LED push-pull
XBR0 = 0x02; // Enable the SPI on the XBAR
XBR2 = 0x40; // Enable the XBAR and weak pull-ups
P2MDOUT = 0xf0; // P2口设为推挽方式
P3MDOUT = 0x00;
}
void SPI0_Init()
{
SPI0CFG = 0x07; // SPI transmits 8 bits
SPI0CN = 0x03; // Master, SPI enabled
// SPI clock frequency equation from the datasheet
SPI0CKR = (SYSCLK/(2*SPI_CLOCK))-1;
// EIE1 |= 0x01; // Enable SPI interrupts
}
此帖出自
小平头技术问答
一周热门 更多>