void main(void) { init_pins(); init_oscillator(); SPI1_Initialize(); float temp = 0; // Set all pins RD1-7 to inputs, RD0 (MSB is set to output) //TRISD = 0b11111110; // RC2 is PWM pin TRISCbits.RC2 = 0; configure_adc(); configure_pwm(); int ticks = 0; while (1) { MAX_7221_INIT(); temp = get_temperature(0); set_fan_speed(temp); if(ticks % 125 == 0) { MAX_7221_WRITE_FLOAT(temp, 3); ticks = 0; } ticks++; } }
void main(void){ init_general();// Set general runtime configuration bits init_gpio_pins(); // Set all I/O pins to low outputs init_oscillator(0);// Initialize oscillator configuration bits init_timer2();// Initialize timer2 (millis) init_adc(NULL); // Initialize ADC module init_termination(NOT_TERMINATING); init_adcs();// Initialize all of the ADC's init_can(); // Initialize CAN canAnalogMillis = canDiagMillis = 0; ADCCON3bits.GSWTRG = 1; // Initial ADC Conversion? STI();// Enable interrupts while(1){ update_analog_channels(); strain_calc(); if(millis - canAnalogMillis >= CAN_ANALOG_INTV){ CANAnalogChannels(); canAnalogMillis = millis; } if(millis - canDiagMillis >= CAN_DIAG_INTV){ CANdiag(); canDiagMillis = millis; } sample_temp(); // Sample internal and external temperature sensors } }
int main(void) { SREG = 0x80; /*ENABLE GLOBAL INTERRUPTS*/ init_oscillator(); init_usart(); init_twi(); //TWI_MASTER_t twi; //PMIC_CTRL= //interrupt PORTC.DIR |= PIN6_bm; if(( TWIC_MASTER_STATUS & TWI_MASTER_BUSSTATE_gm) == TWI_MASTER_BUSSTATE_IDLE_gc) { //TWIC_MASTER_ADDR =0x00; TWIC_MASTER_CTRLC = TWI_MASTER_CMD_REPSTART_gc; //TWIC_MASTER_CTRLC = TWI_MASTER_CMD_NOACT_gc; //read data TWIC_MASTER_ADDR = 0xEC; // R/W bit low to write the reg number from where we want to read TWIC_MASTER_ADDR = 0xA0; TWIC_MASTER_CTRLC = TWI_MASTER_CMD_REPSTART_gc; TWIC_MASTER_ADDR = 0xED; // R/W bit high indicating a read operation TWIC_MASTER_CTRLC = TWI_MASTER_CMD_STOP_gc; int DATA=TWIC_MASTER_DATA; //sendChar(DATA); uint16_t buffer; itoa(DATA, buffer, 10); sendString(buffer); sendString("\n"); } //while(TWIC_MASTER_STATUS & 0x10) //ack/NACK recieved from slave // TWIC_MASTER_ADDR =0x00; // _delay_ms(100); // TWIC_MASTER_ADDR = 0xE7; // TWIC_MASTER_ADDR = 0xE5; // _delay_ms(100); // TWIC_MASTER_ADDR = 0xA0; while(1) //for(int i=1; i<=5 ; i++) { PORTC.OUT &= ~PIN6_bm; // sendString("Test\n"); _delay_ms(1000); PORTC.OUT |= PIN6_bm; _delay_ms(1000); //TWIC_MASTER_CTRLC = TWI_MASTER_CMD_REPSTART_gc; int DATA=TWIC_MASTER_DATA; //sendChar(DATA); uint16_t buffer; itoa(DATA, buffer, 10); // sendString(buffer); } }
int main(void){ init_general();// Set general runtime configuration bits init_gpio_pins();// Set all I/O pins to low outputs init_oscillator(0);// Initialize oscillator configuration bits init_timer2();// Initialize timer2 (millis) int i; while(1){ for(i = 0;i<1000000;i++); PIC_LED_LAT = 1; for(i = 0;i<1000000;i++); PIC_LED_LAT = 0; } return 0; }
/* Intializes the hardware and loop. */ void main(void) { DI(); //initialize the oscillator and global timer init_oscillator(OSC_5_52MHZ); init_timer(TIMER_2MS); init_midi_out(); init_buttons(); //enable interrupts EI(); //loop infinitely while(1) { ; } }
/* Intializes the LED, sets the default value, and loops. */ void main(void) { //initialize the hardware init_buttons(); init_speaker(); init_leds(); //initialize the oscillator and global timer init_oscillator(OSC_5_52MHZ); init_timer(TIMER_2MS); //enable interrupts EI(); //run forever while(1) { //do nothing while responding to interrupts } }
/* Intializes the hardware, loop on the CLI. */ void main(void) { DI(); //initialize the oscillator and global timer init_oscillator(OSC_5_52MHZ); init_timer(TIMER_2MS); init_midi_sensors(SENSOR_NOTES, SENSOR_CTRL_1); init_midi_out(); init_buttons(); init_leds(); //initialize the command line interface init_cli(); //enable interrupts EI(); cli_loop(); }
/* * MAIN */ void main(void) { init_oscillator(); TRISAbits.TRISA1 = 1; //input of IR recepter TRISAbits.TRISA2 = 0; //output led TRISAbits.TRISA3 = 0; //output led TRISB = 0; TRISAbits.TRISA4 = 0; //output led unsigned signal_precedent = 1; unsigned code[8]; /* set code to 0 */ init_code(code); /* set outpu to 0 */ OUT1 = 0; OUT2 = 0; GREEN1 = 0;RED1 = 1; GREEN2 = 0;RED2 = 1; while(1) { /* code: 01010101 -> reception: 10101010 */ if( code[0]==1 && code[1]==0 && code[2]==1 && code[3]==0 && code[4]==1 && code[5]==0 && code[6]==1 && code[7]==0 ){ OUT1 = change_out(OUT1); if( OUT1==1 ){GREEN1=1;RED1=0;}else{GREEN1=0;RED1=1;} init_code(code); } /* code: 00011000 -> reception: 11100111 */ else if( code[0]==1 && code[1]==1 && code[2]==1 && code[3]==0 && code[4]==0 && code[5]==1 && code[6]==1 && code[7]==1 ){ OUT2 = change_out(OUT2); if( OUT2==1 ){ GREEN2=1;RED2=0; }else{ GREEN2=0;RED2=1; } init_code(code); } if( RECEP==0 ){ __delay_ms(10); if( RECEP==0 && signal_precedent==1 ){ __delay_ms(1); __delay_us(500); // delay to be at the midle code[0] = RECEP; __delay_ms(1); code[1] = RECEP; __delay_ms(1); code[2] = RECEP; __delay_ms(1); code[3] = RECEP; __delay_ms(1); code[4] = RECEP; __delay_ms(1); code[5] = RECEP; __delay_ms(1); code[6] = RECEP; __delay_ms(1); code[7] = RECEP; signal_precedent = 0; PORTAbits.RA4 = change_out(PORTAbits.RA4); } else{} } else{ signal_precedent=1; } } }
/** * void main(void) * * Main program execution function */ void main(void) { /** * General initialization */ init_unused_pins(); init_oscillator(); init_timer0(); init_timer1(); /** * Initialize I/O pins */ // Init CAN termination pin TERM_TRIS = OUTPUT; TERM_LAT = 1; // Terminating // Init RADIO pins #if FRONT RADIO0_TRIS = INPUT; RADIO1_TRIS = INPUT; #endif #if FRONT // Init FRONT ADC pins ADC_SPFL_TRIS = INPUT; ADC_SPFR_TRIS = INPUT; ADC_BPF_TRIS = INPUT; ADC_BPR_TRIS = INPUT; ADC_STRP_TRIS = INPUT; ADC_APPS0_TRIS = INPUT; ADC_APPS1_TRIS = INPUT; ADC_PTDP_TRIS = INPUT; ADC_UAN0_TRIS = OUTPUT; ADC_UAN0_LAT = 0; #elif REAR // Init REAR ADC pins ADC_SPRL_TRIS = INPUT; ADC_SPRR_TRIS = INPUT; ADC_EOS_TRIS = INPUT; ADC_BCD_TRIS = INPUT; ADC_CTRI_TRIS = INPUT; ADC_CTRO_TRIS = INPUT; ADC_CTSP_TRIS = INPUT; ADC_CPSP_TRIS = INPUT; ADC_MCD_TRIS = INPUT; ADC_UAN0_TRIS = OUTPUT; ADC_UAN0_LAT = 0; ADC_UAN1_TRIS = OUTPUT; ADC_UAN1_LAT = 0; #endif /** * Setup Peripherals */ #if FRONT ANCON0 = 0b11100110; // All analog except for AN0, AN3, AN4 ANCON1 = 0b00000111; // All digital except for AN8, AN9, AN10 #elif REAR ANCON0 = 0b11111111; // All analog ANCON1 = 0b00000111; // All digital except for AN8, AN9, AN10 #endif init_ADC(); ECANInitialize(); // Interrupts setup INTCONbits.GIE = 1; // Global Interrupt Enable (1 enables) INTCONbits.PEIE = 1; // Peripheral Interrupt Enable (1 enables) RCONbits.IPEN = 0; // Interrupt Priority Enable (1 enables) // Main loop while(1) { // Sample and send fast speed sensor channels on CAN send_fast_can(); // Sample and send medium speed sensor channels on CAN send_med_can(); // Sample and send slow speed sensor channels on CAN send_slow_can(); // Send diagnostic CAN message send_diag_can(); #if FRONT if (radio_sw) { RADIO0_TRIS = OUTPUT; RADIO1_TRIS = OUTPUT; RADIO0_LAT = 0; RADIO1_LAT = 0; } else { RADIO0_TRIS = INPUT; RADIO1_TRIS = INPUT; } #endif } }