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 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
}
Пример #3
0
/*
 * Setup counters for all tiles in cpu set
 */ 
int setup_all_counters(cpu_set_t *cpus) {
    int num_of_cpus = tmc_cpus_count(cpus);
    for (int i=0;i<num_of_cpus;i++) {
        if (tmc_cpus_set_my_cpu(tmc_cpus_find_nth_cpu(cpus, i)) < 0) {
            tmc_task_die("failure in 'tmc_set_my_cpu'");
            return -1;
        }
        clear_counters();
        setup_counters(LOCAL_WR_MISS, LOCAL_WR_CNT, LOCAL_DRD_MISS, LOCAL_DRD_CNT);
    }
    return 0; 
}
Пример #4
0
void main()
{
	set_tris_a(0xFE);
	output_low(PIN_A0);
	setup_counters(RTCC_INTERNAL,RTCC_DIV_16);
	set_timer0(6);
	enable_interrupts(GLOBAL);
	enable_interrupts(INT_TIMER0);
	do
	{
		
	}while(TRUE);		
}	
Пример #5
0
main() {

   char scale;
   byte time;

   do {
      scale = get_scale();

      if(scale=='S')
         setup_counters( RTCC_INTERNAL, RTCC_DIV_64 );
      else
         setup_counters( RTCC_INTERNAL, RTCC_DIV_256 );

      printf("\n\rWaiting...\n\r");

      wait_for_low_to_high();
      set_rtcc(0);
      wait_for_low();
      time = get_rtcc();

      printf("Counter value: %2X\n\n\r", time);

   } while (TRUE);
}
Пример #6
0
int main(void)
{
    // initalize global variables
    start = 0;
    delay1 = 5;
    delay2 = 10;
    delay3 = 3;
    timesec = 0;

    startupPIC();
    initalizePIC();
    setup_counters();

    initAnalogInput();
    initMagnets();


    while(1) {
        if(start) {
            EMAG2=0;
            SetDCOC4PWM(100);
            delaysec(delay1);
            SetDCOC4PWM(1000);
            delaysec(delay2);
            SetDCOC4PWM(500);
            delaysec(delay3);
            EMAG2=1;
            SetDCOC4PWM(0);

//            EMAG1=0;
//            SetDCOC4PWM(900);
//            DIR = 0;
//            delaysec(delay1);
//            SetDCOC4PWM(0);
//            delaysec(delay2);
//            SetDCOC4PWM(700);
//            delaysec(delay1);
//            SetDCOC4PWM(1000);
//            EMAG1=1;

            start=0;
        }
    }
}
Пример #7
0
void initPIC() {
    SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL);

    initLEDs();
    initSerialNU32v2();

    // Setup and turn off electromagnets
    EMAG1 = 0;
    EMAG2 = 0;
    TRISEbits.TRISE7 = 0;
    TRISCbits.TRISC1 = 0;

    // Direction Output
    DIR = 1;
    TRISAbits.TRISA9 = 0;

    setup_counters();

    CloseADC10();
