double X,Y,Zi,thetaa1;int thetaa;void SysInit();doubleatan2(double y,double x);void main(){
X=2;
Y=5;
SysInit();while(1){
thetaa1=atan2(Y,X);
thetaa =(int)(thetaa1*57.295);
PORTB=thetaa;}}void SysInit(){
ADCON1=0x06;// disable ADC and make all the pins of Port A as digital input
TRISA=0xFF;
PORTA=0x00;
TRISB=0x00;
PORTB=0x00;
TRISD=0x00;
PORTD=0x00;
TRISE=0x00;
PORTE=0x00;
TRISC.B6=0;
TRISC.B7=0;
TRISC.B4=1;// SDI input
TRISC.B3=1;// SCK input from master
TRISC.B5=0;// SDO output
SSPSTAT.SMP=0;// input data sampled at middle
SSPSTAT.CKE=0;// transition from idle to active//SPI1_Init_Advanced(_SPI_SLAVE_SS_ENABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);}