void LEDTest4()
{
   int I_B, I_B2, value;
   
   for(I_B2 = 0; I_B2 < 2; I_B2++){
      value = 1;
      for (I_B = 0; I_B < 8; I_B++){
         if (I_B % 2 == 0){
            Portout(value, 0);
            output_low (Ledb_p);
            output_high (Ledm_p);
            output_high (Ledt_p);
            delay_ms (200);
         }
         else{
            Portout(0, value);
            output_high (Ledb_p);
            output_high (Ledm_p);
            output_low (Ledt_p);
            delay_ms (200);
         }
         value = (value*2) + 1;
      }
   }
}
void LEDTest5()
{
   int I_B, I_B2, top, bottom;
   for(I_B2 = 0; I_B2 < 2; I_B2++){
      top = 192;
      bottom = 3;
      for (I_B = 0; I_B < 6; I_B++){
         if (I_B % 2 == 0){
            Portout(top, bottom);
            output_low (Ledb_p);
            output_low (Ledm_p);
            output_low (Ledt_p);
            delay_ms (200);
         }
         else{
            Portout(bottom, top);
            output_high (Ledb_p);
            output_high (Ledm_p);
            output_high (Ledt_p);
            delay_ms (200);
         }
         top = top/2;
         bottom = bottom *2;
      }
   }
}
Esempio n. 3
0
void unlock_door(int rotation)
{
  int i = 0;
  for (i = 0; i < rotation; i++) {
    // Blue Wire + high for 15 milliseconds
    output_high(PORTC,STEPPER4);
    _delay_ms(200);
    //_delay_ms(3000);
    output_low(PORTC,STEPPER4);
    // Green Wire + high fo 15 milliseconds
    output_high(PORTC,STEPPER3);
    _delay_ms(200);
    //_delay_ms(3000);
    output_low(PORTC,STEPPER3);
    // Red Wire + high for 15 milliseconds
    output_high(PORTC,STEPPER2);
    _delay_ms(200);
    //_delay_ms(3000);
    output_low(PORTC,STEPPER2);
    // Black Wire + high for 15 milliseconds
    output_high(PORTC,STEPPER1);
    _delay_ms(200);
    //_delay_ms(3000);
    output_low(PORTC,STEPPER1);
  }
  output_low(PORTB, LED_RED);  // RED LED indicates unlocked
}
Esempio n. 4
0
void init_dac()
{
    output_high(DAC_CS);
    output_high(DAC_LDAC);
    output_high(DAC_CLK);
    output_high(DAC_DI);
}
Esempio n. 5
0
byte lcd_le_byte()
// lê um byte do LCD (somente com pino RW)
{
   byte dado;
   // configura os pinos de dados como entradas
   input(lcd_d4);
   input(lcd_d5);
   input(lcd_d6);
   input(lcd_d7);
   // se o pino rw for utilizado, coloca em 1
   #ifdef lcd_rw
      output_high(lcd_rw);
   #endif
   output_high(lcd_enable); // habilita display
   dado = 0;   // zera a variável de leitura
   // lê os quatro bits mais significativos
   if (input(lcd_d7)) bit_set(dado,7);
   if (input(lcd_d6)) bit_set(dado,6);
   if (input(lcd_d5)) bit_set(dado,5);
   if (input(lcd_d4)) bit_set(dado,4);
   // dá um pulso na linha enable
   output_low(lcd_enable);
   output_high(lcd_enable);
   // lê os quatro bits menos significativos
   if (input(lcd_d7)) bit_set(dado,3);
   if (input(lcd_d6)) bit_set(dado,2);
   if (input(lcd_d5)) bit_set(dado,1);
   if (input(lcd_d4)) bit_set(dado,0);
   output_low(lcd_enable);   // desabilita o display
   return dado;   // retorna o byte lido
}
Esempio n. 6
0
int8 in_read_charlieplex_inputs()
{
	int8 switches;

	output_drive(PI_CHARLIEPLEX_SWITCH_1_PIN);
	switches = input_state(PI_CHARLIEPLEX_SWITCH_3_PIN);
	switches <<= 1;
	switches |= input_state(PI_CHARLIEPLEX_SWITCH_2_PIN);
	output_high(PI_CHARLIEPLEX_SWITCH_1_PIN);
	output_float(PI_CHARLIEPLEX_SWITCH_1_PIN);
	output_low(PI_CHARLIEPLEX_SWITCH_1_PIN);

	output_drive(PI_CHARLIEPLEX_SWITCH_2_PIN);
	switches <<= 1;
	switches |= input_state(PI_CHARLIEPLEX_SWITCH_3_PIN);	
	switches <<= 1;
	switches |= input_state(PI_CHARLIEPLEX_SWITCH_1_PIN);
	output_high(PI_CHARLIEPLEX_SWITCH_2_PIN);
	output_float(PI_CHARLIEPLEX_SWITCH_2_PIN);
	output_low(PI_CHARLIEPLEX_SWITCH_2_PIN);

	//Note: In this block charliplex1 must be read before charliplex2
	// just to charliplex2 has enough time to recover because charliplex2 was 
	// low in previous block. This avoid to put a delay here.
	output_drive(PI_CHARLIEPLEX_SWITCH_3_PIN);
	switches <<= 1;
	switches |= input_state(PI_CHARLIEPLEX_SWITCH_1_PIN);
	switches <<= 1;
	switches |= input_state(PI_CHARLIEPLEX_SWITCH_2_PIN);
	output_high(PI_CHARLIEPLEX_SWITCH_3_PIN);
	output_float(PI_CHARLIEPLEX_SWITCH_3_PIN);
	output_low(PI_CHARLIEPLEX_SWITCH_3_PIN);

	return ~switches;
}
Esempio n. 7
0
set_pot (int pot_num, int new_value) {
   byte i;
   byte cmd[3];

   if (pot_num >= NUM_POTS)
      return;

   pots[pot_num] = new_value;

   cmd[0]=pots[0];
   cmd[1]=pots[1];
   cmd[2]=0;

   for(i=1;i<=7;i++)
     shift_left(cmd,3,0);

   output_high(RST1);
   delay_us(2);

   for(i=1;i<=17;i++) {
      output_bit(DI, shift_left(cmd,3,0));
      delay_us(2);
      output_high(CLK);
      delay_us(2);
      if(i==17)
         output_low(RST1);
      output_low(CLK);
      delay_us(2);
   }
}
Esempio n. 8
0
void LCD_Initialization()
{
	output_low(LCD_CE);
	output_low(LCD_RS);
	output_low(LCD_RW);

	output_d(0);
	output_d(0x38);

	output_high(LCD_CE);
	Nop();
	Nop();
	output_low(LCD_CE);

	delay_ms(20);

	output_d(0x38);

	output_high(LCD_CE);
	Nop();
	Nop();
	output_low(LCD_CE);

	delay_ms(5);

	LCD_Cmd(DISPLAY_ON);		// display on, curse off, blink off
	LCD_Cmd(0x01);				// display on, curse off, blink off
	LCD_Cmd(0x06);				// LCD clear, curse home
	LCD_Cmd(0x80);				// initial DDRAM address
	LCD_Cmd(0x01);				// LCD clear,curse home
}
Esempio n. 9
0
void write_dac(int16 data) {
    BYTE cmd[3];
    BYTE i;

    cmd[0]=data;
    cmd[1]=(data>>8);
    cmd[2]=0x03;

    output_high(DAC_LDAC);
    output_low(DAC_CLK);
    output_low(DAC_CS);

    for(i=0; i<=23; ++i)
    {
        if(i<4 || (i>7 && i<12))
            shift_left(cmd,3,0);
        else
        {
            output_bit(DAC_DI, shift_left(cmd,3,0));

            output_high(DAC_CLK);
            output_low(DAC_CLK);
        }
    }
    output_high(DAC_CS);

    output_low(DAC_LDAC);
    delay_us(10);

    output_HIGH(DAC_LDAC);
}
Esempio n. 10
0
void WRITE_EXT_SRAM_STRING(byte Address, char* ptrData)
{
   byte Cnt,Data;

   EnableSRAM(TRUE);

   // Send Write Address       // write: bit 7 = 1
   Data = 0x80;               // other bits are address
   Data |= Address;
   EnableSRAM(TRUE);
   for(Cnt = 8; Cnt > 0; Cnt--)
   {
      output_bit(SRAM_MOSI,bit_test(Data,(Cnt - 1)));
      output_high(SRAM_SCK);
      output_low(SRAM_SCK);
   }

   // Write ptrData to SRAM
   Data = *ptrData;
   while(Data != 0)
   {
      for(Cnt = 8; Cnt > 0; Cnt--)     // shift in bits 7 - 0
      {
         output_bit(SRAM_MOSI,bit_test(Data,(Cnt - 1)));
         output_high(SRAM_SCK);
         output_low(SRAM_SCK);
      }
      ++ptrData;
      Data = *ptrData;
   }

   EnableSRAM(FALSE);
}
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);
}



}
Esempio n. 12
0
// transmit byte serially, MSB first
void send_8bit_serial_data(unsigned char data)
{
  unsigned char i;

  // select device
  output_high(SD_CS); //Basically does chip enable

  // send bits 7..0
  for(i = 0; i < 8; i++) //Only for 8bits
    {
      // consider leftmost bit
      // set line high if bit is 1, low if bit is 0
      if (data & 0x80) //It's start in the eighs bith
        output_high(SD_DI);
      else
        output_low(SD_DI);

      // pulse clock to indicate that bit value should be read
      output_low(SD_CLK);
      output_high(SD_CLK);

      // shift byte left so next bit will be leftmost
      data <<= 1;
    }

  // deselect device
  output_low(SD_CS);
}
Esempio n. 13
0
void RTCC_isr() //function interrupción TMR0
   {  set_TIMER0(5); //inicializa el timer0 para que cuente 0.2 us 
   output_toggle(PIN_B2);
   set_TIMER0(5); //inicializa el timer0 para que cuente 0.2 us
   cont++;
   //Giro en un sentido
   if(input(PIN_B0)==1){
      if ((int16)cont==(int16)10){ cont=0;
            output_high(PIN_B3);}
      if((int16)comp1==(int16)cont){
            output_low(PIN_B3);}
   }
   if (input(PIN_B0)==0)
   output_low(PIN_B3);
    //--------------Giro opuesto----------------
       if(input(PIN_B1)==1){
      if ((int16)cont==(int16)10){ cont=0;
            output_high(PIN_B4);}
      if((int16)comp1==(int16)cont){
            output_low(PIN_B4);}
   }
   if (input(PIN_B1)==0)
   output_low(PIN_B4);
    
   }
