//------------------------------------------------------------------------------ // === Initialize Function === //------------------------------------------------------------------------------ void Init_Main(void) { Disable_ISR(); // 전체인터럽트 사용금지 Init_Timer(); // 초기화_타이머0/1/2/3 Init_Uart(0,1000000); // 초기화_시리얼통신0 Init_Uart(1,57600); // 초기화_시리얼통신1 Init_ADC(); //Lcd_Init(); //sbi(DDRE,4); Enable_ISR(); // 전체인터럽트 사용허가 }
int main(void) { Init_ADC(); Init_Uart(0,9600); while(1) { // Uart_Putch(0,2); _delay_ms(500); if( Instruction[0] == 1) { Instruction[0] = 0; while(1) { //Uart_Putch(0,1); Read_ADC(0); Dis = (( (11.65/(( ADC/204.8) - 0.147 )) - 0.42 ) * 10)-4; if(Dis < 65) { Uart_Putch(0,SIG_To1[0]); ////SIG TO 1 break; } } } } return 0; }
void Main_Init(void) { Disable_ISR(); // 전체인터럽트 사용금지 Init_Ext_Interrupt(INT0); // 초기화_외부인터럽트0/1/2/3/4/5/6/7 Init_Ext_Interrupt(INT1); // 초기화_외부인터럽트0/1/2/3/4/5/6/7 Init_Uart(UART0,9600); // 초기화_시리얼통신0 Init_Uart(UART1,9600); // 초기화_시리얼통신1 Init_ADC(); // 초기화_ADC Init_Timer(); init_lcd(); Motor_Init(); Enable_ISR(); // 전체인터럽트 사용허가 }
//------------------------------------------------------------------------------ // === Initialize Function === //------------------------------------------------------------------------------ void Init_Main(void) { Disable_ISR(); // 전체인터럽트 사용금지 //Init_Timer(); // 초기화_타이머0/1/2/3 Init_Uart(0,57600); // 초기화_시리얼통신0 //Init_Uart(1,57600); // 초기화_시리얼통신1 Enable_ISR(); // 전체인터럽트 사용허가 }
void Main_Init(void) { Disable_ISR(); // 전체인터럽트 사용금지 //Init_IO(); // 초기화_입출력포트 Init_Ext_Interrupt(INT0); // 초기화_외부인터럽트0/1/2/3/4/5/6/7 Init_Ext_Interrupt(INT1); // 초기화_외부인터럽트0/1/2/3/4/5/6/7 //Init_Timer(); // 초기화_타이머0/1/2/3 Init_Uart(UART0,9600); // 초기화_시리얼통신0 Init_Uart(UART1,9600); // 초기화_시리얼통신1 Init_ADC(); // 초기화_ADC //Init_SPI(MASTER); // 초기화_SPI통신 //Init_TWI(MASTER); // 초기화_TWI통신 //Uart_Getch(1); Motor_Init(); Enable_ISR(); // 전체인터럽트 사용허가 }
//------------------------------------------------------------------------------ // === Initialize Function === //------------------------------------------------------------------------------ void Init_Main(void) { Disable_ISR(); // 전체인터럽트 사용금지 Init_Timer(); // 초기화_타이머0/1/2/3 Init_Uart(0,9600); // 초기화_시리얼통신0 Init_Uart(1,9600); // 초기화_시리얼통신1 sbi(DDRG,0); // 1st_step sbi(DDRG,1); // 1st_dir sbi(DDRG,3); // 2nd_step sbi(DDRG,4); // 2nd_dir cbi(DDRC,0); // 1st_hall sensor cbi(DDRC,1); // 2nd_hall sensor Init_packet((PARTNER_PACKET*)&pPacket, (UART_CONTEXT*)&pContext ); Enable_ISR(); // 전체인터럽트 사용허가 }
/************************************************************** * Name : Init_LIN_SLV1 * Description : Sets variable that controls state machine LIN as IDLE. * Initializes Interruption and UART * Parameters : void * Return : void * Critical/explanation : [yes / No] **************************************************************/ void Init_LIN_SLV1(void) { option_machine = IDLE; LIN_init_Intrruptions(); Init_Uart(); }
int main() { DDRD |= (1 << PORTD6); uint16_t flexi; uint16_t analogValue; Init_Uart(); initPWM(); initADC(); printString("***Transmission begin***\n\r"); while(1) { analogValue = ReadACD(0); printString("Analog is: "); delay_ms(500); serialPrintDec(analogValue); printString("\n\r "); delay_ms(500); flexi = ((analogValue * 0.1759530792)-121);// 860-690 if(flexi < 1) { SetPWMOutput(0); } if(flexi >= 1 && flexi < 15) { SetPWMOutput(150); delay_ms(2000); SetPWMOutput(0); delay_ms(1000); } if(flexi >= 15 && flexi < 30) { SetPWMOutput(120); delay_ms(2000); SetPWMOutput(0); delay_ms(1000); } if(flexi >= 30) { SetPWMOutput(240); delay_ms(2000); SetPWMOutput(0); delay_ms(1000); } printString("Flexi is: "); delay_ms(500); serialPrintDec(flexi); printString("\n\r "); delay_ms(500); } }
void main( void ) { unsigned int ucState=0xffff; unsigned char test[10]; memset(test,'\0',10); int i=0; halBoardInit(); hal430SetSystemClock(); halButtonsInit(); Init_Uart(115200); Init_Lcd(); Msp430_ADC12_Init(); Write_NByte((unsigned char *)eeprom,10,0); Read_NByte_Randomaddress(test,10,0); printf("main %s\r\n",test); while(1) { if(flag==1) { //WDTCTL = WDTPW + WDTNMI + WDTTMSEL + WDTSSEL + WDTCNTCL; // Start watchdog timer //IE1 |= WDTIE; // Enable WDT interrupt printf("we are in active state\r\n"); //这里写自己的程序,把程序做在一个有限的循环里,这样做完之后就可以自动结束并关机。 for(i=0;i<1000;i++){ ucState = halButtonsPressed(); if(ucState!=0xffff) { i=0; send_wave(); hal_buzzer(2); Get_Power(); //printf("%x is pressed\r\n",ucState); switch(ucState) { case BUTTON_MATL: printf("matl is pressed\r\n"); break; case BUTTON_HARD: printf("hard is pressed\r\n"); break; case BUTTON_DIREC: printf("direc is pressed\r\n"); break; case BUTTON_TIMES: printf("times is pressed\r\n"); break; case BUTTON_SAVE: printf("save is pressed\r\n"); break; case BUTTON_UP: printf("up is pressed\r\n"); break; case BUTTON_DEL: printf("del is pressed\r\n"); break; case BUTTON_AVE: printf("ave is pressed\r\n"); break; case BUTTON_LEFT: printf("left is pressed\r\n"); break; case BUTTON_MENU: printf("menu is pressed\r\n"); break; case BUTTON_RIGHT: printf("right is pressed\r\n"); break; case BUTTON_BACKLIGHT: printf("backlight is pressed\r\n"); break; case BUTTON_ESC: printf("esc is pressed\r\n"); break; case BUTTON_DOWN: printf("down is pressed\r\n"); break; case BUTTON_ENTER: printf("enter is pressed\r\n"); break; default: break; } } //LPM3; Delay(100); } //如需定时,上边这个LPM3要被包括在那个有循环的循环体中,这样才能实现类似便携式仪表5分钟自动关机的效果。如果不使用定时也可以不要LPM3这句话。 //WDTCTL = WDTPW + WDTHOLD + WDTNMI; // Stop watchdog timer flag=0; } else { //如果周边设备在关机时有需要复位的或是关闭的在这里处理 printf("we are in power off state\r\n"); } hal_buzzer(0); printf("we going to LPM4\r\n"); LPM4; } }