unsigned char write_spi(unsigned char data) { unsigned char i; unsigned char Temp=0x00; unsigned char SDI; for (i = 0; i < 8; i++) { CLK(1); ms_delay(); if (data&0x80) { MOSI(1); } else { MOSI(0); } data <<= 1; CLK(0); ms_delay(); ms_delay(); SDI = MISO(); Temp<<=1; if(SDI) { Temp++; } CLK(1); } return Temp; }
void lcd_scroll_disp(unsigned char *scroll_data, unsigned char position) { unsigned char i, j, *d; position += 0x80; d = scroll_data; comdr(position); for(j = 15; j>0 ; j--) { position = j + 0x80; comdr(position); ms_delay(5); for(i=0; *d!='\0'; i++) { datar(*d); ms_delay(1); d++; } d = scroll_data++; rtc_get_time(); //-------------- lcd_line4_disp(&Uc_real_time[0],12); //------------------ ms_delay(9000); clrscr(); } }
int i2c_beginTransmission(I2C_TypeDef* I2Cx,uint8_t device_address,uint8_t operation){ int timeout; uint32_t flag1=0,flag2=0; device_address= device_address << 1; I2C_GenerateSTART(I2Cx, ENABLE); //flag1 = I2Cx->SR1; //flag2 = I2Cx->SR2; //usart_printf(USARTx,"Flag1:%04x \n\r Flag2:%04x\n\r",flag1,flag2); //usart_printf(USARTx,"Sending start bit to address:%02x\n\r",device_address); /* Test on I2Cx EV5, Start trnsmitted successfully and clear it */ timeout = I2C_TIMEOUT_MAX; /* Initialize timeout value */ while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT)) { /* If the timeout delay is exeeded, exit with error code */ ms_delay(100); if ((timeout--) == 0){ flag1 = I2Cx->SR1; flag2 = I2Cx->SR2; usart_printf(USARTx,"Flag1:%04x \n\r Flag2:%04x\n\r",flag1,flag2); usart_printf(USARTx,"Timeout reached while checking the EV5 event\n\r"); return -1; }} timeout = I2C_TIMEOUT_MAX; if (!operation){ I2C_Send7bitAddress(I2Cx, device_address, I2C_Direction_Transmitter); //timeout = I2C_TIMEOUT_MAX; while (!I2C_CheckEvent(I2Cx,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) { /* If the timeout delay is exeeded, exit with error code */ ms_delay(100); if ((timeout--) == 0){ flag1 = I2Cx->SR1; flag2 = I2Cx->SR2; usart_printf(USARTx,"Flag1:%04x \n\r Flag2:%04x\n\r",flag1,flag2); usart_printf(USARTx,"Timeout reached while verifying transmitter selection\n\r"); return -2; }} //usart_printf(USARTx,"Transmitter mode selected. Send the address\n\r"); } else{ I2C_Send7bitAddress(I2Cx, device_address, I2C_Direction_Receiver); while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED)) { /* If the timeout delay is exeeded, exit with error code*/ ms_delay(100); if ((timeout--) == 0){ flag1 = I2Cx->SR1; flag2 = I2Cx->SR2; usart_printf(USARTx,"Flag1:%04x \n\r Flag2:%04x\n\r",flag1,flag2); usart_printf(USARTx,"Timeout reached while recieving acknowledge on revice mode \n\r"); return -2; } }} //usart_printf(USARTx,"Success with stage one. Going to senddata\n\r"); return 0; }
void lcd_init() { /* reset LCD, reset pin is connected to p1.9 */ writeb(0, P1_BITBANG+9*4); ms_delay(50); writeb(1, P1_BITBANG+9*4); ms_delay(50); hy32b_write_reg(0x0000, 0x0001); hy32b_write_reg(0x0007, 0x0023); hy32b_write_reg(0x0010, 0x0000); ms_delay(50); hy32b_write_reg(0x0007, 0x0033); hy32b_write_reg(0x0011, 0x6070); hy32b_write_reg(0x0002, 0x0600); hy32b_write_reg(0x0003, 0x0804); hy32b_write_reg(0x000C, 0x0000); hy32b_write_reg(0x000D, 0x0808); hy32b_write_reg(0x000E, 0x2900); hy32b_write_reg(0x001E, 0x00B8); hy32b_write_reg(0x0001, 0x2B3F); hy32b_write_reg(0x0010, 0x0000); hy32b_write_reg(0x0005, 0x0000); hy32b_write_reg(0x0006, 0x0000); hy32b_write_reg(0x0016, 0xEF1C); hy32b_write_reg(0x0017, 0x0003); hy32b_write_reg(0x0007, 0x0233); hy32b_write_reg(0x000B, 0x0000); hy32b_write_reg(0x000F, 0x0000); hy32b_write_reg(0x0041, 0x0000); hy32b_write_reg(0x0042, 0x0000); hy32b_write_reg(0x0048, 0x0000); hy32b_write_reg(0x0049, 0x013F); hy32b_write_reg(0x004A, 0x0000); hy32b_write_reg(0x004B, 0x0000); hy32b_write_reg(0x0044, 0xEF00); /* 240 */ hy32b_write_reg(0x0045, 0x0000); /* starts at 0 */ hy32b_write_reg(0x0046, 0x013F);/* ends at 319 */ hy32b_write_reg(0x0030, 0x0707); hy32b_write_reg(0x0031, 0x0204); hy32b_write_reg(0x0032, 0x0204); hy32b_write_reg(0x0033, 0x0502); hy32b_write_reg(0x0034, 0x0507); hy32b_write_reg(0x0035, 0x0204); hy32b_write_reg(0x0036, 0x0204); hy32b_write_reg(0x0037, 0x0502); hy32b_write_reg(0x003A, 0x0302); hy32b_write_reg(0x003B, 0x0302); hy32b_write_reg(0x0023, 0x0000); hy32b_write_reg(0x0024, 0x0000); hy32b_write_reg(0x0025, 0x8000); hy32b_write_reg(0x004f, 0); hy32b_write_reg(0x004e, 0); hy32b_write_reg(0x0022, 0); }
void lcd_line4_ch_disp(unsigned char line4_data, unsigned char position) { position += 0xd4; comdr(position); ms_delay(5); datar(line4_data); ms_delay(1); }
int main(void) { pin_init(); ms_delay(100); while(1){ sort(500); ms_delay(1000); // 1 seconde avec led rouge allumée } }
void lcd_init(void){ int delay; SYSCTL_RCGC2_R |= 0x03; delay = 0; GPIO_PORTB_LOCK_R = 0x4C4F434B; GPIO_PORTB_CR_R |= 0x3C; GPIO_PORTB_AMSEL_R &= ~0x3C; GPIO_PORTB_AFSEL_R &= ~0x3C; GPIO_PORTB_PCTL_R &= ~0xFFFF00; GPIO_PORTB_DIR_R |= 0x3C; GPIO_PORTB_DEN_R |= 0x3C; GPIO_PORTA_LOCK_R = 0x4C4F434B; GPIO_PORTA_CR_R |= 0x0C; GPIO_PORTA_AMSEL_R &= ~0x0C; GPIO_PORTA_AFSEL_R &= ~0x0C; GPIO_PORTA_PCTL_R &= ~0xFF00; GPIO_PORTA_DIR_R |= 0x0C; GPIO_PORTA_DEN_R |= 0x0C; ms_delay(15); RS_2 = 0; EN_3 = 0; GPIO_PORTB_DATA_R = 0x0C; en_pulse(); ms_delay(5); GPIO_PORTB_DATA_R =0x0C; en_pulse(); us_delay(100); //3 GPIO_PORTB_DATA_R = 0x0C; en_pulse(); ms_delay(100); GPIO_PORTB_DATA_R = 0x8; en_pulse(); ms_delay(100); lcd_write_com(0x28);//Function Set lcd_write_com(0x0F);//Display on/off lcd_write_com(0x06);//Entry mode: Incremental lcd_write_com(0x01); //lcd_write_char(0x48); //lcd_write_char(0x48); }
void gsm_sms_del(U8 mem_location) { U8 uc_gsm_sms_del[20] = {"AT+CMGD=1\r\n"}; ms_delay(10000); ms_delay(10000); uc_gsm_sms_del[8] = mem_location; uart1_tx_string(&uc_gsm_sms_del[0]); }
U8 APP_phone_dial(U8 *phone_no) { U8 uc_cnt = 10; U8 uc_temp_key = 0; U8 *uc_ptr; U8 uc_phone_no[20] = {0}; clrscr(); lcd_line_disp("Phone:",0, 1); lcd_line_disp("Call",0, 4); lcd_line_disp("Cancel",14, 4); ms_delay(8000); uc_ptr = &uc_phone_no[0]; while(uc_temp_key != 'E') { uc_temp_key = get_key(0); if((uc_temp_key >= '0') && (uc_temp_key <= '9')) { *uc_ptr = uc_temp_key; uc_ptr++; } else if(uc_temp_key == 'A') { if(uc_ptr >= &uc_phone_no[0]) { if(uc_ptr > &uc_phone_no[0]) { uc_ptr--; } *uc_ptr = ' '; } } else if(uc_temp_key == 'D') { return 0; } lcd_line_disp(&uc_phone_no[0], 7, 1); ms_delay(1100); } *uc_ptr = '\0'; uc_cnt = LIB_strlen(&uc_phone_no[0]); if(uc_cnt > 0) { LIB_str_copy(&uc_phone_no[0], phone_no, uc_cnt+1); return 1; } else { return 2; } }
void main() { initVariables(); DINT; ms_delay(1); InitAdc(); SetupAdc(); InitSysCtrl(); InitPieCtrl(); IER = 0x0000; IFR = 0x0000; MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); InitPieVectTable(); easyDSP_SCI_Init(); InitEPwm3(); InitEPwm4(); pwm_setup(); initialize_mppt_timer(); EALLOW; PieVectTable.TINT2 = &mppt_int; PieVectTable.EPWM3_INT = &pwm_int; PieCtrlRegs.PIEIER3.bit.INTx3 = 0x1; EDIS; IER |= M_INT3; IER |= M_INT14; EINT; ms_delay(1); InitEPwm3Gpio(); //InitEPwm4Gpio(); // EALLOW; // GpioCtrlRegs.GPADIR.bit.GPIO4 = 1; // GpioCtrlRegs.GPADIR.bit.GPIO5 = 1; // GpioCtrlRegs.GPADIR.bit.GPIO6 = 1; // GpioCtrlRegs.GPADIR.bit.GPIO7 = 1; // // GpioDataRegs.GPASET.bit.GPIO4 = 1; // GpioDataRegs.GPASET.bit.GPIO5 = 1; // GpioDataRegs.GPACLEAR.bit.GPIO6 = 1; // GpioDataRegs.GPACLEAR.bit.GPIO7 = 1; // EDIS; ERTM; for(;;) { //// Bus_Voltage_Q15 = ((long int) AdcResult.ADCRESULT1*VBUS_SCALE); if(delay_flag) { ms_delay(10000); delay_flag = 0; } } }
void lcd_line3_disp(unsigned char *line3_data, unsigned char position) { unsigned char l; position += 0x94; comdr(position); ms_delay(5); for(l=0; *line3_data!='\0'; l++) { datar(*line3_data); ms_delay(1); line3_data++; } }
void lcd_init() { //comdr(0x30); comdr(0x38); //2 line,5*7 matrix ms_delay(25); comdr(0x01); //clear display ms_delay(25); comdr(0x06); //automatic rt shift cursor ms_delay(25); comdr(0x0C); //display on cursor on ms_delay(25); }
void IMU_Initialisation(){ uint8_t counter=3; i2c_initialize(I2C2); usart_printf(USART1,"Hello\n\r"); uint8_t accel_address=0x53; uint8_t magnet_address=0x1E; uint8_t gyro_address=ITG3200_ADDR_AD0_LOW; counter=3; while(counter!=0){ accel_object=accelerometer_initialization(accel_address); if(accel_object==null){ ms_delay(1000); counter--; }else break; } if(counter==0){ usart_printf(USARTx,"Failed to initialize accel.Exiting...\n\r"); while(1); } usart_printf(USARTx,"Initialized accelerometer\n\r"); counter=3; while(counter!=0){ magnet_object=magnetometer_initialisation(magnet_address); if(magnet_object==null){ ms_delay(1000); counter--; }else break; } if(counter==0){ usart_printf(USARTx,"Failed to initialize magnetometer.Exiting...\n\r"); while(1); } usart_printf(USARTx,"Initialized magnetometer\n\r"); counter=3; while(counter!=0){ gyro_object=gyro_initialisation(gyro_address); if(gyro_object==null){ gyro_object=gyro_initialisation(gyro_address); ms_delay(1000); counter--; }else break; } if(counter==0){ usart_printf(USARTx,"Failed to initialize gyro.Exiting...\n\r"); while(1); } usart_printf(USARTx," initialize gyro\n\r"); }
int main(void) { // SystemCoreClockSet(MSI48M_CLOCKSRC, 0, 3, 0); GPIO_Init(0,LED_GREEN|LED_RED); GPIO_Write(LED_GREEN,LED_RED); for (;;) { ms_delay(500); GPIO_Write(LED_RED,LED_GREEN); ms_delay(500); GPIO_Write(LED_GREEN,LED_RED); } }
void gsm_sms_send(U8 *ph_no, U8 *sms_content) { uart1_tx_string("AT+CMGS="); uart1_tx_byte('"'); uart1_tx_string(ph_no); uart1_tx_byte('"'); uart1_tx_string(",128\r"); ms_delay(10000); uart1_tx_string(&sms_content[0]); ms_delay(500); uart1_tx_byte(0x1a); ms_delay(50000); ms_delay(50000); ///////////////////////////////////////// }
int ITG3200::init(byte address, byte _SRateDiv, byte _Range, byte _filterBW, byte _ClockSrc, bool _ITGReady, bool _INTRawDataReady) { int a=0; // _dev_address = address; // //this needs to be debugged // a=readFrom(_dev_address,WHO_AM_I,1,_buff); // MYASSERT(a,"Failed to write to register\n\r") // usart_printfm(USARTx,(const int *)"Succesfully read from register\n\r"); // usart_printfm(USARTx,(const int *)"Value of the who am i register %d \n\r",_buff[0]); // // a=writeTo(_dev_address,WHO_AM_I,66); // // MYASSERT(a,"Failed to write 2 register2\n\r") // // usart_printfm(USARTx,(const int *)"Succesfully written to register2\n\r"); // a=readFrom(_dev_address,WHO_AM_I,1,_buff); // usart_printfm(USARTx,(const int *)"Value of the who am i register %d \n\r",_buff[0]); // MYASSERT(a,"Failed to write to register\n\r") // //this is needed to be debugged // usart_printfm(USARTx,(const int *)"Value of address:%2x\n\r",_dev_address); a=setSampleRateDiv(_SRateDiv); MYASSERT(a,"Failed to set sample rate div\n\r") a=setFSRange(_Range); MYASSERT(a,"Failed to set range\n\r") a=setFilterBW(_filterBW); MYASSERT(a,"Failed to set filter BW\n\r") a=setClockSource(_ClockSrc); MYASSERT(a,"Failed to set clocksrc\n\r") a=setITGReady(_ITGReady); MYASSERT(a,"Failed to set ITG ready\n\r") a=setRawDataReady(_INTRawDataReady); MYASSERT(a,"Failed to set data ready mode\n\r") ms_delay(GYROSTART_UP_DELAY); // startup return 0; }
/////////// // Setup // /////////// void setup() { if (PORTB_BIT4) { int i; PORTB_BIT0 = 0; PORTB_BIT1 = 0; PORTB_BIT2 = 0; PORTB_BIT3 = 0; for(i = 0; i < 10; i++) { //flash LEDs for 250ms to show start PORTB_BIT0 = ~PORTB_BIT0; PORTB_BIT1 = ~PORTB_BIT1; PORTB_BIT2 = ~PORTB_BIT2; PORTB_BIT3 = ~PORTB_BIT3; ms_delay(25); } PORTB_BIT0 = 0; PORTB_BIT1 = 0; PORTB_BIT2 = 0; PORTB_BIT3 = 0; isSetup = 0x01; //Full power to pickup motor //PTT_PTT1 = 1; //Motor SLEW PTT_PTT0 = 1; //Motor EN } else { mid = s4avg-s5avg; } }
void DCMI_IRQHandler(void) { GPIO_SetBits(GPIOD, GREEN_LED); // Serial_print(USART2, DCMI->RISR, 16); /* DCMI overrun */ if ( DCMI_GetITStatus(DCMI_IT_OVF) != RESET) { // Overflow interrupt mask while (1){ GPIO_SetBits(GPIOD, GREEN_LED); ms_delay(500); } DCMI_ClearITPendingBit(DCMI_IT_OVF); } if ( DCMI_GetITStatus(DCMI_IT_FRAME) != RESET) { // Frame capture complete interrupt mask DCMI_ClearITPendingBit(DCMI_IT_FRAME); } if ( DCMI_GetITStatus(DCMI_IT_ERR) != RESET) { // Synchronization error interrupt mask while (1) ; DCMI_ClearITPendingBit(DCMI_IT_ERR); } if ( DCMI_GetITStatus(DCMI_IT_LINE) != RESET) { // Line interrupt mask DCMI_ClearITPendingBit(DCMI_IT_LINE); } if ( DCMI_GetITStatus(DCMI_IT_VSYNC) != RESET) { // Line interrupt mask DCMI_ClearITPendingBit(DCMI_IT_VSYNC); } }
//Flash orange LED at about 1hz int main(void) { //RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; // enable the clock to GPIOD //GPIOD->MODER = (1 << 26); // set pin 13 to be general purpose output //GPIOD->MODER = 0x55000000; STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); // ------------- USB -------------- // USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb); setbuf(stdout, NULL); for (;;) { ms_delay(500); STM_EVAL_LEDToggle(LED3); STM_EVAL_LEDToggle(LED4); STM_EVAL_LEDToggle(LED5); STM_EVAL_LEDToggle(LED6); printf("qqqq\n"); } }
int I2C_read(I2C_TypeDef* I2Cx,byte buff ){ // enable acknowledge of recieved data int timeout; uint8_t flag1=0,flag2=0; /* Test on I2C1 EV8 and clear it */ timeout = I2C_TIMEOUT_MAX; /* Initialize timeout value */ I2C_AcknowledgeConfig(I2Cx, ENABLE); // // wait until one byte has been received while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED) ){ ms_delay(100); if((timeout--)==0){ flag1 = I2Cx->SR1; flag2 = I2Cx->SR2; usart_printf(USARTx,"Flag1:%04x \n\r Flag2:%04x\n\r",flag1,flag2); usart_printf(USARTx,"Failing at read ack stage\n\r"); return -1; } } // read data from I2C data register and return data byte byte data = I2C_ReceiveData(I2Cx); return 0; }
void InitAdc(void) { // *IMPORTANT* // The Device_cal function, which copies the ADC calibration values from TI reserved // OTP into the ADCREFSEL and ADCOFFTRIM registers, occurs automatically in the // Boot ROM. If the boot ROM code is bypassed during the debug process, the // following function MUST be called for the ADC to function according // to specification. The clocks to the ADC MUST be enabled before calling this // function. // See the device data manual and/or the ADC Reference // Manual for more information. EALLOW; SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; (*Device_cal)(); EDIS; // To powerup the ADC the ADCENCLK bit should be set first to enable // clocks, followed by powering up the bandgap, reference circuitry, and ADC core. // Before the first conversion is performed a 5ms delay must be observed // after power up to give all analog circuits time to power up and settle // Please note that for the delay function below to operate correctly the // CPU_RATE define statement in the DSP2802x_Examples.h file must // contain the correct CPU clock period in nanoseconds. EALLOW; AdcRegs.ADCCTL1.bit.ADCBGPWD = 1; // Power ADC BG AdcRegs.ADCCTL1.bit.ADCREFPWD = 1; // Power reference AdcRegs.ADCCTL1.bit.ADCPWDN = 1; // Power ADC AdcRegs.ADCCTL1.bit.ADCENABLE = 1; // Enable ADC AdcRegs.ADCCTL1.bit.ADCREFSEL = 0; // Select interal BG EDIS; ms_delay(10); // Delay before converting ADC channels }
void ZIGB_setting() { ZIGB_menu_page(); while((Uc_key_temp = get_key(1)) != 'A') { if(Uc_key_temp == '1') { Uc_key_temp = 0; #if RESP_ON_UART0 == 1 uart0_send_string("\n\n\rReading ZigBee Parameters..."); #endif ZIGB_read(); ZIGB_menu_page(); } else if(Uc_key_temp == '2') { Uc_key_temp = 0; ms_delay(1000); #if RESP_ON_UART0 == 1 uart0_send_string("\n\n\rWritting ZigBee Parameters..."); #endif ZIGB_write(); ZIGB_menu_page(); } } }
/*** get keypad input ****/ void get_keypad_input() { char keypad_key; keypad_enable(); while(training) { keypad_key=getkey(); // get value from keypad wait_keyup(); lcd_init(); set_lcd_addr(0x00); if(keypad_key==1) { // 1 = forward move_forward(); }else if(keypad_key==4) { // 4 = left move_left(); }else if(keypad_key==7) { // 7 = right move_right(); }else if(keypad_key==0) { // 0 = reverse move_reverse(); }else if(keypad_key==6) { // 7 = pause move_pause(); }else if(keypad_key==9) { // break out of training mode training=0; move_stop(); display_movement(&stop_training); break; }else{ display_movement(&error); } ms_delay(50); } }
/**< 连接 */ bool SimplexSock::Connect(PSIMPLEX_DESC pDesc) { try{ if(!pDesc) return false; struct sockaddr_in pin; bzero(&pin, sizeof(pin)); pin.sin_family = AF_INET; inet_pton(AF_INET, pDesc->cIp, &pin.sin_addr); pin.sin_port = htons(pDesc->nPort); struct timeval sndTime; sndTime.tv_sec=0; sndTime.tv_usec=500000; int nSndBuf=64*1024; linger m_sLinger; m_sLinger.l_onoff=1; m_sLinger.l_linger=1; int nCount=0; if(pDesc->socket_Snddesc) { close(pDesc->socket_Snddesc); pDesc->socket_Snddesc=0; if(nConn>0) nConn--; } pDesc->socket_Snddesc = socket(AF_INET, SOCK_STREAM, 0); trace_log(DBG,"the cIp[%s] nPort[%d] start connect",pDesc->cIp,pDesc->nPort); static int nTimes=0;/**< 主要作用是减少打印信息 */ while(1) { if (connect(pDesc->socket_Snddesc, (struct sockaddr *)&pin, sizeof(pin)) == -1) { nTimes=(++nTimes)%300; if(1==nTimes) trace_log(DBG,"errno[%d]=%s",errno,strerror(errno)); if(2== nCount) { if(pDesc->socket_Snddesc) close(pDesc->socket_Snddesc); pDesc->socket_Snddesc=0; if(1==nTimes)trace_log(ERR,"the cIp[%s] nPort[%d] connect fail",pDesc->cIp,pDesc->nPort); return false; } ms_delay(500);/**< 0.5秒 */; }else{ setsockopt(pDesc->socket_Snddesc,SOL_SOCKET,SO_SNDTIMEO,(const char*)& sndTime,sizeof(sndTime)); setsockopt(pDesc->socket_Snddesc,SOL_SOCKET,SO_SNDBUF,(const char*)&nSndBuf,sizeof(int)); setsockopt(pDesc->socket_Snddesc,SOL_SOCKET,SO_LINGER,(const char*)&m_sLinger,sizeof(linger)); //pDesc->nMask=pDesc->nMask|1; //pDesc->nSndConnStatus=0; if(nConn<nMaxConn) nConn++; pDesc->tSndIdle=time(0); break; } ++nCount; } trace_log(DBG,"the cIp[%s] nPort[%d] connect ok",pDesc->cIp,pDesc->nPort); return true; }catch(...){ trace_log(ERR,"Error in ClientYinLian::Connect()"); return false; } }
void ZIGB_menu_page() { clrscr(); lcd_line1_disp("ZigBee Settings",2); lcd_line2_disp("Read [1]",0); lcd_line3_disp("Write [2]",0); ms_delay(1000); }
void main () { dsco_led_init(); spi_init(FALSE); //no hardware chip select usart_init(); //initialise chip select on PD0 ( Open Drain not work for this module ) GPIOD->MODER |= GPIO_MODER_MODER0_0 ;SPI_CS_HIGH uint8_t response, i; GPIOD->ODR ^= DISCOF4_LED_GREEN; //Lights on green LED uint8_t inReset = 1; spi_write_auto(0x6B,0x80); printString("Reset command sent\r\n"); i = 0; while ( inReset ) { i++; response = spi_read_auto( 0x6B ); inReset = response & 0x80; if ( i > 500 ) { printString("Reset Error, Response: "); printWord(response); printString("\r\n"); i = 0; } } response = spi_read_auto( 0x6B ); printString("Module resets, Power MGT: ");printWord(response);printString("\r\n"); response = spi_read_auto( 0x75 ); printString("ID: ");printWord(response);printString("\r\n"); uint8_t gyro_xl, gyro_xh, gyro_yl, gyro_yh, gyro_zl, gyro_zh; uint8_t accel_xl, accel_xh, accel_yl, accel_yh, accel_zl, accel_zh; while (TRUE) { gyro_xh = spi_read_auto( 67 ) ; gyro_xl = spi_read_auto( 68 ) ; gyro_yh = spi_read_auto( 69 ) ; gyro_yl = spi_read_auto( 70 ) ; gyro_zh = spi_read_auto( 71 ) ; gyro_zl = spi_read_auto( 72 ) ; printString("Gyro : {");printWord((gyro_xh << 8) + gyro_xl); printString(", ");printWord((gyro_yh << 8) + gyro_yl); printString(", ");printWord((gyro_zh << 8) + gyro_zl); accel_xh = spi_read_auto( 59 ) ; accel_xl = spi_read_auto( 60 ) ; accel_yh = spi_read_auto( 61 ) ; accel_yl = spi_read_auto( 62 ) ; accel_zh = spi_read_auto( 63 ) ; accel_zl = spi_read_auto( 64 ) ; printString("} Accel : {");printWord((accel_xh << 8) + accel_xl); printString(", ");printWord((accel_yh << 8) + accel_yl); printString(", ");printWord((accel_zh << 8) + accel_zl);printString("}\r"); ms_delay(20); } }
__interrupt void H5_UART0IT(void) // Interrupt accepts packet, processes, prints via the putchar function, and continues on { __disable_interrupt(); //disable interrupt and continue with the processing of packet //The following code gives the user the state of the 3 buffers //while(!(UCSR0A & 0x80)); //while UCSR1A is not 1000 0000, do nothing (THIS IS USART RECEIVE COMPLETE FLAG! IT TURNS TO 1 WHEN THE PACKET RECEIVE IS COMPLETE) //otherwise, once UCSR1A is 1000 0000, (PACKET IS RECEIVED AND SITTING IN UDR1 READY FOR USE) data = UDR0; //set data equal to UDR1 - where the packet is sitting putchar(data); //run this packet character by character through the putchar function if (data == '$'){ //first character of packet save_on = 1; //set save_on to 1, we will fill the c array with the packet, character by character } else if (data == '@'){ //otherwise if 'data' is @ symbol, last character of packet packet_data[ii] = NULL;//set that final character to null char ms_delay(100); //wait 100 milliseconds and then set the flag to allow TWI to commence. pure_transmissions_only = 1; //set the flag to allow the TWI transmissions to commence. save_on = 0; //set save_on to 0, we will not be filling any more characters of the array 'c' if(strcmp(packet_buff1,comparator) == 0){ //if buffer 1 is empty, fill it strcpy(packet_buff1,packet_data); //printf("I loaded buffer 1\n\r"); } else if ((strcmp(packet_buff1,comparator) != 0) && (strcmp(packet_buff2,comparator) == 0)){ //otherwise if buffer 1 is full and 2 is empty, fill 2 strcpy(packet_buff2,packet_data); //printf("\n\rI loaded buffer 2\n\r"); } else if ((strcmp(packet_buff1,comparator) != 0) && (strcmp(packet_buff2,comparator) != 0) && (strcmp(packet_buff3,comparator) == 0)){ //otherwise if buffer 1 and 2 are full and 3 is empty, fill 3 strcpy(packet_buff3,packet_data); //printf("I loaded buffer 3\n\r"); } //while(strcmp(packet_buff1,comparator) == 0); //wait up while the first buffer is empty parsing(packet_buff1); //enter the parsing function with the next-in-line buffer //printf("I processed buffer 1\n\r"); if(strcmp(packet_buff2,comparator) != 0){ strcpy(packet_buff1,packet_buff2); //move contents from buffer 2 into buffer 1 //printf("I moved 2 into 1\n\r"); strcpy(packet_buff2,comparator); //re-initialize buffer 2 } if(strcmp(packet_buff3,comparator) != 0){ strcpy(packet_buff2,packet_buff3); //move contents from buffer 3 into buffer 2 //printf("I moved 3 into 2\n\r"); strcpy(packet_buff3,comparator); //re-initialize buffer 3 } ii=0; //reset the counter return; //end and wait for next packet } if (save_on ==1){ packet_data[ii++] = data; //since data (UDR1) is only getting 1 character at a time in serial, this sets each character of the c array to the incoming character in UDR1 before it receives the next character } __enable_interrupt(); //enable the interrupt again and wait for next packet }
void ZIGB_exit_cmd() { uart1_send_string("ATCN\r"); if(ZIGB_responce(3,"OK\r")) { #if RESP_ON_UART0 == 1 uart0_send_string("\n\n\rExit CMD: OK "); #endif ms_delay(10000); } else { #if RESP_ON_UART0 == 1 uart0_send_string("\n\n\rExit CMD: ERROR "); #endif ms_delay(10000); } }
void main(void) { PLL_init(); lcd_init(); SCI0_init(9600); SCI1_int_init(9600); // Channel to talk to ESP8266 motor0_init(); // These functions actually control PWM outputs motor1_init(); // We use them to run the RGB LED. motor2_init(); RTI_init(); SW_enable(); initq(); DDRH = 0; // PORTH is an input. result = 0; status = 'b'; // Populate binary search tree: set_lcd_addr(0); send_at_command_sci1("ATE0"); // change to ATE1 for debug status = 'i'; // Establish connection to server. send_at_command_sci1("AT+CWMODE=1"); // Set ESP to station mode send_at_command_sci1("AT+CIPMODE=0"); // Set ESP to normal transmission mode send_at_command_sci1("AT+CIPMUX=0"); // Set ESP to single-connection mode send_at_command_sci1("AT+CWJAP=\"Freynet\",\"\""); // Connect to network send_at_command_sci1("AT+CIPSTART=\"TCP\",\"fpf3.net\",12345"); // connect to server while(1){ command = '\0'; while(qempty()); command = getq(); switch (command) { case 'n': status = 'w'; result = new_sequence(); ms_delay(500); // If we finish too quickly, we open a connection the ESP thinks is already open, and it breaks. send_at_command_sci1("AT+CIPSTART=\"TCP\",\"fpf3.net\",12345"); // connect to server break; } outchar0(result); } }
/*** Move pause ***/ void move_pause() { display_movement(&pause); MOTORDDR=0xFF; // enable motor port as output MOTORPORT=0xFF; ms_delay(2000); if(training) { add_to_array(5); // if training mode boolean is 1, add direction to array } move_stop(); // turn off all motor ports }