//-------------- //main loop int main(void) { int i=0; for(i=0;i<100000ul;i++); rcc_config(); nvic_config(); gpio_config(); usart_config(); USART_puts(USART1, "USART BT initialization complete!\r\n"); // just send a message to indicate that it works MPU6050_I2C_Init(); MPU6050_Initialize(); if( MPU6050_TestConnection() == 1){ // connection success USART_puts(USART1, "I2C IMU connection initialization complete!\r\n"); }else{ // connection failed USART_puts(USART1, "I2C initialization failed!\r\n"); } //sysTick_Config_Mod(SysTick_CLKSource_HCLK_Div8, 10500000ul); // interruption every 1/2sec from systick sysTick_Config_Mod(SysTick_CLKSource_HCLK_Div8, 840000ul); // interruption every 0.04sec from systick while(1) { } }
int main() { rcc_clock_enable(); delay_config(); usart_config(UART4, 115200); print_clock_freq(); //encoder_init(); STM_EVAL_LEDInit(LED4); TIM7_init(10000, 8400); while(1){ STM_EVAL_LEDToggle(LED4); delay_ms(1000); } }
int main(void) { Delay_Init(); RCC_Configuration(); LED_GPIO(); usart_config(); /*while(1) { printf("pr is ok!\n"); delay_ms(800); }*/ OSInit();//初始化UCOS操作系统 OSTaskCreate(start_task,//指向任务代码的指针 (void *)0,//任务开始执行时,传递给任务参数的指针 (OS_STK *)&START_TASK_STK[START_STK_SIZE-1],//分配给任务堆栈的栈顶指针 START_TASK_PRIO);//分配给任务的优先级 OSStart();//启动ucos操作系统 }
void system_init(void) { /* Configure system tick */ systick_device_config(CLOCKS_PER_SEC); /* Configure serial port as terminal */ usart_config(); /* No buffering, serial input/output occurs immediately */ setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); printf("\nF4-DiscoverFree system init...\n"); /* Configure microSD card through SDIO */ printf("configuring file system...\n"); memset(&fs32, 0, sizeof(FATFS)); res = f_mount(0, &fs32); printf("done!\n\n"); printf("Welcome to Aisenke's\n"); printf(" _ _ _ _\n"); printf(" | \\ | | ___ __| |_|___ ___\n"); printf(" | \\| |/ _ \\/ _' | | _ \\/ _ \\\n"); printf(" | |\\ | |_| |_| | | | | |_| |\n"); printf(" |_| \\_|\\___/\\__._|_|_| |_\\___/\n"); printf(" ____ _ _ _\n"); printf(" | _ \\ ___ | |__ ___ | |_|_| ___ ___\n"); printf(" | |_| / _ \\| '_ \\/ _ \\| __| |/ __/ __|\n"); printf(" | _ < |_| | |_| |_| | |_| | |__\\__ \\\n"); printf(" |_| \\_\\___/|_.__/\\___/ \\__|_|\\___|___/\n"); printf("\n"); printf("For further information check:\n"); printf("http://www.aisenke.com/nodinorobotics\n"); printf("\n"); }
int main(void) { // asm("nop"); rtc_init(); //changing the clock to 32MHz enable_oscillator(OSC_RC32MEN_bm); sysclk_prescaler(CLK_PSADIV_1_gc,CLK_PSBCDIV_1_1_gc); sysclk_source(CLK_SCLKSEL_RC32M_gc); usart_config(&USARTC0,&PORTC,USART_CMODE_ASYNCHRONOUS_gc,USART_PMODE_DISABLED_gc,USART_CHSIZE_8BIT_gc,false,false); usart_baud(&USARTC0,9600,-3); FILE my_stdio; create_file_stream(&my_stdio,&USARTC0_putchar,&USARTC0_getchar); set_stdio_stream(&my_stdio); port_direction_set_mask(&PORTR,1<<0); uint8_t page; uint8_t column; gfx_mono_set_framebuffer(framebuffer); ssd1306_init(); ssd1306_clear(); ssd1306_set_display_start_line_address(0); for (page = 0; page < GFX_MONO_LCD_PAGES; page++) { for (column = 0; column < GFX_MONO_LCD_WIDTH; column++) { gfx_mono_ssd1306_put_byte(page, column, 0x00, 1); } } ssd1306_set_page_address(0); ssd1306_write_text("EMON"); rtc_ms_delay(1000); lcd_line_print(0,"EMON YOU ROCK"); esp8266_serial_init(); printf("starting system\n"); printf("-----------------------------------------------------------\n"); #define mqtt_callback_on_message "function(conn, topic, data) print(topic .. \":\" ) if data ~= nil then print(data) end end" // //esp8266_getmode(); esp8266_setmode(ESP8266_WIFI_MODE_STATION); esp8266_available_AP_t myAPdata[10]; int n = esp8266_sta_getap(3000,myAPdata); for(int i=0;i<n;i++){ printf("available ssid : %s\n" , myAPdata[i].BSSID); } esp8266_sta_config("Emon","19031992",NULL,NULL); printf("\nthe wifi mode is %d\n", esp8266_getmode()); esp8266_sta_getmac(); //esp8266_uart_setup(0,9600,8,ESP8266_UART_PARITY_NONE,ESP8266_UART_STOPBITS_1,0); // esp8266_sta_getip(); esp8266_sta_get_status(); lcd_line_print(0,"HABIBUR RAHMAN"); // esp8266_mqtt_create_client("m","clientid", 30 , "user", "password"); esp8266_mqtt_client_connect("m","emon.dlinkddns.com",9000,0,"function(conn) print(\"m:connected\") end"); esp8266_mqtt_client_subscribe("m","sky2",0,"function(conn) print(\"subscribed\") end"); esp8266_mqtt_client_callback_on_message("m",mqtt_callback_on_message); esp8266_mqtt_create_client("n","clientid", 30 , "user", "password"); esp8266_mqtt_client_connect("n","broker.hivemq.com",1883,0,"function(conn) print(\"n:connected\") end"); esp8266_mqtt_client_subscribe("n","dog",0,"function(conn) print(\"subscribed\") end"); esp8266_mqtt_client_callback_on_message("n",mqtt_callback_on_message); int i=0; char numstr[30]; char mydata[100]; char mydata2[100]; char tempcmd[50]; char tempdata[100]; while (1) { esp8266_rx_buff_receive(mydata); if(!strcmp(mydata, "sky2:\r\nkaminey\r\n")){ printf("\n\n******f**k you*****\n\n"); esp8266_mqtt_client_publish("m","sky","test reply .. by emon",0,0,"function(conn) print(\"sent\") end"); printf(mydata2); } else if(!strcmp(mydata, "m:connected\r\n")){ printf("RECONNECTING NOWWWWW!!!"); esp8266_mqtt_client_subscribe("m","sky2",0,"function(conn) print(\"subscribed\") end"); } else if(!strcmp(mydata, "n:connected\r\n")){ printf("RECONNECTING NOW!!!"); esp8266_mqtt_client_subscribe("n","dog",0,"function(conn) print(\"subscribed\") end"); } printf(mydata); ssd1306_clear(); ssd1306_set_page_address(0); ssd1306_write_text(mydata); } }