void LEDTest2()
{
   int I_B, li, re;

   
   for(I_B = 0; I_B < 3; I_B++){
      output_low (Ledb_p);
      output_low (Ledm_p);
      output_low (Ledt_p);
      
      /*
         255 = 1111 1111
         127 = 0111 1111
          85 = 0101 0101
         170 = 1010 1010
      */
     
      li = 170;
      re = 85;
      
      Portout(li, re);
      delay_ms (200);
      
      output_high (Ledb_p);
      output_high (Ledm_p);
      output_high (Ledt_p);
      
      li = 85;
      re = 170;
      
      Portout(li, re);
      delay_ms (200);
   }
}
void LEDTest3()
{
   int I_B, li, re;
   
   for(I_B = 0; I_B < 2; I_B++){
      output_low (Ledb_p);
      output_high (Ledm_p);
      output_low (Ledt_p);
      
      li = 1;
      re = 1;
      
      for (I_B = 0; I_B < 8; I_B++){
         Portout(li, re);
         delay_ms (200);
         li = (li * 2) + 1 ;
         re = (re * 2) + 1 ;
      }
      
      output_high (Ledb_p);
      output_low (Ledm_p);
      output_high (Ledt_p);
      
      
      for (I_B = 0; I_B < 8; I_B++){
         Portout(li, re);
         delay_ms (200);
         li = (int)(li / 2);
         re = (int)(re / 2);
      }
   
   }    
}
Esempio n. 16
0
//-----------------------------------------------------------------------
//	init_ADNS2051()
//-----------------------------------------------------------------------
//
void init_ADNS2051() {
int i;	

// Initialisation
	setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);

	posX = 0;
	posY = 0;

	DeltaX = 0;
	DeltaY = 0;

	teller = 0;
	teller1 = 0;

	for(i=0;i<DELTA_LOG_SIZE;i++){
		lastX[i] = 0;
		lastY[i] = 0;
	}

