/********************************************************************* * * main() * *********************************************************************/ void main() { char rxdata; /****************************************************************** * * Place your code here. ******************************************************************/ int cnt; cnt = 0; InitUSART(); printf("this is example for printf from library\r\n"); do { #ifndef USE_UART_INTR if (UART_GetChar(USART2, &rxdata) == 0) { } else { outbyte(rxdata); if(rxdata==0x0d) outbyte(0x0a); } #endif cnt++; } while (1); }
void vDebugTask (void *pvParameters) { int Res; char strMsgDebug[64]; #ifdef DEBUG_OUTPUT_USART InitUSART(UART_DBG, DBG_BAUDRATE); InitDMA(UART_DBG); #endif while(1) { LED_TOGGLE; Res = HandlerCompass(strMsgDebug); strcat(strMsgDebug, "\r\n"); if(!(Res)) { #ifdef DEBUG_OUTPUT_USART USART_Write(UART_DBG, strMsgDebug, strlen(strMsgDebug)); #endif #ifdef DEBUG_OUTPUT_USB if(bDeviceState == CONFIGURED) { CDC_Send_DATA ((unsigned char *)strMsgDebug, strlen(strMsgDebug)); NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn); } #endif } _delay_ms(1000); } }
void InitAll(void) { RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; //Clock port GPIOB->CRL &= ~(GPIO_CRL_CNF0 | GPIO_CRL_CNF1); GPIOB->CRL |= (GPIO_CRL_MODE0_0 | GPIO_CRL_MODE1_0); InitRCC(); //Разрешаем прерывание если кварц плохо init_bad_clock_inter(); delay_timer_ms_init(); lcd_init(); InitUSART(9600); InitUSART2(9600); usart_interrupt_init(); usart2_interrupt_init(); init_keyboard(); //timer2_init(10); InitSim900Port(); InitBuz(); InitMenu(); Init_Slow_Timer(); }
/****************************************************************************** * Initial subroutine * * This subroutine performs all initializations of variables and registers. * It enables TMR1, initializes SPI, and USART, sets up low and high * priority interrupts, sets up the LCD, and configures all I/O pins. * * Inputs: None * Outputs: None ******************************************************************************/ void Initial(void) { char i; OSCCON = 0b01100100; //Oscillator control register, see data // sheet, pp.43 - 45 ODCON1 = 0x00; //Output Drain register, see data sheet // pp. 167 //Set up all I/O ports InitIO(); //Clear Holding register for incoming USART data for (i = 0; i < 10; i++) { Hold[i] = 0; } //Configuring Interrupts RCONbits.IPEN = 1; //Enable priority levels INTCON2bits.TMR0IP = 0; //Assign low priority to TMR0 interrupt INTCONbits.TMR0IE = 1; //Enable TMR0 interrupts IPR1bits.ADIP = 0; //Assign low priority to AD converter PIE1bits.ADIE = 1; //Enable AD interrupts IPR1bits.RC1IP = 1; //Assign high priority to USART PIE1bits.RC1IE = 1; //Enable USART interrupts IPR1bits.TMR1IP = 0; PIE1bits.TMR1IE = 1; INTCONbits.GIEL = 1; //Enable low-priority interrupts to CPU INTCONbits.GIEH = 1; //Enable all interrupts //Set up Timer0 T0CON = 0b00000101; //16-bit, Fosc/4, prescaler 64 TMR0L = TMRL; //Load Timer0 with correct values TMR0H = TMRH; // for 1 second //Set up Timer1 T1CON = 0b00000010; TMR1H = 0; TMR1L = 0; WakeXBEE(); //Wake XBee from sleep Delay10KTCYx(10); //Set up the A/D converter ADCON0 = 0b00001001; //Set up to read temp data on RA2 ADCON1 = 0b00000000; //VDD = 3.3V and VSS = GND ADCON2 = 0b00100001; //Left Just., TAD = 8, FOSC/8 ANCON0 = 0b00000100; //Set AN2 as analog input //Set up the USART InitUSART(); //Initialize the USART on USART1 //Set up SPI InitSPI1(); //Initialize the SPI on MSSP1 T0CONbits.TMR0ON = 1; //Turn on TMR0 }
//u08 pinStatus = 0; //volatile u08 pinStatus; int main(void) { LED_DDR = 1<<LED1; InitExternalInterrupts(); InitUSART(); buffer[0] = 48; buffer[1] = 49; buffer[2] = 50; buffer[3] = 51; pinStatus = 0; count = 0; u08 tempo = 0; #ifdef _DEBUG u08 var1 = 0; u08 var2 = 0xFF; #endif sei(); // Включаем прерывания while (1) { //DebugOutput(); if (((pinStatus & (SENS1_SB|SENS2_SB)) == 0) && (pinStatusPrev == 0) && (pinStatus & (DIR1|DIR2))) { pinStatusPrev = pinStatus; pinStatus = 0; } if ((pinStatus & (SENS1_SB|SENS2_SB)) == SENS12_SB) { //ReadSensors(); //SendByte(pinStatus); if ((pinStatus & (DIR1|DIR2)) == (pinStatusPrev & (DIR1|DIR2))) { if ((pinStatus & (DIR1|DIR2)) == DIR1) count++; else if ((pinStatus & (DIR1|DIR2)) == DIR2) count--; // Отправляем результат SendByte(count); //pinStatus &= ~(SENS1_SB|SENS2_SB); // } pinStatusPrev = 0; } } }
int main (int argc, char *argv[]) { DDRB = 0xFF; cli(); //Init usart InitUSART(); //Enable Global Interrupts. Sets SREG Interrupt bit. sei(); //Intitialize LCD. Set Blinking cursor. lcd_cursor(); //_delay_ms(10000); while(1){ holder = getChar(); if (holder != '\0') char_write(holder); } return 0; //should never get here. }
int main(void) { unsigned char Arg0; //if DDRX,X=1 PORTX,X=OUT DDRA=0xbf; PORTA = 0xff;//0xc0 prov DDRB=1; PORTB = 0xff; DDRC=0xd4; PORTC =0xff; DDRD=0x12; PORTD=0xff; //INIT TWI; TWBR=0x7f;//F TWI TCCR1B=0xc2;//0.5mkc TIMSK=TIMSK | 0x4;//enable Int overlowT1 TWAR=4; TWCR =(1<<TWEA)|(1<<TWEN); ReadKn(); CtStart=200; while(CtStart--) _WDR(); ReadKn(); _SEI(); RegimTime &=0xc0; CtUst=CtUst0; for(Arg0=1;Arg0<=10;++Arg0) RomReceive[Arg0]=0; CtEeprom=1; RegimWork=0; CtErrorLink=CtErrorLink0; InitUSART(); Gashenie=0;//Gashenie=off; UNom=ReadEeprom(1); if(UNom>260) UNom=220; if(UNom<90) UNom=220; UMin=80;//95;//95B CtReceiveUsart=0; Gashenie =4;//vozb=on //WORK while(1) { _WDR(); if(!CtTransmitUsart) { if(NumberLinkUsart) --NumberLinkUsart; else NumberLinkUsart=2; CtReceiveUsart=0; LoadRegTransmitUsart(NumberLinkUsart); CtTransmitUsart=15; RCHReceive=0xff; RCLReceive=0xff; } if(RegS & 2) RegimWork &=0xfe; else if(RegSWork & 0x40) { if(RegimWork & 1) RegimWork &=0xfe; else RegimWork |=1; RegSWork &=0xbf; } if((RomReceive[1]& 0xe)&&(!(RomReceive[1]& 0x10))) PORTA &=0xdf; else PORTA |=0x20; if(RegS & 2) PORTA &=0x7f; else PORTA |=0x80; if(RegS & 4) PORTC &=0xef; else PORTC |=0x10; if(RegS & 8) PORTC &=0xfb; else PORTC |=0x4; ChangeUNom(); IndicatorLed(); ++TestLink; _WDR(); if(EndAd) { EndAd=0; } if(EnableLoad) { LoadRegTransmit(); LoadControlSum(); } if(TWCR & 0x80) { ReceiveTransmitSlave(); // ++TestTransmit; } if(!CtErrorLink)//ErrorLink; { //INIT TWI; TWBR=0;//F TWI TWAR=0; TWCR =0; TWSR=0xf8; CtStart=50; while(CtStart--) _WDR(); TWBR=0x7f;//F TWI TWAR=4; TWCR =(1<<TWEA)|(1<<TWEN); CtErrorLink=CtErrorLink0; CtStart=200; while(CtStart--) _WDR(); } ReadKn(); } }
// ============================================================================ int main( void ) { int ch = 0; uint32_t ccount = 0; uint32_t lastTick; int pwm; SystemCoreClockUpdate(); SysTick_Config( SystemCoreClock / HB_HZ); // Enable peripheral clocks // TODO: Remove GPIOCEN when moving to the smaller CPU RCC->AHBENR |= (RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN | RCC_AHBENR_GPIOCEN); #ifdef USE_USART InitUSART(400); #endif // USE_USART InitLED(); InitServo(); configButtons(); while( 1 ) { if ( curTick > (HB_HZ) ) { curTick -= (HB_HZ); // Once per second processing... } if ( curTick != lastTick ) { lastTick = curTick; // On each timer tick move the turnout slightly closer to the new position for ( int idx=0; idx<SERVO_COUNT; ++idx ) { if ( servo[idx].currentPos < servo[idx].targetPos ) { servo[idx].currentPos += SERVO_DELTA; if ( servo[idx].currentPos > servo[idx].targetPos ) { servo[idx].currentPos = servo[idx].targetPos; } } else if ( servo[idx].currentPos > servo[idx].targetPos ) { servo[idx].currentPos -= SERVO_DELTA; if ( servo[idx].currentPos < servo[idx].targetPos ) { servo[idx].currentPos = servo[idx].targetPos; } } } TIM1->CCR1 = servo[SERVO1].currentPos; TIM1->CCR2 = servo[SERVO2].currentPos; TIM1->CCR3 = servo[SERVO3].currentPos; TIM1->CCR4 = servo[SERVO4].currentPos; btnCheck(); } #ifdef USE_USART if ( usartTxEmpty() ) { usartWriteByte(ch+33); ++ch; ch &= 0x3F; } #endif // USE_USART } }