main.c

来自「kei carm lpc2103 例子 好东西」· C语言 代码 · 共 93 行

C
93
字号
/******************************************************************************/
/*  This file is part of the uVision/ARM development tools                    */
/*  Copyright KEIL ELEKTRONIK GmbH 2002-2004                                  */
/******************************************************************************/
/*                                                                            */
/*  HELLO.C:  Hello World Example                                             */
/*                                                                            */
/******************************************************************************/

#include <stdio.h>                          /* I/O Functions */
#include <LPC21XX.H>                        /* LPC22XX Peripheral Registers */

unsigned int Send_byte (unsigned Data);
void wait(void);
unsigned int read_byte (void);

#define CS_HIGH IOSET0 = 0x1000
#define CS_LOW  IOCLR0 = 0x1000

 unsigned int result= 0;
 unsigned int result2 = 0;

int main (void)  
{

PINSEL0 |= 0x5500;					 //Select SPI pins and enable SSEL0

CS_HIGH;
IODIR0 = 0x1000;						 //Configure GPIO pin to control the CS on the SPI eeprom
				 			 //Set the pin High
//VPBDIV = 0x01;						 //Set the Clock VBP clock to 60 Mhz  // 0x04

S0SPCCR = 0x32;				//Set SPI bit rate at 300Khz  //0xC8
S0SPCR  = 0x00000020;				//set control register

wait();

CS_LOW;
result =  Send_byte(0x55);

result =  Send_byte(0x05);

   while(1)  { 

result =  Send_byte(0xAA);
//result =  Send_byte(0xAA);
//result =  Send_byte(0xAA);
//result =  Send_byte(0xAA);
//result =  Send_byte(0xAA);
//result =  Send_byte(0xAA);

}


  CS_HIGH;

  while(1)  { }
}

unsigned int Send_byte (unsigned Data)
{
unsigned int result;
result = S0SPSR;
 S0SPDR = Data;
 while (!(S0SPSR & 0x80)) ; 
 /*while(S0SPSR == 0)
 {
 ;
 }
 */
return S0SPSR;
}

unsigned int read_byte (void)
{

 while(S0SPSR == 0)
 {
 ;
 }

return S0SPDR;
}

void wait(void)
{
unsigned delay;
for(delay = 0;delay<0x10000;delay++)	//a bit of setteling time
{
;
}
}
 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?