// Init ADNS-2051 pins
	output_high(SDIO);
	output_high(SCLK);
	output_low(PD);	
	delay_ms(2);

// Resync 
	output_high(PD);
	delay_ms(2);
	output_low(PD);
}
Esempio n. 17
0
int main(void) {
  // initialize the direction of PORTD #6 to be an output
  set_output(DDRC, LED1);  
  set_output(DDRC, LED2);
  set_output(DDRC, LED3);
  set_output(DDRD, LED4);

  while (1) {
    output_high(PORTC, LED1);
    delay_ms(200);
    output_high(PORTC, LED2);
    delay_ms(200);
    output_high(PORTC, LED3);
    delay_ms(200);
    output_high(PORTD, LED4);
    delay_ms(200);

    output_low(PORTC, LED1);
    delay_ms(200);
    output_low(PORTC, LED2);
    delay_ms(200);
    output_low(PORTC, LED3);
    delay_ms(200);
    output_low(PORTD, LED4);
    delay_ms(200);
  }
}
Esempio n. 18
0
byte READ_EXT_SRAM(byte Address)
{
   byte Cnt,Data;

   EnableSRAM(TRUE);

   // Send Read Address       // write: bit 7 = 0
   Data = 0;                  // other bits are address
   Data |= Address;
   EnableSRAM(TRUE);
   for(Cnt = 8; Cnt > 0; Cnt--)
   {
      output_bit(SRAM_MOSI,bit_test(Data,(Cnt - 1)));
      output_high(SRAM_SCK);
      output_low(SRAM_SCK);
   }

   // Read each bit from address
   Data = 0;
   for(Cnt = 8; Cnt > 0; Cnt--)     // shift in bits 7 - 0
   {
      output_high(SRAM_SCK);
      output_low(SRAM_SCK);
      if(input(SRAM_MISO))
         bit_set(Data,(Cnt - 1));
   }
   EnableSRAM(FALSE);
   return(Data);
}
Esempio n. 19
0
void WRITE_EXT_SRAM(byte Address, byte DataIn)
{
   byte Cnt,Data;

   EnableSRAM(TRUE);

   // Send Write Address       // write: bit 7 = 1
   Data = 0x80;               // other bits are address
   Data |= Address;
   EnableSRAM(TRUE);
   for(Cnt = 8; Cnt > 0; Cnt--)
   {
      output_bit(SRAM_MOSI,bit_test(Data,(Cnt - 1)));
      output_high(SRAM_SCK);
      output_low(SRAM_SCK);
   }

   // Write DataIn to SRAM
   for(Cnt = 8; Cnt > 0; Cnt--)     // shift in bits 7 - 0
   {
      output_bit(SRAM_MOSI,bit_test(DataIn,(Cnt - 1)));
      output_high(SRAM_SCK);
      output_low(SRAM_SCK);
   }
   EnableSRAM(FALSE);
}
Esempio n. 20
0
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);
      }
   }
}
Esempio n. 21
0
void write_default_param_file() {
	/* all LEDs for 1.5 seconds */
#if 0
	timers.led_on_a=150;
	timers.led_on_b=150;
	timers.led_on_c=150;
	timers.led_on_d=150;
#else
	output_high(LED_A);
	output_high(LED_B);
	output_high(LED_C);
	output_high(LED_D);
	delay_ms(1500);
	output_low(LED_A);
	output_low(LED_B);
	output_low(LED_C);
	output_low(LED_D);
#endif

	set_config();

	/* write them so next time we use from EEPROM */
	write_param_file();

}
Esempio n. 22
0
void eaDogM_WriteChr(char value)
{
	output_high(EADOGM_PIN_RS);
	output_low(EADOGM_PIN_CSB);
	eaDogM_outSPI(value);
	output_high(EADOGM_PIN_CSB);
	delay_ms(1);
}
Esempio n. 23
0
//enable timer1 int, clear t1 int, pre-set timer
void setup_led_pulse()
{
   set_timer1(0);
   output_high(BOARD_LED);                // LED is turned OFF by timer1_isr()
   if(nv_product==AWS)output_high(PANEL_LED); 
   clear_interrupt(INT_TIMER1);
   enable_interrupts(INT_TIMER1);
}
Esempio n. 24
0
void motor_move(int32 motor, int32 pasos, int32 direccion){
    (motor == 1) ? output_high(PIN_A2):output_low(PIN_A2);
    (motor == 2) ? output_high(PIN_A3):output_low(PIN_A3);
    (motor == 3) ? output_high(PIN_A4):output_low(PIN_A4);
    printf("Motor: %Ld, pasos%Ld, dir %Ld\n\r",motor,pasos,direccion);
    motores2(pasos,direccion);
    motor_off();
}
Esempio n. 25
0
void main()
{
   union {
      unsigned int32 hours;
      unsigned int8 minutes;
      unsigned int8 seconds;} upTime;
   
   
   TICK_TYPE CurrentTick,PreviousUDPTick,PreviousSATick;
   resetStatus = (RCON & 0b00111111) | !(STKPTR & 0b11000000); // Get the Reset Status
   RCON = RCON | 0b00111111; //Reset RCON Reset flags... (Reset Register)
   STKPTR = STKPTR & 0b00111111; // Clear Stack Overflow/Underflow flags
   PortInit(); 
   OutputInit();  
   restart_wdt();
   romEZHRInit();    //set up default ezhr settings
   eeROMinit();      //set up default eprom settings
   IPAddressInit();  //set up MAC and default IP addresses
   delay_ms(500); 
   ADCInit();        //set up ADC ports
   iniADCParams();    
   SerialInit();     //set up serial ports
   TickInit();       //set up tick timer
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   StackInit();   
   WritePHYReg(ERXFCON,EthernetRXfilterSetting); // Allow only uni & multi
   SetLEDConfig(E_LED_CONFIG);   // swap LED's 
   output_high(E_SW_PWR_DN);     // Power Ethernet Switch
   output_high(E_SW_RST);
   output_low(RS485_TXEN);
   output_high(RS485_RXDIS);
   output_high(RS232_F_OFF);
   output_high(RS232_F_ON);
   CurrentTick = PreviousUDPTick = get_ticks();
   UDPSampleRate = eeReadUDPRate() * TICKS_PER_MILLISECOND;
   portControlInit();
   while(TRUE)
   {
      CurrentTick = get_ticks();
      restart_wdt();
      StackTask();
      restart_wdt();
      MyTCPTask();//handles TCP connections
      restart_wdt();
      setIO();// checks voltage status and sets ports accordingly
//!      if(CurrentTick-PreviousUDPTick >= UDPSampleRate)
//!      {
//!         currentRoutine=UDPTASK;
//!         BOOL UDPDone = MyUDPTask();
//!         if(UDPDone) 
//!         {
//!            PreviousUDPTick=CurrentTick;
//!         }
//!      }
      StackApplications();
   }
}
Esempio n. 26
0
void clearLEDs(void)
{
  //int1 currentLEDs[6] = {0, 0, 0, 0, 0, 0};
  // nextLEDs[6] = {0, 0, 0, 0, 0, 0};
  output_high(greenLED);
  output_high(yellowLED);
  output_high(redLED);
  printf("All LEDs cleared\n\r");
}
Esempio n. 27
0
void lock_one_phase(void)
{
  // Blue Wire + high for 15 milliseconds
  output_high(PORTC,STEPPER4);
  _delay_ms(400);
  // Green Wire + high fo 15 milliseconds
  output_high(PORTC,STEPPER3);
  _delay_ms(400);
}
Esempio n. 28
0
void blink() {
    int i;
    for (i=0; i<4; i++) {
    	output_high(LED0); output_high(LED1);
    	delay_ms(125);
    	output_low(LED0); output_low(LED1);
    	delay_ms(125);
    }
}
Esempio n. 29
0
void init_temp() {
   output_high(DAL_SDA);
   output_high(DAL_SCL);
   i2c_start();
   i2c_write(0x90);
   i2c_write(0x51);
   i2c_stop();
   temp_config(0xc);
}
Esempio n. 30
0
void display( char one, char two) {
   display_segs(one);
   output_high(PIN_A0);
   wait();
   output_low(PIN_A0);
   display_segs(two);
   output_high(PIN_A1);
   wait();
   output_low(PIN_A1);
}