Projekt/snake_init.c
void init_controller(){
	  /*
	  This will set the peripheral bus clock to the same frequency
	  as the sysclock. That means 80 MHz, when the microcontroller
	  is running at 80 MHz. Changed 2017, as recommended by Axel.
	*/
	SYSKEY = 0xAA996655;  /* Unlock OSCCON, step 1 */
	SYSKEY = 0x556699AA;  /* Unlock OSCCON, step 2 */
	while(OSCCON & (1 << 21)); /* Wait until PBDIV ready */
	OSCCONCLR = 0x180000; /* clear PBDIV bit <0,1> */
	while(OSCCON & (1 << 21));  /* Wait until PBDIV ready */
	SYSKEY = 0x0;  /* Lock OSCCON */
	
	/* Set up output pins */
	AD1PCFG = 0xFFFF;
	ODCE = 0x0;
	TRISECLR = 0xFF;
	PORTE = 0x0;
	
	/* Output pins for display signals */
	PORTF = 0xFFFF;
	PORTG = (1 << 9);
	ODCF = 0x0;
	ODCG = 0x0;
	TRISFCLR = 0x70;
	TRISGCLR = 0x200;
	
	/* Set up input pins */
	TRISDSET = (1 << 8);
	TRISFSET = (1 << 1);
	
	/* Set up SPI as master */
	SPI2CON = 0;
	SPI2BRG = 4;
	/* SPI2STAT bit SPIROV = 0; */
	SPI2STATCLR = 0x40;
	/* SPI2CON bit CKP = 1; */
        SPI2CONSET = 0x40;
	/* SPI2CON bit MSTEN = 1; */
	SPI2CONSET = 0x20;
	/* SPI2CON bit ON = 1; */
	SPI2CONSET = 0x8000;
}
/*Given to us in the lab*/
Given to us in the lab
Given to us in the lab
void init_controller(){
	SYSKEY = 0xAA996655;  
	SYSKEY = 0x556699AA;  
	while(OSCCON & (1 << 21)); 
	OSCCONCLR = 0x180000; 
	while(OSCCON & (1 << 21));  
	SYSKEY = 0x0;  
	AD1PCFG = 0xFFFF;
	ODCE = 0x0;
	TRISECLR = 0xFF;
	PORTE = 0x0;
	PORTF = 0xFFFF;
	PORTG = (1 << 9);
	ODCF = 0x0;
	ODCG = 0x0;
	TRISFCLR = 0x70;
	TRISGCLR = 0x200;
	TRISDSET = (1 << 8);
	TRISFSET = (1 << 1);
	SPI2CON = 0;
	SPI2BRG = 4;
	SPI2STATCLR = 0x40;
        SPI2CONSET = 0x40;
	SPI2CONSET = 0x20;
	SPI2CONSET = 0x8000;
}
void init_controller ( ) { SYSKEY = 0xAA996655 ; SYSKEY = 0x556699AA ; while ( OSCCON & ( 1 << 21 ) ) ; OSCCONCLR = 0x180000 ; while ( OSCCON & ( 1 << 21 ) ) ; SYSKEY = 0x0 ; AD1PCFG = 0xFFFF ; ODCE = 0x0 ; TRISECLR = 0xFF ; PORTE = 0x0 ; PORTF = 0xFFFF ; PORTG = ( 1 << 9 ) ; ODCF = 0x0 ; ODCG = 0x0 ; TRISFCLR = 0x70 ; TRISGCLR = 0x200 ; TRISDSET = ( 1 << 8 ) ; TRISFSET = ( 1 << 1 ) ; SPI2CON = 0 ; SPI2BRG = 4 ; SPI2STATCLR = 0x40 ; SPI2CONSET = 0x40 ; SPI2CONSET = 0x20 ; SPI2CONSET = 0x8000 ; }
Given to us in the lab
Given to us in the lab
/*
	  This will set the peripheral bus clock to the same frequency
	  as the sysclock. That means 80 MHz, when the microcontroller
	  is running at 80 MHz. Changed 2017, as recommended by Axel.
	*/ /* Unlock OSCCON, step 1 */ /* Unlock OSCCON, step 2 */ /* Wait until PBDIV ready */ /* clear PBDIV bit <0,1> */ /* Wait until PBDIV ready */ /* Lock OSCCON */ /* Set up output pins */ /* Output pins for display signals */ /* Set up input pins */ /* Set up SPI as master */ /* SPI2STAT bit SPIROV = 0; */ /* SPI2CON bit CKP = 1; */ /* SPI2CON bit MSTEN = 1; */ /* SPI2CON bit ON = 1; */