1. 程式人生 > >使用c8051f005通過SPI讀取SCA100T角度值的程式

使用c8051f005通過SPI讀取SCA100T角度值的程式

//main.c
/*
***************************************************
 * Template for C8051F00x written by Manio,
http://blog.csdn.net/manio
 * This template aim to make the program more clear
 * to read and write.
 * Any other function file should follow this rule.
 ***************************************************
*/

#include 
<c8051f000.h>
#include 
"defs_c51_manio.h"
#include 
"spi.h"/////////////////////////////////////////////////////// Include function head file here /////////////////////////////////////////////////////


/////////////////////////////////////////////////////// Define Global macro #define xxx xxxxx/////////////////////////////////////////////////////


/////////////////////////////////////////////////////// Define Global var/////////////////////////////////////////////////////


/////////////////////////////////////////////////////// DECLARE LOCAL FUNCTION/////////////////////////////////////////////////////void MCU_Init(void);

void LongDelay( void ){
    
uint i ;
    
for ( i =0 ; i <30 ; ++i );
}

main(){
    
uint result;
    
//CLEAN THE DOG    WDTCN 
=0xde;                              // disable watchdog timer    WDTCN =0xad;

    
//SET THE CRYSTAL
    
//OSCICN = (OSCICN & 0xf0) | 0x07;        //use the inner crystal and set to 16MHZ

    
//All the module initial here    MCU_Init(); 
    
    P1 
=0xf0;                            //Initialize the inner reg, etc.interrupt timer pwm...


    
//Operations
    SPI_Reset();
    SPI_Delay(
1000);

    SPI_Init();    
    SPI_Delay(
1000);

    
while(1){
        result 
= SPI_GetX();
        
//P1 = result >>3;
        
//LongDelay();    }
}


/////////////////////////////////////////////////////// DEFINE FUNCTION USED IN MAIN//////////////////////////////////////////////////////****************************************************
 * MCU_Init
 * Function: initiallize interrupt ,crystal .... 
 ***************************************************
*/void MCU_Init(void){
    
//SET THE CROSSBAR eg. XBR0 XBR1    XBR2     XBR2 =0x40;

    
//SET THE IO MODE PRTxCF    PRT0CF =0xff;
    PRT1CF 
=0xff;


    
//Timer Init

    
//Interrupt Setting

    
//Interrupt Enable Disable

    
//Other inner reg setting ,LIKE SMBus PWM PCA...



    
//Global interrupt Enable or Disable
    
//EA = 1;
}


/////////////////////////////////////////////////////// DEFINE INTERRUPT FUNCTION/////////////////////////////////////////////////////