void main() { BYTE i, j, address, value; int16 q,q1; float p; q1=0; setup_adc_ports(AN0|VSS_VDD); setup_adc(ADC_CLOCK_INTERNAL); set_adc_channel(0); usb_cdc_init(); usb_init(); // while(!usb_cdc_connected()) {} do { usb_task(); if (usb_enumerated()) { delay_ms(500); q = read_adc(); if (q!=q1){ p = 5.0 * q / 1024.0; printf(usb_cdc_putc,"\r Voltage=%01.2fV", p); } q1=q; } } while (TRUE); }
void main () { set_tris_a(0xff);//se pone el puerto RA analogo de entrada set_tris_d(0x00);//se pone el puerto RD en salida para prender los led setup_adc_ports(ALL_ANALOG);//configuracion de los puertos analogos setup_adc(ADC_CLOCK_DIV_32);//el osilador del ADC while (true) { set_adc_channel(0); delay_us(10); valor = read_adc(); if(valor){ output_d(0x01); }else{ output_d(0x00); } set_adc_channel(1); delay_us(10); valor = read_adc(); if{ output_d(0x02); }else{ output_d(0x00); } }
void init_pic() { setup_adc_ports(AN0); setup_adc(ADC_CLOCK_DIV_32); setup_psp(PSP_DISABLED); setup_spi(FALSE); setup_counters( RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_RTCC); enable_interrupts(INT_EXT); enable_interrupts(GLOBAL); EXT_INT_EDGE(L_TO_H); OUTPUT_B(0); OUTPUT_C(0); SET_TRIS_B(0b01000111); //pins B0, B1 and B2 are set to give inputs. b0 is the external interuupt pin SET_TRIS_C(0b00000000); SET_TRIS_D(0b00000000); set_adc_channel(0); //the next read_adc call will read channel 0 }
void main() { setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); TX = 0; RX = 1; TRIS_B = 0x00; while(1) { //putc(getc()); LED = 1; delay_ms(300); LED = 0; delay_ms(300); if(verificaFlag()) { if(recebeByte()) enviaByte('T'); } } }
void main(){ //CHAR letA[]="A"; //CHAR letB[]="B"; //CHAR letC[]="C"; //CHAR espera[]="teste"; setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); glcd_init(ON); //inicializa o display glcd_fillScreen(0); //limpa display inteiro //glcd_text57(34, 55, letA, 1, 1); //glcd_rect(46,53,60,63,1,1); //glcd_text57(48, 55, letB, 1, 0); while(TRUE){ glcd_imagem(1); delay_ms(3000); glcd_fillScreen(0); //limpa display inteiro glcd_imagem(2); delay_ms(3000); glcd_fillScreen(0); //limpa display inteiro } }
main() { int i,value,min,max; printf("Sampling:"); setup_port_a( ALL_ANALOG ); setup_adc( ADC_CLOCK_INTERNAL ); set_adc_channel( 0 ); do { min=255; max=0; for(i=0; i<=30; ++i) { delay_ms(100); value = Read_ADC(); if(value<min) min=value; if(value>max) max=value; } printf("\n\rMin: %2X Max: %2X\r\n",min,max); } while (TRUE); }
//--------------------------------- void main() { //#byte TRISB=0b11000000; SET_TRIS_B(0xC0); //configura PORTB entrada / 0=salida / 1=entrada OUTPUT_D(0x00); //inicializando PORTD en 0x00 //#byte PORTB=0x00; setup_adc_ports(AN0); setup_adc(ADC_CLOCK_INTERNAL); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);//|RTCC_8_bit); //51.2 us overflow // setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //13.1 ms overflow // setup_ccp1(CCP_COMPARE_SET_ON_MATCH); // enable_interrupts(INT_RTCC); enable_interrupts(INT_RTCC); enable_interrupts(GLOBAL); cont=0; comp1=0; while(TRUE) { set_adc_channel(0); delay_ms(1);//tiempo de offset necesario comp1=((read_adc())/1024.0*250.0); delay_ms(1);//tiempo de offset necesario } }
void init_pic() { setup_adc_ports(AN0); setup_adc(ADC_CLOCK_DIV_32); setup_psp(PSP_DISABLED); setup_spi(FALSE); setup_counters( RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_RTCC); enable_interrupts(INT_EXT); enable_interrupts(GLOBAL); EXT_INT_EDGE(L_TO_H); OUTPUT_B(0); OUTPUT_C(0); SET_TRIS_B(0b01000111); //pins B0, B1, B2 and B6 are set to give inputs. B0 is the external interuupt pin //B0, B1 & B2 are used for people counting. B6 for zero crossing detection in fan controlling SET_TRIS_C(0b00000000); SET_TRIS_D(0b00000000); //D port except D0 pin, is used for lcd panel set_adc_channel(0); //the next read_adc call will read channel 0 }
void main() { int16 valor; float tensao; lcd_init(); setup_adc_ports(AN0|VSS_VDD); setup_adc(ADC_CLOCK_DIV_16); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); set_adc_channel(0); //Setup_Oscillator parameter not selected from Intr Oscillator Config tab // TODO: USER CODE!! while(1) { valor = read_adc(); tensao = valor*5.0/1024.0; printf("ADC = %04ld",valor); printf(" Tensao = %.3fV\r", tensao); printf(lcd_putc,"\fADC = %ld",valor); printf(lcd_putc,"\nTensao = %.3fV",tensao); delay_ms(250); } }
void main() { setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF|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|RTCC_8_bit); //RTCC_DIV_32 -> 122 Hz ou 30 Hz por nivel setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_RTCC); enable_interrupts(INT_TIMER1); enable_interrupts(INT_EXT); enable_interrupts(INT_EXT1); enable_interrupts(GLOBAL); set_tris_a (0b11110000); set_tris_c (0b00000000); set_tris_d (0b00000000); while(1){ delay_ms(10); } }
//============================================================================= 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); }
// Setup ports and ADC config void setup() { SET_TRIS_C(0); // Sets PORT C to output only setup_adc_ports(sAN2); setup_adc(adc_clock_internal); set_adc_channel(2); }
int main(void) { BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; Max1.index = -1; Max1.magnitude = 0; Max2.index = -1; Max2.magnitude = 0; // setup the watchdog timer as an interval timer WDTCTL =(WDTPW + // (bits 15-8) password // bit 7=0 => watchdog timer on // bit 6=0 => NMI on rising edge (not used here) // bit 5=0 => RST/NMI pin does a reset (not used here) WDTTMSEL + // (bit 4) select interval timer mode WDTCNTCL + // (bit 3) clear watchdog timer counter // bit 2=0 => SMCLK is the source 2 // bits 1-0 = 10 => source/512 . ); IE1 |= WDTIE; // enable the WDT interrupt (in the system interrupt register IE1) // in the CPU status register, set bits: // GIE == CPU general interrupt enable // LPM0_bits == bit to set for CPUOFF (which is low power mode 0) setup_adc(); init_pwm_timer0(PWM_PERIOD, 0, BIT2); //Pin 2, port of port A. Initially off init_pwm_timer1((PWM_PERIOD*1.5), 0, BIT4); _bis_SR_register(GIE/*+LPM0_bits*/); // after execution of this instruction, the CPU is off! }
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 } } }
void main() { setup_adc_ports(ALL_ANALOG); setup_adc(ADC_CLOCK_INTERNAL); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); // TODO: USER CODE!! set_adc_channel(0); // set ref valus delay_ms(100); ref_0 =read_adc(); delay_ms(100); set_adc_channel(3); // set ref valus delay_ms(100); ref_3 =read_adc(); delay_ms(100); output_b(0b11111111); delay_ms(700); output_b(0); while(1){ set_adc_channel(0); delay_ms(20); // take readings adc_val_0 =read_adc(); delay_ms(20); if(adc_val_0 > ref_0+cons){ l_0 =1; output_high(pin_d7); delay_ms(500); } else{ l_0=0; output_low(pin_d7); // delay_ms(500); } set_adc_channel(3); delay_ms(20); // take readings adc_val_3 =read_adc(); delay_ms(20); if(adc_val_3> ref_3+cons){ l_3 =1; output_high(pin_d6); delay_ms(500); } else{ l_3=0; output_low(pin_d6); } } }
void main() { setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF); setup_spi(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_EXT); ext_int_edge(L_to_H); enable_interrupts(GLOBAL); output_low(PIN_B7); //Setup_Oscillator parameter not selected from Intr Oscillator Config tab // TODO: USER CODE!! while(TRUE) { } }
void main() { setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(FALSE); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); while (TRUE) { printf("\r\nSinyali Baslatmak icin B tusuna basiniz"); if (getchar() == 'b') //eðer b tuþuna basarsan { printf("\n1 hz sinyal aktif edildi\r"); while (1) { output_high(PIN_B0); delay_ms(500); output_low(PIN_B0); delay_ms(500); } } } }
void main() { setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF|ADC_TAD_MUL_0); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_bit); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_RTCC); enable_interrupts(INT_EXT); enable_interrupts(INT_EXT1); enable_interrupts(GLOBAL); set_tris_a (0b11110000); set_tris_b (0b00000000); set_tris_c (0b00000000); cubeLevelC0 = 0xFF; cubeLevelC1 = 0x00; cubeLevelC2 = 0xFF; cubeLevelC3 = 0x00; cubeLevelD0 = 0x00; cubeLevelD1 = 0xFF; cubeLevelD2 = 0x00; cubeLevelD3 = 0xFF; }
void main(void){ int8_t data=0; setup_adc(ADC_CLOCK_DIV_8); //ADCのサンプリング設定 setup_wdt(WDT_1152MS); while(1){ restart_wdt();/* output_high(PIN_A0); output_low(PIN_A1); output_high(PIN_A2); //以上アドレスピン設定 output_low(PIN_A3); output_low(PIN_A4); output_high(PIN_A5); //以上エネーブルピン設定*/ output_a(0b00001111); setup_adc_ports(ALL_ANALOG); set_adc_channel(6); /* ここでADCを適用できるピンと実際に適用するピンを決めます。 ちなみに仕様として各ピンの役割を個別に設定できないようです。 ですがすべてアナログに設定しても問題なくエネーブルピンやアドレスピンは動いてくれているので見なかったことにしましょう。 */ delay_us(20); restart_wdt(); data=read_adc(); setup_adc_ports(NO_ANALOGS);//一応戻しています。 putc((char)data); sleep(); } }
int main(void) { unsigned char ret; DDRB = 0xff; // use all pins on port B for output PORTB = 0x00; // (LED's low & off) i2c_init(); // init I2C interface ret = i2c_start(DevSSD1306+I2C_WRITE); // set device address and write mode if ( ret ) { /* failed to issue start condition, possibly no device found */ i2c_stop(); PORTB=0xff; // activate all 8 LED to show error */ } else { /* issuing start condition ok, device accessible */ setup_i2c(); setup_adc(); } for(;;){ clearBuffer(buffer); // get accelerometer values sample_adc_channel(1); sample_adc_channel(2); sample_adc_channel(3); PORTB=0x00; drawBuffer(0, 0, buffer); PORTB=0xFF; _delay_ms(500); } }
// ** 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 main() { char reponse='a'; int flag=255; int id1=23; int id2=12; int value1=15; int value2=16; int value3=17; //initialisation du PIC setup_adc(ADC_OFF); //on gère toutes les entrées comme étant de type analogique et on mesure les tensions par rapport à une ref 5V enable_interrupts(INT_TIMER2); //configuration des interruptions enable_interrupts(INT_AD); enable_interrupts(GLOBAL); setup_timer_2(T2_DIV_BY_4,250,5); //setup up timer2 to interrupt every 0,1ms can_init(); //initialise le CAN can_set_baud(); //obsolète à priori à tester restart_wdt(); #ifdef DEBUG // Mise en évidence d'un problème lié au Watchdog switch ( restart_cause() ) { case WDT_TIMEOUT: { printf("\r\nRestarted processor because of watchdog timeout!\r\n"); break; } case NORMAL_POWER_UP: { printf("\r\nNormal power up! PIC initialized \r\n"); break; } } restart_wdt(); #endif // BOUCLE DE TRAVAIL while(TRUE) { putc(flag); putc(id1); putc(value1); putc(flag); putc(id1); putc(value2); putc(flag); putc(id2); putc(value3); } }
int main(void) { static unsigned int led_state = 0; RCC_ClocksTypeDef clockinfo; RCC_GetClocksFreq(&clockinfo); // regardless of clock speed this gives us 1000 ticks per second SysTick_Config(clockinfo.SYSCLK_Frequency / 1000); int blink_speed_ms = 400; setup_gpios(); setup_adc(); setup_usart(); setup_button_irqs(); kkputs("hello karl...\n"); uint64_t lasttime = millis(); while (1) { if (millis() - blink_speed_ms > lasttime) { if (led_state & 1) { switch_leds_on(); kkputs("O"); } else { switch_leds_off(); kkputs("o"); } led_state ^= 1; GPIO_TOGGLE(GPIOC, GPIO_Pin_3); lasttime = millis(); } if (button_pressed) { button_pressed = 0; kkputs("button was pressed!\n"); blink_speed_ms >>= 1; if (blink_speed_ms <= 50) { blink_speed_ms = 1000; } } // start and wait for adc to convert... ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_192Cycles); ADC_SoftwareStartConv(ADC1); while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0) ; uint16_t pot_val = ADC_GetConversionValue(ADC1); if (pot_val > 0x700) { GPIO_HIGH(GPIOA, GPIO_Pin_4); } else { GPIO_LOW(GPIOA, GPIO_Pin_4); } } }
int main(void) { network_control(ENABLE); setup_adc(); //setup the ADC while(1) { // Infinite loop iomod_decimal(FIRST_LINE, vcc, 4); // delay_ms(500); } }
void inicializar() { output_low(PIN_B4); output_low(PIN_B5); output_low(PIN_B6); output_low(PIN_B7); setup_adc_ports(RA0_ANALOG); //puerto A0 como entrada analoga setup_adc(adc_clock_internal); //configura el clk interno para el muestreo analogo set_adc_channel( 0 ); //activa el canal a0 delay_us(30); //retardo de 30 micro segundos }
int main(void) { uint8_t i; cli(); MCUSR = 0; wdt_disable(); //TODO replace by an ana comp polling loop _delay_ms(10); setup_datastructs(); setup_led(); setup_ar_uart(); setup_adc(); setup_pulse_input(); setup_analog_comparator(); setup_timer0(); setup_timer1(); // initialize the CTRL buffers ctrlInit(); // initialize the SPI in slave mode setup_spi(SPI_MODE_0, SPI_MSB, SPI_INTERRUPT, SPI_SLAVE); // initialize the Si4421/RFM12 radio and buffers rfm12_init(); // the clk/8 fuse bit is set clock_prescale_set(clock_div_1); FLAG_CLR_ICF1(); sei(); for(;;) { if (spi_status & SPI_NEW_CTRL_MSG) { ctrlDecode(); spi_status &= ~SPI_NEW_CTRL_MSG; } for (i = 0; i < max_analog_sensors; i++) { if (state[i].flags & STATE_POWER_CALC) { calculate_power(&state[i]); state[i].flags &= ~STATE_POWER_CALC; state[i].flags |= STATE_POWER; } } rfm12_tick(); } return 0; }
void InitHardware() { delay_ms(100); setup_adc(ADC_OFF); TRISB = 0x20; // set port B I/O TRISC = 0x00; // set port C I/O NOT_RABPU = 0x00; // allow pull-ups PORTB = 0x00; // set io port initial levels // fire up interrupts enable_interrupts(GLOBAL); // allow all other interrupts }
void bsp_init(void) { set_tris_c(0xff); set_tris_e(0xff); set_tris_a(0x00); output_a(0); set_tris_a(0);//configurado como salida set_tris_e(1); //configurado como entrada SETUP_ADC_PORTS(sAN5); // este pin es analogo SET_ADC_CHANNEL(5); // el canal que usaremos y de cual obtendremos la señal es el 5 setup_adc(ADC_CLOCK_DIV_32); lcd_init(); }
int8 analogRead(int8 _Channel) { int8 _adcReading; setup_adc(ADC_CLOCK_INTERNAL); setup_adc_ports(ALL_ANALOG); set_adc_channel(_Channel); delay_us(10); _adcReading = read_adc(); setup_adc_ports(NO_ANALOGS); return(_adcReading); }
void main() { setup_adc(ADC_OFF); if (input(BOOTLOADER_PIN) && !input(BOOTLOADER_PIN_BIS)) { output_high(LED1); output_high(LED2); bootloader(); } #asm goto RESET_VECTOR #endasm }