/* p2_5.c * * Display number 35 on a 2-digit 7-segment common cathode LED. * The segments are driven by Port B. * The digit selects are driven by PA4 and PA5. * * Tested with Atmel Studio 7 v7.0.1006 and Keil MDK-ARM v5.20 */ #include "samd21.h" void delayMs(int n); int main(void) { const unsigned char digitPattern[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; REG_PORT_DIRSET1 = 0x0000007F; /* make PB6-PB0 output */ REG_PORT_DIRSET0 = 0x00000030; /* make PA5-PA4 output */ for(;;) { REG_PORT_OUT1 = digitPattern[3]; /* display tens digit */ REG_PORT_OUTSET0 = 0x20; /* deselect ones digit */ REG_PORT_OUTCLR0 = 0x10; /* select tens digit */ delayMs(8); REG_PORT_OUT1= digitPattern[5]; /* display ones digit */ REG_PORT_OUTSET0 = 0x10; /* deselect ones digit */ REG_PORT_OUTCLR0 = 0x20; /* select tens digit */ delayMs(8); } } /* millisecond delay based on 8 MHz system clock */ void delayMs(int n) { int i; for (; n > 0; n--) for (i = 0; i < 199; i++) __asm("nop"); }