void serial_init(void){ SCI_init(SCI_BAUDS,MOD_NONE); SCI_enableRxInterrupts(receiveByte); // Reset the sequence if nothing is received in 1s RTC_init(6); // 1S RTC_enableInterrupts(rxIdleReset); }
//============================================================================= int main(void) { LIGHT_init(); LCD_init(); LIGHT_on(); LCD_clear(); BEEP_init(); RTC_init(); RTOS_init(); RC5_Init(); RC5_Reset(); ENC_init(); KBD_init(); bmp180Init(); dht22Init(); rda5807Init(); rda5807PowerOn(); rda5807SetMute(1); ds18x20SearchDevices(); LCD_goto(0, 0); LCD_puts("POGODNAY STATION"); LCD_goto(0, 1); LCD_puts(" VERSION 1.0 "); _delay_ms(1000); LCD_clear(); LCD_load_bignum(); ds18x20Process(); if (bmp180HaveSensor()) bmp180Convert(); dht22Read(); #if (DEBUG == 1) if ((BUT_1_PINX & (1<<(BUT_1_PIN))) == 0) { _delay_ms(100); if ((BUT_1_PINX & (1<<(BUT_1_PIN))) == 0) { RTOS_setTask(EVENT_SET_STATE_OPTION, 0, 0); BEEP_beep(); while (((BUT_1_PINX & (1<<(BUT_1_PIN))) == 0)) { } BEEP_beep(); } } #else RTOS_setTask(EVENT_SET_STATE_OPTION, 0, 0); BEEP_beep(); #endif RTOS_setTaskFunc(set_blink, 0, 1000); // моргание RTOS_setTaskFunc(KBD_scan, 0, 5); // запускаем опрос кнопок RTOS_setTaskFunc(ENC_poll, 0, 1); // запускаем опрос енкодера RTOS_setTaskFunc(RC5_scan, 0, 5); // запускаем опрос RC5 RTOS_setTask(EVENT_SET_SHOW, 0, 0); // запуск шоу sei(); // Разрешили прерывания while(1) { RTOS_dispatchTask(); // Вызываем диспетчер в цикле. } }
interrupt(USCI_A0_VECTOR)USCI_A0_ISR(void) { if (UCA0RXBUF == 'c') { RTC_init(2013,10,10,10,10,10); RTCCTL1 |= RTCRDY; printf(" %d %d %d %d %d %d \n",RTCYEAR,RTCMON,RTCDAY,RTCHOUR,RTCMIN,RTCSEC); RTCCTL1 &= ~RTCRDY; } if (UCA0RXBUF == 't') { RTC_init(0,0,0,0,0,0); RTCCTL1 |= RTCRDY; printf(" %d %d %d %d %d %d \n",RTCYEAR,RTCMON,RTCDAY,RTCHOUR,RTCMIN,RTCSEC); RTCCTL1 &= ~RTCRDY; } if (UCA0RXBUF == 's') { RTCCTL1 |= RTCRDY; printf(" %d %d %d %d %d %d \n",RTCYEAR,RTCMON,RTCDAY,RTCHOUR,RTCMIN,RTCSEC); RTCCTL1 &= ~RTCRDY; } }
int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT uart_init(); RTC_init(2013,10,10,10,10,10); __bis_SR_register(GIE); // Enter LPM0, interrupts enabled __no_operation(); // For debugger }
void main(void) { WDTCTL = WDTPW+WDTHOLD; // Stop the dog // RTCCTL01 = RTCBCD | 0x20; //P1DIR |= 0x01; RTC_init(); //RTC_date today = {0x20,0x10,0x03,0x22,0x12, 0x00, 0x55}; //RTC_setDate(&today); //RTC_setMinute(); //RTC_init(); //P1OUT |= 0x1; for(;;) { __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable ints __no_operation(); // For debugger } }
//============================================================================= int main(void) { I2C_init(); LED_init(); KBD_init(); RTC_init(); RTOS_init(); RTOS_setTaskFunc(set_blink, 0, 500); // моргание RTOS_setTaskFunc(KBD_scan, 10, 0); // запускаем опрос кнопок sei(); // Разрешили прерывания #if (DEBUG == 1) RTC_set_time(23, 58, 50); // Test time LED_clear(); #endif while (1) { RTOS_dispatchTask(); // Вызываем диспетчер в цикле. } }
int main(void) { CHIP_Init(); initOscillators(); //init_uart_interface(); #ifdef DEBUG //init_uart_interface_for_debuging(); //uart_sendText("GPS module Startup\n"); init_leuart_interface(); LeUart_SendText("GPS module Startup\n"); #endif //RTC initialization RTC_init(); RTC_setTime(1000); RTC_enableInt(); while(1) { EMU_EnterEM1(); } }
/* *@功能 主函数入口 *@参数 空 *@返回 空 */ int main(void) { /*测试变量部分*/ /*******************************************/ uint8_t t=' '; uint8_t usb_code[6]={0x55,0x7A,0xBB,0x01,0x00,0x01};//下位机反复的向上位机发送此命令,用以建立初始化连接 uint8_t p[6]={0x30,0x31,0x32,0x33,0x34,0x35}; uint8_t hanzi[11]; uint8_t *phz; uint32_t flash_data; uint8_t flash_temp[4]; uint8_t status; uint32_t addr; uint8_t nChar; // uint8_t char_buf[50]; // uint8_t count; uint32_t batt_test=0; /*********************************************/ //设置中断向量表的位置在 0x5000,即内部flash的前20K NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x5000); SystemTick_Init(); NVIC_Configuration(); //按键初始化 Init_Sw_Key_Io(); Exit_Line_Init(); EXTILine_Mask(EXTI_Line5); EXTILine_Mask(EXTI_Line8); EXTILine_Mask(EXTI_Line15); //长按开机,如果长按不够3m则继续保持关机状态,如果长按3m,则退出停机模式,开机 WKUP_Init(); EXTILine_Unmask(EXTI_Line5); EXTILine_Unmask(EXTI_Line8); EXTILine_Unmask(EXTI_Line15); //如果没有进入停机模式,则开启显示 OLED_WR_Byte(0xAF,OLED_CMD); //开启显示 longpress=0; stop_flag=0; SPI_FLASH_Init(); //正常运行后,显示logo OLED_Init(); SPI_FLASH_Init(); OLED_Clear(); OLED_DrawBMP(32,2,48,4,hui); OLED_ShowUnite(48,2,"合科技"); //delay_ms(800); USB_BIT_Init(); //为降低功耗的控制位 /****************************************/ bluetooth_control_Init(); max232_control_Init(); oled_control_Init(); OLED_ON; buzzer_control_Init(); BUZZER_OFF; coil_control_Init(); COIL_NO_ACTUATE; /****************************************/ Init_Timer(); //实时时钟初始化 RTC_init(); //初始化并启动看门狗 //iwdg_init(); //串口1 USB初始化及配置 Uart1_Init(); USART1_Configuration(); //串口2 RFID初始化及配置 Uart2_Init(); USART2_Configuration(); //串口3 bluetooth初始化及配置 Uart3_Init(); USART3_Configuration(); bluetooth_Configuration(); //蓝牙的EN和BRST配置 CLR_BT_EN; //开启蓝牙 ADC_GPIO_Configuration(); ADC_Configuration(); //flash区域指针初始化 //SPI_FLASH_WriteWord(INIT_FLAG,1); //此次下载清flash SPI_FLASH_WriteWord(INIT_FLAG,0); //此次下载不清flash if(SPI_FLASH_ReadWord(INIT_FLAG) ==0x01) //当初始化标志等于1,就初始化POINT和ROW { mykey_init(); //初始化钥匙操作的头指针 ---如何设定在什么情况下重新设置 } // OLED_ClearArea(0,4,128,6); // OLED_ShowUnite(24,4,"初始化蓝牙"); // mac_query_result=bluetooth_mac(); /*延时函数测试*/ /**********************************************/ // GPIO_Configuration(); // while(1) // { // GPIO_SetBits(GPIOB,GPIO_Pin_0); // delay_ms(1000); // GPIO_ResetBits(GPIOB,GPIO_Pin_0); // delay_ms(3000); // } /**********************************************/ /*OLED测试*/ /**********************************************/ // while(1) // { // OLED_Clear(); // OLED_ShowChinese(0,0,0); //中 // OLED_ShowChinese(18,0,1); //景 // OLED_ShowChinese(36,0,2); //园 // OLED_ShowChinese(54,0,3); //电 // OLED_ShowChinese(72,0,4); //子 // OLED_ShowChinese(90,0,5); //科 // OLED_ShowChinese(108,0,6);//技 // OLED_ShowString(0,3,"1.3' OLED TEST"); // //OLED_ShowString(8,2,"ZHONGJINGYUAN"); // //OLED_ShowString(20,4,"2014/05/01"); // OLED_ShowString(0,6,"ASCII:"); // OLED_ShowString(63,6,"CODE:"); // OLED_ShowChar(48,6,t);//显示ASCII字符 // t++; // if(t>'~') // t=' '; // OLED_ShowNum(103,6,t,3,16);//显示ASCII字符的码值 // // delay_ms(8000); // //OLED_Clear(); // // OLED_DrawBMP(0,0,128,8,BMP1); //图片显示(图片显示慎用,生成的字表较大,会占用较多空间,FLASH空间8K以下慎用) // delay_ms(800); // // //OLED_Display_On(); // //delay_ms(800); // // OLED_DrawBMP(0,0,128,8,BMP2); // delay_ms(800); // // //OLED_Display_Off(); // //delay_ms(800); // } /**********************************************/ /*OLED+字库测试*/ /**********************************************/ // phz="字库"; // hanzi[0]=*phz; // hanzi[1]=*(phz+1); // hanzi[2]=*(phz+2); // hanzi[3]=*(phz+3); // hanzi[4]=*(phz+4); // // // OLED_ShowChinese(0,0,"汉"); // OLED_ShowChinese(16,0,"字"); // // OLED_ShowUnite(0,2,"你很不错"); // OLED_ShowUnite(0,4,"ABCDEF"); // OLED_ShowUnite(0,6,"123456"); /**********************************************/ /* STM32F103C8串口有3个 串口1通过USB接充电器,与上位机PC通信 串口2通过串口读RFID的数据 串口3通过蓝牙与PDA通信 */ /*串口1 USB测试*/ /**********************************************/ // while(1) // { // UART1nSendChar(1,"12345",5); // delay_ms(1000); // } //UART1nSendChar(1,usb_code,6); //USB_Cheak_init(); //Test_Usb_Data(); // UART1SendwordHex(1, 0x123456); // UART1nSendChar(1,"汉字",5); // while(1); /**********************************************/ /*串口2 RFID测试*/ /**********************************************/ // while(1) // { // OLED_ShowUnite(32,2,"RFID"); // delay_ms(1000); // UART1nSendChar(1,"12345",5); // //OLED_Clear(); //清屏 // nChar =Read_RfidData(2,Rfid_Buff,0xff); // m_UB2; // if(nChar ==5) // { // if(Rfid_Buff[0]==0&&Rfid_Buff[1]==0&&Rfid_Buff[2]==0&&Rfid_Buff[3]==0) // ; // else //至少有一个不为零 // { // UART1nSendChar(1,Rfid_Buff,5); // OLED_ShowNumHex(32,4,Rfid_Buff[0],2,16); // OLED_ShowNumHex(48,4,Rfid_Buff[1],2,16); // OLED_ShowNumHex(64,4,Rfid_Buff[2],2,16); // OLED_ShowNumHex(80,4,Rfid_Buff[3],2,16); // delay_ms(1000); // break; // } // } // } // while(1); /**********************************************/ /*串口3 bluetooth测试*/ /**********************************************/ // CLR_BT_EN; // CLR_BT_BRTS; // // while(1) // { // UART3nSendChar(3,"012345",6); // delay_ms(1000); // } // while(1) // { // UART3nSendChar(3,"TTM:MAC-?",9); // count=UART3GetCount(3); // UART3nReadChar(3,char_buf,count); // // // // // UART1nSendChar(1,char_buf,count); // delay_ms(1000); // } /**********************************************/ /*flash测试*/ /**********************************************/ // SPI_FLASH_WriteWord(AUTHOR_ROW,0x456789); // // SPI_FLASH_BufferRead(flash_temp,AUTHOR_ROW,4); // // flash_data=SPI_FLASH_ReadWord(AUTHOR_ROW); // UART1nSendChar(1,flash_temp,4); // // OLED_ShowNum(0,6,flash_data,8,16); // // //SPI_FLASH_WriteEnable(); // status=SPI_FLASH_ReadStatusReg(); // OLED_ShowNum(112,6,status,1,16); // SPI_FLASH_BulkErase(); // SPI_FLASH_BufferWrite("98765",0x100002,6); // SPI_FLASH_BufferRead(p,0x100002,6); // SPI_FLASH_Write("98765",0x1f0005,6); // SPI_FLASH_Read(p,0x1f0005,6); // while(1) // { // UART1nSendChar(1,p,6); // delay_ms(1000); // } /**********************************************/ //菜单测试 /**********************************************/ //Main_Lcd_Show(); //主界面显示 //Main_Lcd_Show2(); // mode=1; // // OLED_ShowChar(0,0,'A'); // // OLED_ShowChinese(0,2,"我"); // // OLED_ShowUnite(0,4,"你很不错"); // // while(1); // // mode=0; // delay_ms(1000); //ShowMenu(HsMenu); // Choose_MenuOp1(); // Choose_MenuOp4(); // Choose_MenuOp4_1(); // Choose_MenuOp4_2(); // Choose_MenuOp4_22(); // Choose_MenuOp4_3(); // Choose_MenuOp4_4(); // Choose_MenuOp5(); // Choose_MenuOp5_1(); // Choose_MenuOp5_3(); // Choose_MenuOp5_4(); // while(1) // { // Main_Oled_Time(); // Main_Oled_Power(); // delay_ms(1000); // } // while(1); /**********************************************/ //蜂鸣器测试 /**********************************************/ // while(1) // { // BUZZER_OFF; // delay_ms(1000); // // BUZZER_ON; // delay_ms(1500); // } /**********************************************/ //协议测试 /**********************************************/ //OLED_Clear(); // OLED_ShowUnite(32,2,"通信中.."); // OLED_ShowUnite(0,4,"你很不错"); // delay_ms(1000); // addr=0xFFFF; // OLED_ShowNumHex(0,6,addr,8,16); //USB_Cheak_init(); //USB_transmit(); // bluetooth_uart_switch=1; // Test_Usb_Data(); // while(1); // SPI_FLASH_WriteWord(AUTHOR_POINT,AUTHOR_START); // addr= SPI_FLASH_ReadWord(AUTHOR_POINT); // OLED_ShowNum(0,0,addr,8,16); /**********************************************/ //ADC测试 /**********************************************/ // while(1) // { // OLED_Clear(); // batt_test=ADC_GetConversionValue(ADC1); // OLED_ShowNum(24,2,batt_test,8,16); // delay_ms(1000); // } // /**********************************************/ //定时器2测试 /**********************************************/ // GPIO_Configuration(); // GPIO_ResetBits(GPIOB,GPIO_Pin_6); // delay_ms(10); // GPIO_SetBits(GPIOB,GPIO_Pin_6); // g_WaitTimeOut = 0; // SetTimer(TIMER_TIMEOUT,1,Do_TimeOut,THREE_MIN); // while(g_WaitTimeOut == 0) // { // GPIO_ResetBits(GPIOB,GPIO_Pin_6); // } // KillTimer(TIMER_TIMEOUT); // GPIO_SetBits(GPIOB,GPIO_Pin_6); // g_WaitTimeOut = 0; // SetTimer(TIMER_TIMEOUT,10,Do_TimeOut,THREE_MIN); // while(g_WaitTimeOut == 0) // { // nChar =Read_RfidData(2,Rfid_Buff,0xff); // if(nChar ==5) // { // OLED_ShowUnite(32,80,Rfid_Buff); // ++rfidrow; // delay_ms(1000); // for(i=0;i<4;i++) // { // for(k =0;k<40;k++) // msDelay(500); // WritEDAta(CAIMA_START+8*rfidrow+4+i,Rfid_Buff[i]); // } // break; // } // } // KillTimer(TIMER_TIMEOUT); /**********************************************/ // OLED_ClearArea(0,4,128,6); // OLED_ShowUnite(24,4,"初始化完成"); // delay_ms(100); //bluetooth_uart_switch=0; // for(int iter=0;iter<3;iter++) // Power_Cheak(); //主循环测试 g_State=ST_IDLE; while(1) { switch (g_State) //g_State是一个全局函数 { case ST_IDLE: //#define ST_IDLE 0XFF ST_Idle(); //空闲时做状态检测,可改变g_State break; case ST_USB: //#define ST_USB 0XFD USB_transmit(); //USB传输 break; // case ST_KEY: // Key_Trismit(); //读钥匙的RFID,判断是否已经连接上 // break; case ST_LCDMENU: //#define ST_LCDMENU 0XFA 多选择菜单操作 Choose_MenuOp1(); break; default:break; } } }
int main(void){ // Init buffer for (int i=0; i<BUFFER_SIZE; i++){ Buffer[i] = 0; } //uIP unsigned int i; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; clock_init(2); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); init(); // Touch init ToushRes_t XY_Touch; Boolean Touch = FALSE; TouchScrInit(); // Init font GLCD_SetFont(&Terminal_9_12_6,0xFFFFFF,0x000000); // Init UART UART_init(UART_0,4,NORM); // Init Real Time Clock RTC_init(); // Init animations Animation_init(); // Init navigationBar navigationBar = initNavigationBar(); // Init pages mainLayout = initMainLayout(); learningLayout = initLearningLayout(); graphLayout = initGraphLayout(); devicesLayout = initDevicesLayout(); swapToLayout(0); // Initialize the ethernet device driver do{ GLCD_TextSetPos(0,0); } while(!tapdev_init()); GLCD_TextSetPos(0,0); // uIP web server // Initialize the uIP TCP/IP stack. uip_init(); uip_ipaddr(ipaddr, 192,168,0,100); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,0,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); // Initialize the HTTP server. httpd_init(); while(1){ if(TouchGet(&XY_Touch)) { // Check if the current Layout accepts the touch if (!Layout_dispatchTouch(currentLayout, XY_Touch.X, XY_Touch.Y)){ // Touch not accepted, pass it on to the navigationBar Layout_dispatchTouch(navigationBar, XY_Touch.X, XY_Touch.Y); } if (Touch == FALSE){ Touch = TRUE; } } else if(Touch) { USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK; Touch = FALSE; } // Data from UART0 UART_Check(Buffer); if (Buffer[0] != 'E'){ Parsing_parse(Buffer, &measurement); // Notify the graph updateGraphLayout(&measurement, currentLayout == graphLayout); checkDevices(&measurement, currentLayout); double vRMS = measurement.voltage; double iRMS = measurement.current; double pACT = measurement.P_power; double pREAC = measurement.Q_power; double pHAR = measurement.H_power; if (currentLayout == mainLayout){ GLCD_SetWindow(0, 0, 150, 70); GLCD_TextSetPos(0,0); GLCD_SetFont(&Terminal_9_12_6,0xFFFFFF,0x000000); GLCD_print(" Voltage: %f\r\n Current: %f\r\n Power: \t%f\r\n Reac: \t%f\r\n Har: \t%f", vRMS, iRMS, pACT, pREAC, pHAR); } } // HANDLE uIP uip_len = tapdev_read(uip_buf); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(uip_buf,uip_len); } } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { tapdev_send(uip_buf,uip_len); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(uip_buf,uip_len); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } }