#define __MAIN_C__ #include #define AHB_LED_BASE 0x50000000 #define AHB_SW_BASE 0x50000004 // Define pointers with correct type for access to 16-bit peripherals volatile uint16_t* LED_BASE_POINTER = (volatile uint16_t*) AHB_LED_BASE; volatile uint16_t* SW_BASE_POINTER = (volatile uint16_t*) AHB_SW_BASE; // LED and Switch bytes can be addressed individually volatile uint8_t* LED_BYTES = (volatile uint8_t*) AHB_LED_BASE; volatile uint8_t* SW_BYTES = (volatile uint8_t*) AHB_SW_BASE; #include ////////////////////////////////////////////////////////////////// // Main Function ////////////////////////////////////////////////////////////////// void write_leds(uint16_t value) { *LED_BASE_POINTER = value; } uint16_t read_leds(void) { return *LED_BASE_POINTER; } void write_leds_low(uint8_t value) { LED_BYTES[0] = value; } void write_leds_high(uint8_t value) { LED_BYTES[1] = value; } uint16_t read_switches(void) { return *SW_BASE_POINTER; } uint16_t read_switches_low(void) { return SW_BYTES[0]; } uint16_t read_switches_high(void) { return SW_BYTES[1]; } int factorial(int value) { if ( value == 0 ) return 1; else return ( value * factorial(value - 1) ); } void delay_loop(int value) { volatile int i; for ( i = 1; i <= value; i++ ) {}; } int main(void) { int fact_in; write_leds( 0xA5A5 ); while( read_switches() != 0xFFFF ){ write_leds_low( read_switches_high() ); write_leds_high( read_switches_low() ); } write_leds( 0xA815 ); while( read_switches() != 0x0000 ){} while(1){ fact_in = read_switches_low() & 7; write_leds( factorial(fact_in) ); } }