u8 FING_u8HandShake(u8 * Copy_u8ChipAdd) { u8 Local_u8Count ; const u8 Local_u8HndShkArr[7]={0x01,0x00,0x04,0x17,0x00,0x00,0x1C}; u16 Local_u8RxData; TIM0_u8SetTime(500); while(TIM0_u8GetTimFlg()==0); FING_voidSendHeader(); for(Local_u8Count=3 ; Local_u8Count>=0;Local_u8Count--) { USART_Transmit(Copy_u8ChipAdd[Local_u8Count]) ; } for(Local_u8Count=0;Local_u8Count<7;Local_u8Count++) { USART_Transmit(Local_u8HndShkArr[Local_u8Count]); } for(Local_u8Count=0 ; Local_u8Count<10;Local_u8Count++) { USART_Receive(&Local_u8RxData); } TIM0_voiResetTimFlg(); TIM0_voiResetTimer(); return Local_u8RxData ; }
u8 FING_u8SetSysPra(u8 * Copy_u8ChipAdd,u8 *Copy_u8ParamArr) { u8 Local_u8Count; const u8 Local_u8SysPra[6]={0x01,0x00,0x03,0x0f,0x00,0x13}; u16 Local_u16RxData,Local_u16Param; FING_voidSendHeader(); for(Local_u8Count=3 ; Local_u8Count>=0;Local_u8Count--) { USART_Transmit(Copy_u8ChipAdd[Local_u8Count]) ; } for(Local_u8Count=0;Local_u8Count<6;Local_u8Count++) { USART_Transmit(Local_u8SysPra[Local_u8Count]); } for(Local_u8Count=0 ; Local_u8Count<10;Local_u8Count++) { USART_Receive(&Local_u16RxData); } for(Local_u8Count=0 ; Local_u8Count<16;Local_u8Count++) { USART_Receive(&Local_u16Param); Copy_u8ParamArr[Local_u8Count]=(u8)Local_u16Param ; } return Local_u16RxData ; }
//output a note off MIDI packet on the USART void output_packet_off(char pitch){ //note on USART_Transmit(0b10000000); //pitch USART_Transmit(pitch); //velocity USART_Transmit(0b01100100); }
void InitMessage(){ putstring("DDS generator driver v_"); putnum(10); USART_Transmit( '\n' ); USART_Transmit( '\r' ); putstring("Type help for command list"); USART_Transmit( '\n' ); USART_Transmit( '\r' ); }
//Main Function int main(void) { init_devices(); USART_Transmit('+'); USART_Transmit('+'); USART_Transmit('+'); while(1); }
// Print an array of chars instead of just one char. void serialPrint(uint8_t *StringOfCharacters, size_t len) { USART_Transmit_Start(); for (size_t i = 0; i < len; i++) { USART_Transmit(*StringOfCharacters++); } // TODO(cduck): Properly wait for end of transmission USART_Transmit(0xFF); while (!(SS_UCSRnA & (1 << SS_UDREn))) {} USART_Transmit_Stop(); }
void serial_puts(char* str) { USART_Transmit('\n'); USART_Transmit('\r'); int size = strlen(str); for(int i = 0; i < size; i++) { USART_Transmit(str[i]); } }
int main( void ) { char buffer[21] = {'\0'}; int i = 0; USART_Init ( calcUBRR() ); init_push_buttons(); lcd_init(); while(1){ switch(read_push_buttons()) { case '6': USART_Transmit('Y'); break; case '5': USART_Transmit('N'); break; case '4': Transmit_String("AHHHH!!!!"); break; case '3': Transmit_String("This"); break; case '2': Transmit_String("computer is"); break; case '1': Transmit_String("broken!"); break; } wait_ms(100); /* unsigned char new_letter = USART_Receive(); if(new_letter != 13) { buffer[i++] = new_letter; } USART_Transmit(new_letter); lprintf("%d, %c", i, new_letter); if(i == 20 || new_letter == 13) { if(new_letter == 13) { USART_Transmit(10); } i = 0; lprintf("%s", buffer); for(int j=0;j<20;j++) { buffer[j] = 0; } } */ } }
void USART_print(char * text){ uint8_t text_size=strlen(text); uint8_t i; for(i=0;i<text_size;i++){ USART_Transmit(text[i]); } USART_Transmit(0x0D); USART_Transmit(0x0A); }
void sendMessage(char *number, char *message, char success){ usartPrintString("at+cmgs=\""); usartPrintString (number); usartPrintString ("\"\r"); usartPrintString(message); if (success == 1){ usartPrintString(" success"); } else if (success == 2){ usartPrintString(" failure"); } USART_Transmit(26); USART_Transmit(ENTER); }
int main(void) { unsigned char c; /* ----------------- USART Initialization --------------------*/ // BAUD Rate = 9600, F_CPU = 1000000UL, BAUD = F_CPU / (speed * (UBRR+1)) // speed = 16 for standard more (U2X = 0) and speed = 8 for double speed mode (U2X = 1) // So, We can choose UBRR = 6 for standard more (U2X = 0) // or UBRR = 12 for double speed mode (U2X = 1) // Since double speed mode (U2X = 1) provides lower error, we are going // to use it for this configuration. Please check datasheet for more detail // // Set BAUD rate register to generate our desired BAUD 9600 (UBRR = 12) // Enable double speed mode (U2X = 1) // Disable Rx, Tx complete INT, Enable Rx, Tx module // USART as asynchronous mode, No Parity (UPM1:0 = 0), One STOP bit (USBS = 0) // Char Size 8 bit (UCSZ2:0 = 3) /* ------------------------------------------------------------*/ UBRRH = 0; UBRRL = 12; UCSRA |= 0x02; UCSRB |= 0x18; UCSRC |= 0x86; while (1) { // wait until a data receive from PC c = USART_Receive(); // Send the received data back to PC USART_Transmit(c); } }
void usartPrintString(char *buffer){ int count = 0; while (buffer[count] != '\0'){ USART_Transmit(buffer[count]); count++; } }
char SPI_sendchar(char cData) { SPI_MasterTransmit(cData); USART_Transmit(SPDR); return SPDR; }
/*==================================================================== 関数名: _rsputc 機能: char型文字を1文字コンソール出力し、0を返します。 ====================================================================*/ int _rsputc(char c) { //使用するマイコンに合わせて記述します // uart_putc(c); USART_Transmit((unsigned char)c); return 0; }
uint8_t keypad_4keys(void) { //PORTA=0x00; PORTC = 0x00;//&=~(1<<PC7); PORTB=0xFF; //set all the input to one _nkey_=check_key_4keys(); if(_nkey_ == d_nkey) { USART_Transmit(9); } if (_nkey_ == 0xFF) { _nkey_ = 98, _okey_ = 99;} // this differntiates btw a key gap , sends oxff when a key is nt pressed if(_nkey_ == _okey_) { _nkey_ = 0xFF;} if ((_nkey_!= 0xFF)&(_nkey_!=98)) { //USART_Transmit(keymap[_nkey_]); // a variable should hold this value _okey_=_nkey_; return (_nkey_); //d_nkey = _nkey_; } return 0xFF; }
uint8_t Decrypt_Data(unsigned char Data) { // @00 means broadcast to ALL CAN ID's unsigned char Output_Command[MAX_COMMAND_SIZE] = {'@', '0', '0', '!', 'G', ' '}; unsigned char dataIndexSize; #ifdef WATCHDOG_ENABLED wdt_reset(); #endif /* switch(Data) { case 71: Output_Command[5] = '1'; Output_Command[6] = '0'; Output_Command[7] = '0'; Output_Command[8] = '0'; Output_Command[9] = '\r'; dataIndexSize = 10; break; } */ dataIndexSize = (sizeof(Output_Command) / sizeof(char)); USART_Transmit(Output_Command, dataIndexSize); return 0; }
void pi_shutdown_task(void){ if(!(PISTARTPORT & (1<<PISTART))) return; // pi ausgeschaltet? dann zurück! //pi herunterfahren if(PIPORT & (1<<PISHUTDOWN)){ // pi hat shutdown signal bekommen: ist er schon aus? if(PIPIN & (1<<PIACTIVE)){ //noch an... da machen wir nix. return; } //hier isser schon aus. PIPORT &= ~(1<<PISHUTDOWN); _delay_ms(10000);//sicherheit PISTARTPORT &= ~(1<<PISTART);// und abschalten _delay_ms(10000);//sicherheit }else{ // pi ist an - soll jetzt abgeschaltet werden if(!(PIPIN & (1<<PIREADY))){ uint8_t x = 0; do{ USART_Transmit(0xFF); // MFD ausgeschaltet. Der Pi möge seine Arbeit einstellen. _delay_ms(200); x++; if(x>50) break; }while(PIPIN & (1<<PIREADY)); } PIPORT |= (1<<PISHUTDOWN); } }
void Transmit_String(char *str) { for(int i = 0; i < strlen(str); i++) { USART_Transmit(str[i]); } }
void Console_help( char ch){ switch (helpcounter) { case 0: if (ch=='h') helpcounter++; else helpcounter=0; break; case 1: if (ch=='e') helpcounter++; else helpcounter=0; break; case 2: if (ch=='l') helpcounter++; else helpcounter=0; break; case 3: if (ch=='p') helpcounter++; else helpcounter=0; break; } if (helpcounter ==4){ putstring("help reset minXXX maxXXX freqXXXXXXXX"); USART_Transmit( '\n' ); USART_Transmit( '\r' ); helpcounter=0; } }
void USART_Transmit_String(unsigned char * transmitString ) { int i; for (i=0; transmitString[i] != NULL; i++) { USART_Transmit(transmitString[i]); } }
//for debug void SerialPort::write(){ unsigned char myMessage[]="hello world\r\n"; unsigned char* message; message = myMessage; unsigned char c; while( (c = *(message++)) != '\0' ){ USART_Transmit(c ); } message = myMessage; }
void Service_ReadEEPROMData(uint8_t command_type, uint8_t command_size, char *command) { char buffer[101]; char buffer_coded[101]; int16_t crc; int16_t crc_data; uint16_t offset = (command[1]<<8) + command[0]; //odczyt offsetu uint8_t len = command[2]; //odczyt dlugosci if (len>100) len = 100; crc = GetCRC(command,command_size-2); //wygenerowanie CRC crc_data = (command[command_size-1]<<8) + command[command_size-2]; //odczyt CRC if (crc!=crc_data) { Service_send_ERROR("CRC Error"); return; } //odczyt paczki z eepromu GetBlockEE((char *)(buffer+2), offset,len); buffer[0] = command[0]; //offset (ten sam, ktory przyszedl w zadaniu) buffer[1] = command[1]; //obliczanie crc crc = GetCRC(buffer,len+2); memcpy(buffer+len+2,&crc,2); //zakodowanie informacji base64_encode((unsigned char*)buffer, len+4, (unsigned char*)buffer_coded); len = strlen((char *)buffer_coded); //odeslanie paczki przez uart USART_Transmit(UART_CMD_EEPROM_DATA); //przesylamy dane for (int i=0;i<len;i++) USART_Transmit(buffer_coded[i]); USART_Transmit(UART_EOT); }
void Service_Recieve(uint8_t command_type, uint8_t command_size, char *command) { char command_decoded[101]; uint8_t new_size; switch(command_type) { case UART_CMD_EEPROM_DATA: //write EEPROM block new_size = base64_decode((unsigned char*)command, command_size, (unsigned char*)command_decoded); Service_SaveEEPROMData(command_type,new_size,command_decoded); break; case UART_CMD_EEPROM_REQ: //read EEPROM block new_size = base64_decode((unsigned char*)command, command_size, (unsigned char*)command_decoded); Service_ReadEEPROMData(command_type,new_size,command_decoded); break; case UART_CMD_EEPROM_END: //after all eeprom packets //ReadConfigFromEEPROM(); SOFT_RESET; break; case UART_CMD_PING: //ping USART_Transmit(UART_CMD_PING); USART_Transmit(UART_EOT); break; case UART_CMD_VERSION: //return version number Service_VersionInfo(); break; case UART_CMD_DEFAULTS: //load default values to EEPROM if ((command[0]=='E')&&(command[1]=='F')&&(command[2]=='A')&&(command[3]=='U')&&(command[4]=='L')&&(command[5]=='T')&&(command[6]=='S')) { SetDefaults(); SOFT_RESET; } break; } }
void check_task_completion() { USART_Transmit('%'); USART_Transmit(bot_id); switch(bot_id) { case 'A': done[0]=1;break; case 'B': done[1]=1;break; case 'C': done[2]=1;break; case 'D': done[3]=1;break; } stop(); for(k=0;k<1000;k++) { lcd_print(1,9,k,4); if(neigh == 0) { switch(bot_id) { case 'A': if(done[1]==1) neigh=1; break; case 'B': if(done[2]==1) neigh=1; break; case 'C': if(done[3]==1) neigh=1; break; case 'D': if(done[0]==1) neigh=1; break; } } else { break; } } }
void main(void) { int AX; int AY; twi_init(); delay_nms(50); MPU_6050_init(); delay_nms(500); Usart_init(); //hc05_init(); while(1) { delay_nms(50000); AX=Get_data(ACCEL_XOUT_H)/187.62; AY=Get_data(ACCEL_YOUT_H)/187.62; if(AY<86) { USART_Transmit('1'); //UCSRB=0X90; //关发送使能 } else { USART_Transmit('0'); } /*else { sent('2'); //UCSRB=0X90; //关发送使能 if(AX<45 || AY<45) { UCSRB=0X98; //打开发送使能 } }*/ } }
u8 FING_u8SetAdd(u8 * Copy_u8ChipOldAdd , u8 * Copy_u8ChipNewAdd) { u8 Local_u8Count,Local_u8CastChkSum ; const u8 Local_u8HndShkArr[4]={0x01,0x00,0x07,0x15}; u16 Local_u16RxData ,Local_u16CastChkSum ; u64 Local_u64ChekSum=0; FING_voidSendHeader(); for(Local_u8Count=3 ; Local_u8Count>=0;Local_u8Count++) { USART_Transmit(Copy_u8ChipOldAdd[Local_u8Count]) ; } for(Local_u8Count=0;Local_u8Count<4;Local_u8Count++) { USART_Transmit(Local_u8HndShkArr[Local_u8Count]); Local_u64ChekSum+=Local_u8HndShkArr[Local_u8Count]; } for(Local_u8Count=3 ; Local_u8Count>=0;Local_u8Count++) { USART_Transmit(Copy_u8ChipNewAdd[Local_u8Count]); Local_u64ChekSum+=Copy_u8ChipNewAdd[Local_u8Count]; } //Cjeck sum calculations Local_u16CastChkSum=(u16)Local_u64ChekSum ; Local_u8CastChkSum=(u8)Local_u64ChekSum ; USART_Transmit(Local_u8CastChkSum); Local_u16CastChkSum>>=8; USART_Transmit(Local_u16CastChkSum); for(Local_u8Count=0 ; Local_u8Count<10;Local_u8Count++) { USART_Receive(&Local_u16RxData); } return Local_u16RxData ; }
void send_wave() { uint16_t i; uint16_t cs; cs = 0; for(i=0; i < WAVE_LENGTH; i += 2) { thexw(wave[i]); thexw(wave[i+1]); cs ^= wave[i]; cs ^= wave[i+1]; } thexw(cs ^ 0x1234); USART_Transmit('\n'); }
int main( void ) //Главная функция { USART_Init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) ); //Скорость соединения 19200 бит/с for(;;) //Вечный цикл { USART_Transmit( USART_Receive() ); //Отправка принятого символа назад } }
//·µ»Ø1³É¹¦£¬·µ»Ø0ʧ°Ü uchar OV7670_init(void) { uint i=0; InitSCCB();//io init.. //OV2640_JpegInit(1); RCC->APB2ENR|=1<<4;//ÏÈʹÄÜÍâÉèPORTCʱÖÓ //PORTC0~13ÍÆÍìÊä³ö GPIOC->CRL = 0x88888888; GPIOC->ODR |= 0x00FF; Exit_Init(GPIOB, GPIO_Pin_8, GPIO_Mode_IPU, EXTI_Trigger_Rising, 2, 3); //VSYNC Exit_Init(GPIOB, GPIO_Pin_15, GPIO_Mode_IPU, EXTI_Trigger_Falling, 2, 4);//PICLK GpioInit(GPIOB, GPIO_Pin_14, GPIO_Mode_IPU, 0); //HREF return;//´ÓÕâÀï·µ»Ø temp=0x80; if(0==wrOV7670Reg(0x12, temp)) //Reset SCCB { return 0 ; } while(0) { rdOV7670Reg(0x1C, &temp); USART_Transmit(temp); Delay_nMS(100); } Delay_nMS(10); for(i=0;i<CHANGE_REG_NUM;i++) { if( 0 == wrOV7670Reg (change_reg[i][0],change_reg[i][1]) ) { return 0; } } return 0x01; //ok }
void initialize( void ) { CPU_PRESCALE(0); USART_Init(BAUD_RATE); USART_Transmit('\f'); // Send form feed to clear the terminal. USART_SendString("WunderBoard initializing...\r\n"); USART_SendString("\tSetting ADC prescaler and disabling free running mode...\r\n"); SetupADC(ADC_PRESCALER_32, FALSE); USART_SendString("\tEnabling ADC...\r\n"); ADCEnable(); USART_SendString("\tSetting ADC reference to Vcc...\r\n"); ADCSetReference(ADC_REF_VCC); // Configure IO // USART_SendString("\tConfiguring IO...\r\n"); //DDRx corresponds to PORTx/PINx, dependng on direction of data flow -- PORT for output, PIN for input DDRA = 0x00; // Buttons and switches DDRB = 0xE7; // Red enable, green enable and audio out DDRC = 0xff; // Discrete LEDs DDRE = 0x47; // LED Column DDRF = 0x00; // Accelerometer // Disable pullups and set outputs low // PORTA = 0x00; PORTB = 0x01; PORTC = 0x81; PORTE = 0x00; PORTF = 0x00; //Set OC1A to toggle TCCR1A = 0b01000000; // Clk/64 and CTC mode TCCR1B = 0b00001011; OCR1A = 24; USART_SendString("\tSetting SPI\r\n"); //Set the SPI bus appropriately to use the LED array SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0); }