// ** Grundinitialisierung ** void coldstart () { setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_VDD); setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0); setup_oscillator(OSC_8MHZ|OSC_INTRC); setup_comparator(NC_NC_NC_NC); output_a (0b00001000); output_b (0); output_c (0); output_d (0); output_e (0); set_tris_a (TRISA_INIT); // Datenrichtung Port A set_tris_b (TRISB_INIT); // Datenrichtung Port B set_tris_c (TRISC_INIT); set_tris_d (TRISD_INIT); set_tris_e (TRISE_INIT); port_b_pullups(TRUE); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32|RTCC_8_BIT); // Timer0 intern, Takt 20.00/4/64 = 78.125 KHz // Interrupt alle 256/15.625 = 3.2768 ms (305Hz) // Korrekturwert für 10 ms: 156 Timerclicks // -> Timer wird auf 256-156=100 vorgestellt set_timer0 (Timerstartwert_K); // Timerwert auf Startwert setzen enable_interrupts(INT_TIMER0); setup_timer_1(T1_DISABLED); // Nur Timer0 Interrupt delay_ms (200); }
//============================================================================= void init_prog(void) { setup_wdt(WDT_OFF); setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_BIT);// TIMER0 setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_low_volt_detect(FALSE); setup_oscillator(OSC_32MHZ); set_tris_a(0xFF);//7F set_tris_b(0xFF); //FF set_tris_c(0x94);//94 set_tris_d(0xFF); //02 set_tris_e(0xF0); //f0 set_tris_f(0xFF);//ff set_tris_g(0xFC); //04 output_a(0x00); output_b(0x00); output_c(0x00); output_d(0x00); output_e(0x00); output_f(0x00); output_g(0x00); }
void main() { setup_oscillator(OSC_NORMAL); while (true) { output_A(0xff); output_B(0xff); output_C(0xff); output_D(0xff); output_E(0xff); output_high(pin_C1); output_high(pin_C0); output_high(pin_A4); Delay_ms(500); output_A(0x0); output_B(0x0); output_C(0x0); output_D(0x0); output_E(0x0); output_low(pin_C1); output_low(pin_C0); output_low(pin_A4); Delay_ms(500); } }
int main (void) { int dummy; //int matrix; //only for test of ledmdrv int i; //int temp_current_val; //temporary //int first_ec=1; //Setup oscillator/ports/pins first setup_oscillator(); setup_ports(); setup_peripheral_pin_select(); setup_interrupt_priorities(); #ifdef USE_DIO setup_dio(); #endif #ifdef USE_ADC setup_adc(); #endif #ifdef USE_ETHERCAT while (!eeprom_loaded()) //Wait until ESC is ready //ToggleHeartbeatLED(); //Success SetHeartbeatLED; setup_ethercat(); ClrHeartbeatLED; #endif setup_interrupt_priorities(); dummy = U1RXREG; while(1){ if (i++%20001==0) { ToggleHeartbeatLED(); #if defined USE_ETHERCAT //&& ! defined M3_MAX2_BDC_ARMH step_ethercat(); #endif } } }
int main( void ) { uint8_t buffer_index; packet_header_t* header; // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; header = (packet_header_t*)tx_buffer; // Initialize Tx Buffer header->length = sizeof(packet_header_t) - 1; header->source = DEVICE_ADDRESS; header->type = 0x66; // Sync message header->flags = 0xAA; // Make sure processor is running at 12MHz setup_oscillator(); // Initialize UART for communications at 115200baud setup_uart(); // Initialize LEDs setup_leds(); // Initialize timer set_ccr( 0, TIMER_LIMIT ); setup_timer_a(MODE_UP); // Send sync message register_timer_callback( send_sync_message, 0 ); // Initialize radio and enable receive callback function setup_radio( process_rx ); // Enable interrupts, otherwise nothing will work eint(); while (1) { // Enter sleep mode __bis_SR_register( LPM0_bits + GIE ); __no_operation(); } return 0; }
void main() { int16 data = 0; //Habilitar Oscilador interno setup_oscillator(OSC_8MHZ,OSC_INTRC); //Configuración de ADC setup_adc_ports(AN0_TO_AN8); setup_adc(ADC_CLOCK_INTERNAL); while(TRUE) { sampling_ADC(); printf("\n\n"); } }
void init_pic(void) { // initialise port A LATA = PA_DefData; TRISA = PA_DefTRIS; // initialise port C LATC = PC_DefData; TRISC = PC_DefTRIS; APFCON0 = 0x0; //setup_timer_2 (T2_DIV_BY_16, 250, 10); //500 us overflow, 5.0 ms interrupt setup_comparator (NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard setup_oscillator (OSC_8MHZ|OSC_PLL_ON) ; setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32|RTCC_8_bit); //1.0 ms overflow setup_timer_4(T4_DISABLED,0,1); setup_timer_6(T6_DISABLED,0,1); }
// Frequency of interrupt (clock/(4*divisor)) / (256-reload) void mcu_init() { setup_oscillator(OSC_16MHZ); setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_comparator(NC_NC_NC_NC); // Setup the TIMER0 Interrupt set_timer0(0); setup_timer_0(RTCC_INTERNAL | RTCC_8_BIT | RTCC_DIV_4); enable_interrupts(INT_TIMER0); enable_interrupts(GLOBAL); set_tris_a(0); set_tris_b(0); set_tris_c(0); }
void main() { int8 val; char car; // Initialization delay_ms(400); disable_interrupts(global); disable_interrupts(int_timer1); disable_interrupts(int_timer2); disable_interrupts(int_ext); setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF|ADC_TAD_MUL_0); setup_spi(FALSE); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); setup_timer_2(T2_DIV_BY_1,2,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_low_volt_detect(FALSE); setup_oscillator(False); delay_ms(400); while(1) { val = input(PIN_B0); if (val == 0) { output_a(0); } else if (val == 1) { output_a(255); } } }
//------------------------------------------------------------------------------ void init_prog(void) { setup_wdt(WDT_OFF); setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_BIT);// TIMER0 setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_low_volt_detect(FALSE); setup_oscillator(OSC_32MHZ); set_tris_a(0x00); set_tris_b(0x24); set_tris_c(0x80); set_tris_d(0x00); set_tris_e(0x15); set_tris_f(0x58); set_tris_g(0x10); output_a(0x00); output_b(0x00); output_c(0x00); output_d(0x00); output_e(0x00); output_f(0x00); output_g(0x00); // RF Modul and PA/LNA activation IOpin.modulepower=0; IOpin.moduleCTX=1; IOpin.moduleCPS=0; IOpin.modulePWRUP=1; }
//------------------------------------------------------------------------------ void main(){ int i; setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); disable_interrupts(INT_TIMER0); enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF); output_low(PIN_C5); while(TRUE){ if(f_process){ f_process=0; output_toggle(PIN_C5); disable_interrupts(INT_RDA); printf("\n\r"); for(i=0;i<(cont-2);i++){ printf("vector[%u]=%c\n\r",i,p[i]); //muestro los datos recibidos } procesar_guardar(); cont=0; printf("Fin programacion\n\r"); enable_interrupts(INT_RDA); } } }
void main(){ setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); setup_timer_1(T1_DISABLED); setup_oscillator (OSC_8MHZ); setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); //Software workaround for the power switch floating /* onewire_init(); onewire_sendbyte(0xCC); onewire_sendbyte(0x6C); //Write Data Command onewire_sendbyte(0x31); //Eeprom address but actually gets written to Shadow Ram onewire_sendbyte(0xE7); //Value to make PMOD1 SWEN=0 RNAOP=0 //Copy the shadow Ram written above over to actual EEPROM onewire_init(); onewire_sendbyte(0xCC); onewire_sendbyte(0x48); //send the copy command onewire_sendbyte(0x30); //copy shadow ram to the block containing 31 */ for (i=1;i<5;i++){ output_high(pin_A4); delay_ms(250); output_low(pin_A4); delay_ms(250); } while(true){ //Use the following to determine the state of the one wire net //Will report if device present, not, or shorted //Comment out rest of code //onewire_init_with_error_check(); //read_status(); //printf("status byte is ====>(%x)\n\r",status); //printf("Please enter a command (h for help):\n\r"); //Waits for a command to come in over the serial port //printf("Enter Command\n\r"); //Base commands are: //N = Print out the net address of one attached sensor //K = Return the current in micro volts //C = Return the chip temperature in celsius //F = Return the chip temperature in fahrenheit if (interactive == 1) printf("Enter Command:\n\r"); gets(command); //Check to see if controller is present if (command[0] == 'p'){ printf("Pyro Logger found and responding...\n\r"); printf("Firmware Version 1\n\r"); printf("N - Get Net address\n\r"); printf("Kaddress - Thermo uV's\n\r"); printf("Caddress - Temp in C\n\r"); printf("Faddress - Temp in F\n\r"); printf("i - toggle interactive\n\r"); interactive = 1; } if (command[0] == 'i'){ interactive = 0; } //Print out the Net address for configuring other software if (command[0] == 'N'){ printf("Reading Net Address...\r\n"); read_netaddress(); } //**************************************************** //READ Current from Sensor //**************************************************** if (command[0] == 'K'){ //Initialize the Temporary Buffer and make sure you have the null char tmp_buff[0]='0'; tmp_buff[1]='X'; tmp_buff[2]='0'; tmp_buff[3]='0'; tmp_buff[4]='\n'; i=0; for(j=1; j<=15; j+=2) { tmp_buff[2]=command[j]; tmp_buff[3]=command[j+1]; address_array[i]=ATOI(tmp_buff); i++; } onewire_init(); onewire_sendbyte(0x55); //Transmit skip Rom Command //Unique 64 Bit address for(j=0; j<=7; j++) { onewire_sendbyte(address_array[j]); } onewire_sendbyte(0x69); //0x69 Transmit Read RAM command onewire_sendbyte(0x0E); //Transmit Read start address data_MSB=onewire_readbyte(); data_LSB=onewire_readbyte(); //printf("MSB ====>(%x)\n\r",data_MSB); //printf("LSB ====>(%x)\n\r",data_LSB); current=make16(data_MSB,data_LSB); current=current >> 3; current_float=(current*.000015625); printf("%4.7f\r\n",current_float); blink(); } //*********************************************************** //Read Temperature of the on Chip Sensor //*********************************************************** //DS2760 can measure 0.125 deg C per bit //Whole number temperature values can be had by simpling taking the high byte //Or if high and low bytes are used shift right 5 places and multiply by .125 in a float if (command[0] == 'C' || command[0] == 'F'){ //Initialize the Temporary Buffer and make sure you have the null char tmp_buff[0]='0'; tmp_buff[1]='X'; tmp_buff[2]='0'; tmp_buff[3]='0'; tmp_buff[4]='\n'; //Pull the address out of the command 8 bytes of HEX //Changes it from a string to array stuffed in address_array i=0; for(j=1; j<=15; j+=2) { tmp_buff[2]=command[j]; tmp_buff[3]=command[j+1]; address_array[i]=ATOI(tmp_buff); i++; } //Send the addresss down the One Wire Buss onewire_init(); onewire_sendbyte(0x55); //Match Net Address Command for(j=0;j<=7;j++){ onewire_sendbyte(address_array[j]); } //Read Data onewire_sendbyte(0x69); //0x69 Transmit Read RAM command onewire_sendbyte(0x18); //Transmit Read start address data_MSB=onewire_readbyte(); data_LSB=onewire_readbyte(); temp=make16(data_MSB,data_LSB); //Check for a negative temperature for cold junction. Really cold junction //can only be positive or zero. Cold junction reference should never fall below zero //so if its below zero make it zero, about the best we could do aside throwing up errors //To force temperature negative for testing uncomment below //temp = temp + 32768; //The Check if (bit_test(temp,15) == 1) temp = 0; /* //Bit Shift Math For Whole Number Only temp=temp>>8; temp_float = temp; */ //Shift the data 5 bits to the right temp=temp >> 5; //Math for celsius temp_float=(temp *.125); //Math for fahrenheit temp_float_faren=((temp_float * 1.8) + 32); //Print out either celsius or fahrenheit //Over the serial Port if (command[0] == 'C' ) printf("%3.2f\r\n",temp_float); if (command[0] == 'F' ) printf("%3.2f\r\n",temp_float_faren); //Flash the leds to show there is communication blink(); }
void main() { disable_interrupts(GLOBAL); setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_spi2(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_4V096); setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0); // TIMER 0 is being used to service the WTD setup_timer_0(T0_INTERNAL|T0_DIV_256); /* sets the internal clock as source and prescale 256. At 10 Mhz timer0 will increment every 0.4us (Fosc*4) in this setup and overflows every 6.71 seconds. Timer0 defaults to 16-bit if RTCC_8_BIT is not used. Fosc = 10 MHz, Fosc/4 = 2.5 Mhz, div 256 = 0.0001024 s, 65536 increments = 6.71 sec Fosc = 64 MHz, Fosc/4 = 16 Mhz, div 256 = 0.000016 s, 65536 increments = 1.05 sec .. pre-load with 3036 to get exact 1.0000 sec value */ // TIMER 1 is used to extinguish the LED setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); /* sets the internal clock as source and prescale 4. At 10Mhz timer0 will increment every 0.4us in this setup and overflows every 104.8 ms. Timer1 is 16-bit. Fosc = 10 Mhz ... 2.5 MHz / div 4 = 0.00000160 s * 65536 = 0.104858 sec Fosc = 64 Mhz ... 16 MHz / div 4 = 0.00000025 s * 65536 = 0.016384 sec Fosc = 64 Mhz ... 16 MHz / div 8 = 0.00000200 s * 65536 = 0.032768 sec */ setup_stepper_pwm(); // Uses TIMER 2 // TIMER 3 is used for stepper motor intervals setup_timer_3(T3_INTERNAL | T3_DIV_BY_1); // 16 bit timer // TIMER 4 is use for serial time-outs. 8-bit timer. setup_timer_4(T4_DIV_BY_4, 127, 1); setup_comparator(NC_NC_NC_NC); setup_oscillator(OSC_16MHZ | OSC_PLL_ON); // Fosc = 64 MHz ext_int_edge(0, H_TO_L); // Set up PIC18 EXT0 enable_interrupts(INT_EXT); start_heartbeat(); enable_interrupts(GLOBAL); init_hardware(); motor_sleep_rdy(); sleep_mode = FALSE; busy_set(); init_nv_vars(); get_step_vars(); init_aws(); blink(); //Add for TCP/IP interface //delay_ms(15000); signon(); RTC_read(); RTC_last_power(); RTC_reset_HT(); RTC_read(); RTC_read_flags(); if(nv_sd_status>0) fprintf(COM_A,"@SD=%Lu\r\n", nv_sd_status); init_rtc(); // This is the FAT RTC sd_status = init_sdcard(); if(sd_status>0) msg_card_fail(); reset_event(); if(m_error[0] > 0 || m_error[1] > 0) msg_mer(); if (m_comp[0]==FALSE) { e_port[0]=0; write16(ADDR_E1_PORT,0); fprintf(COM_A, "@MC1,%Lu,%Ld\r\n", m_comp[0],e_port[0]); } if (m_comp[1]==FALSE) { m_lin_pos[1]=-1; write16(ADDR_M2_LIN_POS, -1); fprintf(COM_A, "@MC2,%Lu,%Ld\r\n", m_comp[1],m_lin_pos[1]); } if (nv_cmd_mode == FALSE){ for(dt=0; dt<100; ++dt){ blip(); if (nv_cmd_mode == TRUE) { busy_clear(); fputs("@OK!", COM_A); command_prompt(); dt = 100; } } } else command_prompt(); user_quit = auto_sample_ready(); reset_cpu(); }
////////////////////////////////////////////////////////////////////////////////////////////// // // // Main function // // // ////////////////////////////////////////////////////////////////////////////////////////////// int main(void) { //Test int last_nombre = 4; char str[64] = "Test de String..."; unsigned char distanceActuel = 0; //Variables protocole de liaison de donnée char trame_a_envoye = 0, trame_complete = 0, trameRX[NBROCTET], trameTX[NBROCTET]; //Initial configuration setup_oscillator(); config(); //Init fifo fifo_init(); radio_dir(TRM_RX); //Module en réception //Display welcome screen: ToDo #ifdef USE_GLCD GLCD_Bitmap((char*)Base1, 0, 0, 128, 64); #endif //Test // index = 0; // while(1) // { // // result = get_offset(dirty_buf[index], dirty_buf[index + 1], flag); // result = get_flag(flag); // Nop(); // clean_buffer(result, 16); // Nop(); // } //Main loop while (1) { #ifdef AUTO routine_auto(&trame_a_envoye, &trame_complete, trameTX, trameRX); #endif #ifdef BORNE routine_borne(&trame_a_envoye, &trame_complete, trameTX, trameRX); #endif //Test: encodeur et GLCD if((last_nombre != nombre) || buttonPress) //Si une transition a eu lieu { #ifdef USE_GLCD GLCD_ClearScreen(); GLCD_Bitmap((char*)Base1, 0, 0, 128, 64); if(buttonPress && !toEcran1) { BORNERESERVE = nombre; GLCD_GoTo(0,5); GLCD_WriteString(RESERVE); toEcran1 = 1; } else if(buttonPress && toEcran1) { toEcran1 = 0; BORNERESERVE = 3; confirm=2; } sprintf(str,"%d",SERIALBATTERIE); GLCD_GoTo(107,0); GLCD_WriteString(str); #endif switch(nombre) { case 0: #ifdef USE_GLCD DISTANCE = D1; GLCD_GoTo(0,2); GLCD_WriteString(ADR1A); if(!toEcran1) { GLCD_GoTo(0,3); GLCD_WriteString(ADR2); GLCD_GoTo(0,4); GLCD_WriteString(ADR3); } #endif break; case 1: #ifdef USE_GLCD DISTANCE = D2; GLCD_GoTo(0,3); GLCD_WriteString(ADR2A); if(!toEcran1) { GLCD_GoTo(0,2); GLCD_WriteString(ADR1); GLCD_GoTo(0,4); GLCD_WriteString(ADR3); } #endif break; case 2: #ifdef USE_GLCD DISTANCE = D3; if(!toEcran1) { GLCD_GoTo(0,2); GLCD_WriteString(ADR1); GLCD_GoTo(0,3); GLCD_WriteString(ADR2); } GLCD_GoTo(0,4); GLCD_WriteString(ADR3A); #endif break; default: #ifdef USE_GLCD GLCD_ClearScreen(); GLCD_Bitmap((char*)Base1, 0, 0, 128, 64); #endif break; } #ifdef USE_GLCD GLCD_GoTo(90,7); GLCD_WriteString(METER); distanceActuel = DISTANCE; buttonPress = 0; last_nombre = nombre; if(confirm==2) { if(D1<DISTANCEPROCHE){ borneProche(0); } else if(D2<DISTANCEPROCHE){ borneProche(1); } else if(D3<DISTANCEPROCHE){ borneProche(2); } if(confirm==1) { buttonPress=1; toEcran1=0; } else if(confirm==0) { buttonPress=0; toEcran1=0; last_nombre=4; } } #endif } //Données sortantes if(trame_a_envoye == 1) { envoie = rf_envoie(trameTX, (char *)clean_buf); if(envoie == 1) trame_a_envoye = 0; } //Flags - Données entrantes if(rf_flag == 1)//&& trame_complete == 0) { //Actualise la batterie #ifdef USE_GLCD getBatt(); sprintf(str,"%03i",BATTERIE); GLCD_GoTo(80,0); if(nombre==0) {DISTANCE = D1;} else if(nombre==1) {DISTANCE = D2;} else if(nombre==2) {DISTANCE = D3;} GLCD_WriteString(str); sprintf(str,"%i",DISTANCE); GLCD_GoTo(40,7); GLCD_WriteString(str); #endif result = get_flag(flag); if(result != 10) { clean_buffer(result, 32); //Extraction des octets vers la couche application trame_complete = rf_gerer_RX((char *)clean_buf, trameRX); } //Remise à zéro de la détection rf_flag = 0; result = 10; } // #ifdef GPS_FEEDTHROUGH //TestGPS #ifdef DEBUG_MPSIM gps_flag =1; //REMOVE #endif if(gps_flag) { gps_flag = 0; //Filtre les données quand le buffer est plein #ifdef DEBUG_MPSIM (gpsstr[3]='R'); //REMOVE #endif if((gpsstr[3]=='R')) { for(a =0;a<47;a++) { gps[a] = gpsstr[a]; //Buffer de travail } // puts_usart1(gpsstr); //gps[] = "$GPRMC,174254.000,V,4522.75800,N,07155.43400,W"; #ifdef DEBUG_MPSIM gps[20]='4'; gps[21]='5'; gps[22]='2'; gps[23]='2'; gps[25]='7'; gps[26]='5'; gps[27]='8'; gps[33]='0'; gps[34]='7'; gps[35]='1'; gps[36]='5'; gps[37]='5'; gps[39]='4'; gps[40]='3'; gps[41]='4'; gps[45]='W'; #endif convStr(); //LaA = 45.3793; //LoA= -71.9239; assignDist(LaA,LoA); } } #endif /* #ifdef USE_GLCD if(buttonPress) { switchScreen(last_nombre); buttonPress = 0; } if(distanceActuel < DISTANCEBATT && BATTERIE < 50 && ecran ==2) { switchBatt(); } #endif */ if(buttonPress) { #ifdef BORNE buttonPress = 0; char donnee_test[NBROCTET] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37}; envoie = rf_envoie(donnee_test, (char *)clean_buf); #endif #ifdef AUTO puts_usart1(gps); #endif } if(rssi_flag) { rssi_flag = 0; //Filtre les données quand le buffer est plein rssi = get_rssi(); } } return 0; }
int main (void) { int dummy; //int matrix; //only for test of ledmdrv int i; //int temp_current_val; //temporary //int first_ec=1; //Setup oscillator/ports/pins first setup_oscillator(); setup_ports(); setup_peripheral_pin_select(); setup_interrupt_priorities(); #ifdef USE_DIO setup_dio(); #endif #ifdef USE_CONTROL setup_control(); #endif #ifdef USE_ADC_SPI setup_adc_spi(); #endif #ifdef USE_ADC setup_adc(); initDma0(); // Initialise the DMA controller to buffer ADC data in conversion order #endif #ifdef USE_TIMER3 //setup_timer3(); #endif #ifdef USE_UART setup_uart(); #endif ecat_isr_running = 0; #ifdef USE_ETHERCAT while (!eeprom_loaded()) //Wait until ESC is ready //ToggleHeartbeatLED(); //Success SetHeartbeatLED; //#ifdef ECAT_DMA cfgDma0SpiTx(); cfgDma1SpiRx(); //#endif setup_ethercat(); ClrHeartbeatLED; #endif #if defined PWR_0_2 || defined PWR_0_3 || defined PWR_0_4 || defined PWR_0_5 ClrEnableMotor; #endif setup_interrupt_priorities(); dummy = U1RXREG; while(1){ if (i++%20001==0) { //ToggleHeartbeatLED(); } #if defined USE_ETHERCAT if (!IEC0bits.DMA1IE) { DISABLE_AL_EVENT_INT; step_ethercat(); ENABLE_AL_EVENT_INT; } #endif } }
//inits void init(){ setup_oscillator(OSC_INTRC|OSC_8MHZ); setup_timer_2(MODE,PERIOD,POSTSCALE); enable_interrupts(INT_TIMER2); enable_interrupts(global); }
void main () { disable_interrupts(GLOBAL); //общее запрещение прерываний setup_oscillator(OSC_8MHZ); //|OSC_INTRC set_tris_a(0x00); //выходы set_tris_b(0xff); //входы set_tris_c(0x10); //выходы, RC4-вход(данные от STM) //output_c(0x4f); portc=0x4f; porta=0x7f; portb=0xff; //set_tris_c(0x10); //выходы, RC4-вход(данные от STM) //output_a(0x7f); //output_b(0xff); pit_bykl(); pr_wkl_pit=0; //пр. вкл. питания (исп. для 1-го нажатия кн. "Питание") delay_ms(1000); //для настройки STM //Инициализация модуля MSSP(режим SPI) SSPCON1=0x31; SSPSTAT=0; //0x80; SSPBUF=0x55; //иниц. таймеров: //t0con=0xc8; //8-ми разр t0con=0x88; //16-ми разр счетчик T1CON=0x85; setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); set_timer1(62286); set_timer0(64536); //enable_interrupts(INT_TIMER2); enable_interrupts(INT_TIMER1); enable_interrupts(INT_TIMER0); enable_interrupts(GLOBAL); //СОСТОЯНИЕ кнопок и ручек по ВКЛЮЧЕНИЮ: //---------------------------------------- for (ii=0; ii<6;ii++) { du_pA=porta&0xc0|mask[ii]; output_a(du_pA); pr_state_rb[ii] = input_b(); } while(1) { for (ii=0; ii<6;ii++) { pr_ruk=0; // output_a(mask[ii]); //SL... -> PORTA du_pA=porta&0xc0|mask[ii]; output_a(du_pA); tek_state_rb[ii] = input_b(); if (pr_state_rb[ii] ^ tek_state_rb[ii]) //возможно нажатие или вращение ? { if ((tek_state_rb[ii]&mask_kn[ii])!=mask_kn[ii]) //если это кнопка, то отрабат. дребезг { //кнопка delay_ms(1); tek1_state_rb = input_b(); delay_ms(1); tek2_state_rb = input_b(); delay_ms(1); tek3_state_rb = input_b(); // if (tek_state_rb[ii] == tek3_state_rb) //дребезг зак.-есть нажатие/отжатие или вращение! } else //ручка { tek3_state_rb=tek_state_rb[ii]; } if (tek_state_rb[ii] == tek3_state_rb) //дребезг зак.-есть нажатие/отжатие или вращение! switch(ii) //номер сигнала SL0,SL1,SL2,SL3,SL4,SL5 { case 0: //SL0 //Кнопки K1, Ser: if (!(tek3_state_rb & (1 << 0))) { buf_per=0x81; //№1-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 0))); //отжатие произошло while (buf_per!=0) {} buf_per=0x01; //№1-отж. break; } if (!(tek3_state_rb & (1 << 5))) { buf_per=0x82; //№2-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 5))); //отжатие произошло while (buf_per!=0) {} buf_per=0x02; //№2-отж. break; } //Ручки -B_K1, +B_K1 -Sm_K1, +Sm_K1: //*********************************** if ((tek3_state_rb & 0x02)&&(tek3_state_rb & 0x04)) //RB1 & RB2==1 { for (ib=0; ib<2;ib++) { if ((tek3_state_rb & (0x02 << ib)) && (!(pr_state_rb[ii] & (0x02 << ib)))) switch(ib) { case 0: pr_ruk=1; buf_per=0x14; //№20-влево break; case 1: pr_ruk=1; buf_per=0x94; //№20-вправо break; }//switch } //for ib } //if // else // { if ((tek3_state_rb & 0x08)&&(tek3_state_rb & 0x10)&& (!pr_ruk)) //RB3 & RB4==1 & pr_ruk=0 { for (ib=0; ib<2;ib++) { if ((tek3_state_rb & (0x08 << ib)) && (!(pr_state_rb[ii] & (0x08 << ib)))) switch(ib) { case 0: { buf_per=0x15; //№21-влево break; } case 1: { buf_per=0x95; //№21-вправо break; } }//switch ib } //for } //if // } //else pr_state_rb[ii]=tek3_state_rb; pr_ruk=0; break; case 1: //SL1 //Кнопки K2, DISP: if (!(tek3_state_rb & (1 << 0))) { buf_per=0x83; //№3-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 0))); //отжатие произошло while (buf_per!=0) {} buf_per=0x03; //№2-отж. break; } if (!(tek3_state_rb & (1 << 5))) { buf_per=0x84; //№4-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 5))); //отжатие произошло while (buf_per!=0) {} buf_per=0x04; //№4-отж. break; } //Ручки -B_K2, +B_K2 -Sm_K2, +Sm_K2: //*********************************** if ((tek3_state_rb & 0x02)&&(tek3_state_rb & 0x04)) //RB1 & RB2==1 { for (ib=0; ib<2;ib++) { if ((tek3_state_rb & (0x02 << ib)) && (!(pr_state_rb[ii] & (0x02 << ib)))) switch(ib) { case 0: pr_ruk=1; buf_per=0x16; //№22-влево break; case 1: pr_ruk=1; buf_per=0x96; //№22-вправо break; }//switch } //for } //if // else // { if ((tek3_state_rb & 0x08)&&(tek3_state_rb & 0x10) && (!pr_ruk)) //RB3 & RB4==1 & (!pr_ruk) { for (ib=0; ib<2;ib++) { if ((tek3_state_rb & (0x08 << ib)) && (!(pr_state_rb[ii] & (0x08 << ib)))) switch(ib) { case 0: { buf_per=0x17; //№23-влево break; } case 1: { buf_per=0x97; //№23-вправо break; } }//switch } //for } //if // } //else // pr_state_rb[ii]=tek3_state_rb; pr_ruk=0; break; case 2: //SL2 //Кнопки Raz, Pam: if (!(tek3_state_rb & (1 << 0))) { buf_per=0x85; //№5-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 0))); //отжатие произошло while (buf_per!=0) {} buf_per=0x05; //№5-отж. break; } if (!(tek3_state_rb & (1 << 5))) { buf_per=0x86; //№6-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 5))); //отжатие произошло while (buf_per!=0) {} buf_per=0x06; //№6-отж. break; } //Ручки -T, +T -Del, +Del: //*********************************** if ((tek3_state_rb & 0x02)&&(tek3_state_rb & 0x04)) //RB1 & RB2==1 { for (ib=0; ib<2;ib++) { if ((tek3_state_rb & (0x02 << ib)) && (!(pr_state_rb[ii] & (0x02 << ib)))) switch(ib) { case 0: pr_ruk=1; buf_per=0x18; //№24-влево break; case 1: pr_ruk=1; buf_per=0x98; //№24-вправо break; }//switch } //for } //if // else { if ((tek3_state_rb & 0x08)&&(tek3_state_rb & 0x10) && (!pr_ruk)) //RB3 & RB4==1 & (!pr_ruk) { for (ib=0; ib<2;ib++) { if ((tek3_state_rb & (0x08 << ib)) && (!(pr_state_rb[ii] & (0x08 << ib)))) switch(ib) { case 0: { buf_per=0x19; //№25-влево break; } case 1: { buf_per=0x99; //№25-вправо break; } }//switch } //for } //if } //else // pr_state_rb[ii]=tek3_state_rb; pr_ruk=0; break; case 3: //SL3 //Кнопки Sinch, Pusk, Kurs, Izm: if (!(tek3_state_rb & (1 << 0))) { buf_per=0x87; //№7-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 0))); //отжатие произошло while (buf_per!=0) {} buf_per=0x07; //№7-отж. break; } if (!(tek3_state_rb & (1 << 3))) { buf_per=0x88; //№8-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 3))); //отжатие произошло while (buf_per!=0) {} buf_per=0x08; //№8-отж. break; } if (!(tek3_state_rb & (1 << 4))) { buf_per=0x89; //№9-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 4))); //отжатие произошло while (buf_per!=0) {} buf_per=0x09; //№9-отж. break; } if (!(tek3_state_rb & (1 << 5))) { buf_per=0x8A; //№10-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 5))); //отжатие произошло while (buf_per!=0) {} buf_per=0x0A; //№10-отж. break; } //Ручки -Ur, +Ur : //**************** if ((tek3_state_rb & 0x02)&&(tek3_state_rb & 0x04)) //RB1 & RB2==1 { for (ib=0; ib<2;ib++) { if ((tek3_state_rb & (0x02 << ib)) && (!(pr_state_rb[ii] & (0x02 << ib)))) switch(ib) { case 0: buf_per=0x1A; //№26-влево break; case 1: buf_per=0x9A; //№26-вправо break; }//switch } //for } //if // pr_state_rb[ii]=tek3_state_rb; break; case 4: // SL4 //Кнопки Pit, Sbor: if (!(tek3_state_rb & (1 << 0))) { buf_per=0x8B; //№11-наж. if (pr_wkl_pit==0) { pit_bkl(); } break; } if (!(tek3_state_rb & (1 << 5))) { buf_per=0x8C; //№12-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 5))); //отжатие произошло while (buf_per!=0) {} buf_per=0x0C; //№12-отж. break; } //Ручки -Ur, +Ur : //**************** if ((tek3_state_rb & 0x02)&&(tek3_state_rb & 0x04)) //RB1 & RB2==1 { for (ib=0; ib<2;ib++) { if ((tek3_state_rb & (0x02 << ib)) && (!(pr_state_rb[ii] & (0x02 << ib)))) switch(ib) { case 0: buf_per=0x1B; //№27-влево break; case 1: buf_per=0x9B; //№27-вправо break; }//switch } //for } //if // pr_state_rb[ii]=tek3_state_rb; break; case 5: //SL5 //Кнопки Men,"1", "2", "3", "4", "5": if (!(tek3_state_rb & (1 << 0))) { buf_per=0x8D; //№13-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 0))); //отжатие произошло while (buf_per!=0) {} buf_per=0x0D; //№13-отж. break; } if (!(tek3_state_rb & (1 << 1))) { buf_per=0x8e; //№14-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 1))); //отжатие произошло while (buf_per!=0) {} buf_per=0x0e; //№14-отж. break; } if (!(tek3_state_rb & (1 << 2))) { buf_per=0x8f; //№15-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 2))); //отжатие произошло while (buf_per!=0) {} buf_per=0x0f; //№15-отж. break; } if (!(tek3_state_rb & (1 << 3))) { buf_per=0x90; //№16-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 3))); //отжатие произошло while (buf_per!=0) {} buf_per=0x10; //№16-отж. break; } if (!(tek3_state_rb & (1 << 4))) { buf_per=0x91; //№17-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 4))); //отжатие произошло while (buf_per!=0) {} buf_per=0x11; //№17-отж. break; } if (!(tek3_state_rb & (1 << 5))) { buf_per=0x92; //№18-наж. do tek3_state_rb = input_b(); while (!(tek3_state_rb & (1 << 5))); //отжатие произошло while (buf_per!=0) {} buf_per=0x12; //№18-отж. break; } pr_state_rb[ii]=tek3_state_rb; break; }//switch(ii) pr_state_rb[ii]=tek3_state_rb; }//if }//for (ii) }//while(1) //output_bit(PIN_C3,1); //BUF_CAP[i-1]=input(PIN_C4); //output_bit( PIN_B2, 0); //Ldac в 0 //level = input_state(pin_A3); } //main
void main(){ setup_oscillator (OSC_8MHZ); setup_timer_1(T1_DISABLED); setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); // Give indiction that the microcontroller is up and running for (i=0;i<5;i++){ blink(); } //On boot interactive mode is on so that the user can use a terminal interface interactive = 1; //Main loop starts here... while(true){ //Waits for a command to come in over the serial port in interactive mode if (interactive == 1) printf("Please enter a command (h for help):\n\r"); command = getc(); switch (command){ case 'i': //Turn off interactive mode printf("Turning Off Interactive...\n\r"); interactive = 0; printf("Done...\n\r"); break; case 'r': //Reset DS2482 if (interactive == 1){ printf("Resetting the DS2482\n\r"); } //Do the Reset result = ds2482_reset(); if (interactive == 1){ if (result == 1) printf("...Success...\n\r"); else printf ("...Fail..\n\r"); } break; case 'c': //Configure DS2482 //Active pullup should always be selected unless //there is only a single slave on the 1-Wire line. //0x01 1WS Disabled, SPU Disabled, 0 NC, APU Active Pullup (Normal Operation for more then one device on onewire bus) //0x05 1WS Disabled, SPU Active, 0 NC, APU Active Pullup (Strong pullup is commonly used with 1-Wire parasitically powered temperature sensors, eeprom, A/D converters) if (interactive == 1){ printf("Configuring the DS2482\n\r"); } //Do the Config result = ds2482_write_config(0x01); if (interactive == 1){ if (result == 1) printf("...Success...\n\r"); else printf ("...Fail..\n\r"); } break; case 'R': //Reset One Wire Bus if (interactive == 1){ printf("Resetting the One Wire\n\r"); } result = OWreset(); if (interactive == 1){ if (result == 1) printf("...Success...\n\r"); else printf ("...Fail..\n\r"); } break; case 'n': //Read the Network Address OWreset(); delay_ms(1); OWWriteByte("33"); //delay_ms(20); for(i=0; i<=7; i++) { result = OWReadByte(); printf ("%2X",result); delay_ms(1); } break; case 's': //Read the OW status register OWreset(); delay_ms(1); OWWriteByte(204); //Transmit skip Rom Command CC = 204 OWWriteByte(105); //0x69 Transmit Read RAM command OWWriteByte(1); //Transmit Read start address result=OWReadByte(); break; case 'f': //Fix the floating power switch OWreset(); OWWriteByte(0xCC); OWWriteByte(0x6C); //Write Data Command OWWriteByte(0x31); //Eeprom address but actually gets written to Shadow Ram OWWriteByte(0xE7); //Value to make PMOD1 SWEN=0 RNAOP=0 //Copy the shadow Ram written above over to actual EEPROM OWreset(); OWWriteByte(0xCC); OWWriteByte(0x48); //send the copy command OWWriteByte(0x30); //copy shadow ram to the block containing 31 break; default: //Displays help message if you get an 'h' or an unknown command printf("PyroLogger Board Found and Responding...\n\r"); printf("Firmware Version 2\n\r"); printf("Interactive Mode is ON\n\r"); printf("\n\r"); printf("\n\r"); printf("Command List:\n\r"); printf("h = System Help\n\r"); printf("i = Exit ineractive mode\n\r"); printf("r = Reset DS2482\n\r"); printf("c = Configure DS2482\n\r"); printf("R = Reset One Wire Bus\n\r"); printf("N = Print Net Address\n\r"); } } }
//==================================== void main() { int16 local_ccp_delta; got_pulse_width = FALSE; first_press = TRUE; //DAC_address = 0xC4; //Address of the DAC don't ever forget this please DAC_address = 0xC0; //I2C Address of parts with marking AJ //Oscillator Config //setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_ON); //I am giving it all shes got, she can't take any more Captain //setup_oscillator(OSC_500KHZ|OSC_INTRC|OSC_PLL_OFF); //Can measure a little over 4 seconds with timer1 setup_oscillator(OSC_2MHZ|OSC_INTRC|OSC_PLL_OFF); //Can measure a little over 1 second with timer1 Use this one //Capture Compare Config setup_CCP1(CCP_CAPTURE_FE); //Sets up Capture Compare for Falling Edge - Reads Tap Input bit_set(APFCON,0); //Set CCP1 Pin to A5 instead of A2 //ADC Config SETUP_ADC(ADC_CLOCK_INTERNAL); SETUP_ADC_PORTS(sAN3); //Analog in on RA4 set_adc_channel(3); delay_us(10); setup_timer_1(T1_INTERNAL | T1_DIV_BY_8 ); setup_timer_2(T2_DIV_BY_16 , 31, 1); //Need a real understanding of what this lines does here enable_interrupts(INT_CCP1); enable_interrupts(INT_TIMER2); enable_interrupts(GLOBAL); //DAC Test Code //setVoltage(4095, FALSE); //Sets DAC output to Max voltage //setVoltage(0, FALSE); mode = 1; //Start off in POT mode while(1) { pot_val = read_adc(); //Read the ADC everytime if (mode == 1){ //We are in POT mode just set the value pot_save = pot_val; setVoltage(pot_val * 4, FALSE); //scale to 12bit DAC } if (((pot_val > pot_save + 10 && mode ==0)) || ((pot_val < pot_save - 10) && (mode == 0))){ //We are in TAP mode only set voltage if POT moves a lot mode = 1; //Jump out of tap mode and enter pot mode } if(got_pulse_width) { disable_interrupts(GLOBAL); local_ccp_delta = ccp_delta; enable_interrupts(GLOBAL); pulse_width_ms = local_ccp_delta / 62; //2E-6 per tick * 8 Prescale = 1.6E-5 so .001 / 1.6E-5 = 62.5 got_pulse_width = FALSE; // For Testing set Pulse width ms here // pulse_width_ms = 524; LUT_count = 1; while (millisecond_delay[LUT_count] >= pulse_width_ms){ LUT_count = LUT_count + 1; } calculated_voltage = map(pulse_width_ms, millisecond_delay[LUT_count - 1], millisecond_delay[LUT_count] , dac_out[LUT_count-1],dac_out[LUT_count]); // printf("%lu ms \n\r", pulse_width_ms); //Debug Message // printf("%lu dac \n\r", calculated_voltage); //Debug Message setVoltage(calculated_voltage,FALSE); mode = 0; //Set Mode to tap mode, requires larger movement of POT to break out } } }
void main(){ setup_oscillator( OSC_8MHZ ); //setup_adc_ports(sAN6|VSS_VDD); setup_adc(ADC_CLOCK_INTERNAL); //setup_counters(RTCC_INTERNAL,RTCC_DIV_1); //setup_timer_1(T1_DISABLED); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); state0 = read_eeprom (0); state1 = read_eeprom (1); state2 = read_eeprom (2); //Test the LEDs /* while (1){ output_low(LED0); output_low(LED1); output_low(LED2); delay_ms(1000); output_high(LED0); output_high(LED1); output_high(LED2); delay_ms(1000); } */ //The LEDs are an active High because of the NPN transistor driving the low side if (state0 == 1) output_high(LED0); if (state1 == 1) output_high(LED1); if (state2 == 1) output_high(LED2); //The buttons are an active high to avoid problems with powerdown causing false triggers // while(true) { if(input(button0)){ //Toggle the LED output_toggle(LED0); while (input(button0)){} //Stay right here until button is released //We know button was pressed and released state0 = !state0; write_eeprom(0, state0); } if(input(button1)){ //Toggle the LED output_toggle(LED1); while (input(button1)){} //Stay right here until button is released //We know button was pressed and released state1 = !state1; write_eeprom(1, state1); } if( input(button2) ){ output_toggle(LED2); while (input(button2)){} //Stay right here until button is released //We know button was pressed and released state2 = !state2; write_eeprom(2, state2); } } }
int main (void) { int i=0; tmp_debug = 0; //Setup oscillator/ports/pins first setup_oscillator(); setup_ports(); setup_peripheral_pin_select(); setup_interrupt_priorities(); //init_temperature_model(); //Blinking HB LED and Timestamp #ifdef USE_DIO setup_dio(); #endif //ToDo Used? #ifdef USE_TIMER1 setup_timer1(); //do before setup_pwm #endif //ToDo: there was a missing #endif, maybe that's why disabling Timer1 was breaking the code! //Motor control PWM #ifdef USE_PWM //setup_pwm(); #endif //Brushless motor #ifdef USE_BLDC setup_bldc(); #endif //Torque PID and Current PID #ifdef USE_CONTROL setup_control(); #endif //Analog to Digital #ifdef USE_ADC setup_adc(); #endif //Torso external ADC #ifdef USE_ADC_SPI setup_adc_spi(); #endif //Current measurment, control and limitation #ifdef USE_CURRENT setup_current(); #endif //ToDo: Remvove? #ifdef USE_TIMER3 setup_timer3(); #endif //VerteX SPI Encoder #ifdef USE_ENCODER_VERTX setup_vertx(); #endif //Torso motor brake #ifdef USE_BRAKE setup_brake(); #endif //EtherCAT Communication #ifdef USE_ETHERCAT while (!eeprom_loaded()) //Wait until ESC is ready SetHeartbeatLED; setup_ethercat(); ClrHeartbeatLED; #endif setup_interrupt_priorities(); if (RCONbits.WDTO) SetHeartbeatLED; //RCONbits.SWDTEN = 1;//enable watchdog timer if (RCON & 0x03 == 0x03) { RCONbits.BOR = 0; RCONbits.POR = 0; } rcon_reg = RCON; while(1) { if (i++%10001==0) { //ToggleHeartbeatLED(); #if defined USE_ETHERCAT step_ethercat(); #endif } } }
void main(){ setup_oscillator( OSC_8MHZ ); setup_adc_ports(sAN6|VSS_VDD); setup_adc(ADC_CLOCK_INTERNAL); setup_counters(RTCC_INTERNAL,RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); //Software workaround for the power switch floating onewire_init(); onewire_sendbyte(0xCC); onewire_sendbyte(0x6C); //Write Data Command onewire_sendbyte(0x31); //Eeprom address but actually gets written to Shadow Ram onewire_sendbyte(0xE7); //Value to make PMOD1 SWEN=0 RNAOP=0 //Copy the shadow Ram written above over to actual EEPROM onewire_init(); onewire_sendbyte(0xCC); onewire_sendbyte(0x48); //send the copy command onewire_sendbyte(0x30); //copy shadow ram to the block containing 31 while(true){ /*------------------------------------------------------------------- Pull Reading From Temp Probe -------------------------------------------------------------------*/ //Use the following to determine the state of the one wire net //Will report if device present, not, or shorted //Comment out rest of code //onewire_init_with_error_check(); //read_status(); //printf("status byte is ====>(%x)\n\r",status); printf("Please enter a command (h for help):\n\r"); command = getc(); //Gets a key from the keyboard switch (command){ case 'h' : printf("Type any of the following commands:\n\r"); printf("h This Help Message\n\r"); printf("C Ambiant Temp in deg. C\n\r"); printf("c Ambiant Temp in deg. C(No Formatting)\n\r"); printf("F Ambiant Temp in deg. F\n\r"); printf("f Ambiant Temp in deg. F(No Formatting)\n\r"); printf("N 64 bit node address in Hex\n\r"); printf("K Thermo millivolts\n\r"); printf("k Thermo millivolts(No Formatting)\n\r"); printf("s One line scroll test\n\r"); break; case 'C' : read_temp(); printf(" deg C===>(%3.2f)\n\r",temp_float); break; case 'c' : read_temp(); printf("%3.2f\n\r",temp_float); break; case 'F' : read_temp(); printf(" deg F===>(%3.2f)\n\r",temp_float_faren); break; case 'f' : read_temp(); printf("%4.2f",temp_float_faren); break; case 'K' : read_current(); printf("mV===>(%4.3f)\n\r",current_float); break; case 'k' : read_current(); printf("%4.3f\n\r",current_float); break; case 's' : scroll_test(); break; default : printf("Not a valid command:\n\r"); } delay_ms(1000); } }