#define PARAM1  ADC_MODULE_ON | ADC_FORMAT_INTG | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON
#define PARAM2  ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_ON | ADC_SAMPLES_PER_INT_16 | ADC_ALT_BUF_OFF | ADC_ALT_INPUT_OFF
#define PARAM3  ADC_CONV_CLK_INTERNAL_RC | ADC_SAMPLE_TIME_31
#define PARAM4  ENABLE_AN0_ANA | ENABLE_AN1_ANA | ENABLE_AN2_ANA | ENABLE_AN3_ANA | ENABLE_AN5_ANA | ENABLE_AN15_ANA
    OpenADC10(PARAM1, PARAM2, PARAM3, PARAM4, 0);
    EnableADC10();

    // 20kHz PWM signal, duty from 0-1000, pin D3
    OpenTimer2(T2_ON | T2_PS_1_4, MAX_DUTY);
    OpenOC4(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);
    SetDCOC4PWM(0);

    // 200 Hz ISR
    OpenTimer3(T3_ON | T3_PS_1_256, (6250/4 - 1));
    //OpenTimer3(T3_ON | T3_PS_1_256, (62500 - 1));
    mT3SetIntPriority(1);
    mT3ClearIntFlag();
    mT3IntEnable(1);

    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
    INTEnableSystemMultiVectoredInt();
}
Пример #8
0
void init() {
   unsigned int16 i;

   blink();

   init_queue(&rxque0);
   init_queue(&txque0);

   set_step(1);		// 0=full, 1=1/2, 5=1/4, 4=1/8, 7=1/16
   enable(1);

   //setup_counters(T0_INTERNAL, T0_DIV_1 | T0_8_BIT);
   setup_counters(T0_INTERNAL, T0_DIV_2 | T0_8_BIT);

   set_timer0(0);

   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

   output_bit(CTS,0);		// ready to receive from usb
   output_bit(STROBE,1);	// parallel port strobe

   // input(PIN_C3);		// ESTOP
   input(PIN_C4);		// ALIM
   input(PIN_C0);		// XLIM
   input(PIN_C1);		// YLIM
   
   // input(PIN_C2);		// ZLIM
   output_bit(PIN_C2,0);	// changed from ZLIM to PWM OUTPUT

   setup_ccp1(CCP_PWM);
   setup_timer_2(T2_DIV_BY_16, 255, 1); // mode, period, postscale
   set_timer2(0);
   set_pwm1_duty(0);		// duty cycle is val/(4*(255+1))
}
Пример #9
0
int main(void) {
	timesec=0;
	// set PIC32 to max computing power
	SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL);
	INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
	INTEnableSystemMultiVectoredInt();   
    initLEDs(); 	
    LED0 = 1;
    LED1 = 1;
    initSerialNU32v2();
	setup_counters();

  	CloseADC10();
  	#define PARAM1  ADC_MODULE_ON | ADC_FORMAT_INTG | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON
  	#define PARAM2  ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_ON | ADC_SAMPLES_PER_INT_16 | ADC_ALT_BUF_OFF | ADC_ALT_INPUT_OFF
  	#define PARAM3  ADC_CONV_CLK_INTERNAL_RC | ADC_SAMPLE_TIME_31
  	#define PARAM4  ENABLE_AN0_ANA | ENABLE_AN1_ANA | ENABLE_AN2_ANA | ENABLE_AN3_ANA | ENABLE_AN5_ANA | ENABLE_AN15_ANA
  	OpenADC10( PARAM1, PARAM2, PARAM3, PARAM4,0);
  	EnableADC10();


    // Setup and turn off electromagnets
    EMAG1 = 0; EMAG2 = 0; 
    TRISEbits.TRISE7 = 0; TRISCbits.TRISC1 = 0;
	//Direction Output
	DIR = 1;
  	TRISAbits.TRISA9 = 0;
	//g-select Outputs
	GSEL1 = 0; GSEL2 = 0;
  	TRISEbits.TRISE2 = 0; TRISCbits.TRISC13= 0;
  	//0g Inputs
  	TRISAbits.TRISA0 = 1;
  	TRISAbits.TRISA4 = 1;

  	// 20kHz PWM signal, duty from 0-1000, pin D3
  	OpenTimer2(T2_ON | T2_PS_1_4, 1000);
  	OpenOC4(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);
  	HBridgeDuty = 0;
  	SetDCOC4PWM(HBridgeDuty);

    // 20Hz ISR
    OpenTimer3(T3_ON | T3_PS_1_256, 15625);
    mT3SetIntPriority(1);
    mT3ClearIntFlag();
    mT3IntEnable(1);


	while(1) {
		if(start){
			EMAG2=0;
			SetDCOC4PWM(100);
			delaysec(delay1);
			SetDCOC4PWM(1000);		
			delaysec(delay2);
			SetDCOC4PWM(500);
			delaysec(delay3);
			EMAG2=1;
			SetDCOC4PWM(0);	

//			EMAG1=0;
//			SetDCOC4PWM(900);
//			DIR = 0;
//			delaysec(delay1);
//			SetDCOC4PWM(0);
//			delaysec(delay2);
//			SetDCOC4PWM(700);
//			delaysec(delay1);
//			SetDCOC4PWM(1000);
//			EMAG1=1;

			start=0;
		}
	}
}
Пример #10
0
void main()
{
   set_timer0(0);
   setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);
   //ext_int_edge(H_TO_L);
   //enable_interrupts(INT_EXT);
   //enable_interrupts(GLOBAL);
   //Cai dat vao ra
     trisa = 0xff;
     trisb = 0x00;
     trisc = 0xff;
     trisd = 0xff;
     trisd = 0x00;
     trise=   0x00;
     output_d(0x00);
   // TODO: USER CODE!!
   lcd_init();
   welcome();
   denbao = 0x00;
   Open_temp = false;   //Bien trung gian bao dang thuc hien mo cua
   Close_temp = false;  //Bien trung gian bao dang thuc hien dong cua
   Slide_Open_temp = false;
   Slide_Close_temp = false;
   error_open_slide = false;//Kiem tra loi khi dong cua.
   error_close_slide = false;  
   temp_quetlcd = 7;    //Cai dat ban dau se kiem tra vi tri cua.
   keyCode = 0;
  /* xoadong(1);
   lcd_putc(thongbao[0]);
   delay_ms(3000);
   xoadong(1);
   lcd_putc(thongbao[1]);
   delay_ms(3000);
   lcd_putc(thongbao[2]);
   delay_ms(3000);*/
   while(1)
     {
         if(SW_Emergency != 0){
            kiemtra_vitri();
            if(Open == 0) {
               program_Open();
            }else if(Close == 0){
               program_Close();
            }else if(Semi_Open == 0){
               program_Open_Semi();
            }else if(Open_Slide == 0){
               program_Open_Slide();
            }else if(Close_Slide == 0){
               program_Close_Slide();
            } else if(Stop == 0) {
               bit_clear(denbao,7);
               quangbao();
               D7 = 0;
               xuat_E0();
               temp_quetlcd = 7;    //Cai dat ban dau se kiem tra vi tri cua.
            }
            switch(keyCode)
               {
                  case 1: program_Close_Slide();Break;
                  case 2: program_Open_Slide();Break;
                  case 3: program_Close();Break;
                  case 4: program_Open();Break;
               }
           bit_clear(denbao,6);
           quangbao();
         } else {
            lcd_gotoxy(1,1);
            lcd_putc("<-  EMERGENCY...  ->");
            lcd_gotoxy(1,2);
            lcd_putc(" DUNG MOI THAO TAC ");
            denbao = 0x40;
            quangbao();
            temp_quetlcd = 7;    //Cai dat ban dau se kiem tra vi tri cua.
         }
     //printf(lcd_putc," keyCode = %u",debug);
     }
}
Пример #11
0
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);
}
}