We wrote the following code:
# include <c8051f120.h> # include <stdio.h> int i; sbit miso=P0^1; // P0.1 receives data from SDCARD void uddelay(double a) // Delay function for 'a' machine cycles { int j; for(j=0;j<a;j++); } void device_init() // Initialises all devices { SFRPGCN=0x01; // Disable Watch dog timer WDTCN=0x0DE; WDTCN=0x0AD; SFRPAGE=CONFIG_PAGE; // Set the crossbars XBR0=0x02; XBR1=0x00; XBR2=0x40; SFRPAGE=CONFIG_PAGE; // Set system clock using internal oscillator to 24.5 MHz OSCICN=0x83; //CLKSEL=0x00; OSCXCN=0x00; SFRPAGE=LEGACY_PAGE; // Disabling flash FLSCL=0x30; SFRPAGE=CONFIG_PAGE; // Initialise PLL PLL0CN=0x01; PLL0DIV=0x01; PLL0FLT=0x01; PLL0MUL=0x04; uddelay(5); PLL0CN=0x03; while(PLL0CN!=0x13); CLKSEL=0x02; SFRPAGE=SPI0_PAGE; // Initialise SPI SPI0CFG=0x43; SPI0CN=0x03; SPI0CKR=0x79; // Initialises port P0 SFRPAGE=CONFIG_PAGE; P0MDOUT=0x05; miso=1; } void main() { device_init(); // device initialisation while(1); }
Please suggest corrections so that SCK is generated at P0.0