int main(void) { u8 cnt; board_setup(); configure_leds(C); light_leds(C, 0x0); enable_interrupt(0, IT_RAISING_EDGE); enable_interrupt(1, IT_LEVEL); usart_init(9600); sei(); light_leds(C, 0x1); { u8 hw[] = "HELLO WORLD\n"; usart_write(hw, sizeof(hw)-1); } for (;;) { int_clear_ack(0); int_clear_ack(1); led_cbk[cur_led_cbk](); _delay_ms(1000); } return 0; }
//***** chip Initialization ********************************** void chip_init(void) { // If using crystal oscillator of 16 Mhz // Note - May want to set the CKDIV8 fuse if MCU is only supposed to run // at 8MHz so as not to exceed its operating conditions at startup. // CLKPR = ( 1 << CLKPCE ); // Set Clock Prescaler change enable // CLKPR = 0x01; // Clock Division Factor of 2 // Note - CLKPR must be written within 4 clock cycles of setting CLKPCE DDRB = 0xFF; // PORT B to be outputs for LED monotoring DDRC = 0x00; // Inputs, not used DDRE = 0x00; // Inputs, not used PORTB = 0xFE; // ALL LEDs OFF PORTC = 0x00; // Inputs, not used PORTD = 0x00; // Inputs, not used PORTE = 0x00; // Inputs, not used PRR = 0x00; // Individual peripheral clocks enabled DDRC |= 0x04; // PC 2, TXCAN Output DDRC &= ~0x08; // PC 3, RXCAN Input PORTC &= ~0x08; configure_leds(); RESET_LED_1 RESET_LED_2 RESET_LED_3 RESET_LED_4 }
/* Main Code */ /************************************************************************/ int main(void) { /* Initialize the SAM system */ sysclk_init(); /* Disable the watchdog */ WDT->WDT_MR = WDT_MR_WDDIS; /* Configura Leds */ configure_leds(); /** Configura o timer */ configure_tc(); /* Configura os botões */ configure_buttons(); while (1) { /* Entra em modo sleep */ pmc_sleep(SAM_PM_SMODE_SLEEP_WFI); }
int main(void) { uint8_t uc_key; /* Initialize the system */ sysclk_init(); board_init(); /* Configure LED 1 */ pmc_enable_periph_clk(PIN_LED_BLUE_ID); pio_set_output(PIN_LED_BLUE_PIO , PIN_LED_BLUE_MASK, 1, 0, 0); /* Initialize debug console */ config_uart(); /* frase de boas vindas */ puts(" ---------------------------- \n\r" " Bem vindo terraquio ! \n\r" " ---------------------------- \n\r"); /* Enable peripheral clock */ pmc_enable_periph_clk(ID_SMC); /** Configura o LEDs */ configure_leds(); /** Configura o timer */ configure_tc(); /* Configuração LCD */ configure_lcd(); desenhaCabecalho(); /* display main menu */ display_menu(); while (1) { usart_serial_getchar((Usart *)CONSOLE_UART, &uc_key); switch (uc_key) { case '1': display_menu(); break; case '2': flagLED = 0; pio_clear(PIN_LED_BLUE_PIO, PIN_LED_BLUE_MASK); puts("Led ON \n\r"); break; case '3' : flagLED = 1; pio_set(PIN_LED_BLUE_PIO, PIN_LED_BLUE_MASK); puts("Led OFF \n\r"); break; case '4' : flagLED = 2; pio_set(PIN_LED_BLUE_PIO, PIN_LED_BLUE_MASK); puts("Led OFF \n\r"); break; case '5' : flagLED = 3; pio_set(PIN_LED_BLUE_PIO, PIN_LED_BLUE_MASK); puts("Defina a o valor da Frequência (0-65356) \n\r"); usart_serial_getchar((Usart *)CONSOLE_UART, &uc_key); //tc_write_rc(uc_key); break; default: printf("Opcao nao definida: %d \n\r", uc_key); } } }