Пример #1
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);
  }
}
Пример #2
0
// Purpose:       Initialize a graphic LCD. This must be called before any
//                other glcd function is used.
// Inputs:        The initialization mode
//                OFF - Turns the LCD off
//                ON  - Turns the LCD on
// Date:          5/28/2003
void glcd_init(int1 mode)
{
   // Initialze some pins
   output_HIGH(GLCD_RST);
   output_low(GLCD_E);
   output_low(GLCD_CS1);
   output_low(GLCD_CS2);

   output_low(GLCD_DI);                // Set for instruction
   glcd_writeByte(GLCD_CS1, 0xC0);     // Specify first RAM line at the top
   glcd_writeByte(GLCD_CS2, 0xC0);     //   of the screen
   glcd_writeByte(GLCD_CS1, 0x40);     // Set the column address to 0
   glcd_writeByte(GLCD_CS2, 0x40);
   glcd_writeByte(GLCD_CS1, 0xB8);     // Set the page address to 0
   glcd_writeByte(GLCD_CS2, 0xB8);
   if(mode == ON)
   {
      glcd_writeByte(GLCD_CS1, 0x3F);  // Turn the display on
      glcd_writeByte(GLCD_CS2, 0x3F);
   }
   else
   {
      glcd_writeByte(GLCD_CS1, 0x3E);  // Turn the display off
      glcd_writeByte(GLCD_CS2, 0x3E);
   }

   glcd_fillScreen(OFF);               // Clear the display
}
Пример #3
0
int16 read_analog(int channel)
{
   int i;
   channel &= 0x1F;

   delay_us(2);			   // 2 usec delay
   output_high(MPH_CLK);   // activates SCLK
   output_high(MPH_SYNC);  // activetes SYNC

   delay_us(1);			   // 1 usec delay
   output_low(MPH_SYNC);   // resets SYNC

   for(i=8; i>0; i--)
   {
      if ((channel & (1<<(i-1)))==0)
			output_low(MPH_DIN);
      else
			output_high(MPH_DIN);
      output_low(MPH_CLK);   // resets SCLK
      output_high(MPH_CLK);  // activates SCLK
   }

   delay_us(50);		   // 50 usec delay to stabilize the value.
   return (read_adc());	// reads the analog channel, waits for end of conversion
                        // and returns the value.
}
Пример #4
0
void motor_off(){
    output_low(PIN_A1); 
    delay_ms(100);
    output_low(PIN_A2);
    output_low(PIN_A3);
    output_low(PIN_A4);
}
Пример #5
0
void giro_izquierda50() {
   output_high(PIN_B4);  
   output_low(PIN_B5);   
   output_low(PIN_B6);   
   output_high(PIN_B7);  
   delay_ms( time ); 
   
   output_low(PIN_B4);  
   output_low(PIN_B5);  
   output_low(PIN_B6);  
   output_high(PIN_B7); 
   delay_ms( time );    
   
   output_low(PIN_B4);  
   output_low(PIN_B5);  
   output_high(PIN_B6); 
   output_high(PIN_B7); 
   delay_ms( time );    
   
   output_low(PIN_B4); 
   output_low(PIN_B5); 
   output_high(PIN_B6);
   output_low(PIN_B7); 
   delay_ms( time );   
}
Пример #6
0
void glcd_image(long mempointer  /*This is the image location in program memory*/) 
{  int j, i; 
   int page = 0xB8; 
   char chipsel; 
   char buffer[1]; 
   output_low(GLCD_DI);                // Set for instruction 
   glcd_writeByte(GLCD_CS1, 0x40);     // Set the column address to 0 
   glcd_writeByte(GLCD_CS2, 0x40); 
   glcd_writeByte(GLCD_CS1, page);     // Set the page address to 0 
   glcd_writeByte(GLCD_CS2, page); 
   for (j = 0; j < 8; j++, page+=1) 
   {  output_low(GLCD_DI); 
      glcd_writeByte(GLCD_CS1, page); 
      glcd_writeByte(GLCD_CS2, page); 
      for (i = 0; i < 128; i++) 
      { 
         if ( i < 64) 
         { 
            chipsel = GLCD_CS1; 
         } 
         else 
         { 
            chipsel = GLCD_CS2; 
         } 
         read_program_memory(mempointer, buffer, 1); 
         mempointer++; 
         output_high(GLCD_DI); 
         glcd_writeByte(chipsel, *buffer); 
      } 
   } 
}
Пример #7
0
void WriteFSKbyte(int8 DATA)
{
	int8 	RGIT = 0;
	int16 	temp = 0xB800;
	
	output_float(_SDO);
	output_low(_SCK);

	temp|= DATA;

Loop:	SCK = false;

	RF_EN	= false;
	output_low(_SDA);
	SCK		= true;
	RGIT 	= (SDO==true); //Polling SDO
	SCK		= false;
	output_high(_SDA);
	RF_EN	= true;

	if (RGIT==0){
		goto Loop;
	} else {
		RGIT=false;
		WriteCMD(temp);
	}
}
Пример #8
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();

}
Пример #9
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);
   }
}
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);
}



}
Пример #11
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);
}
Пример #12
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);
    
   }
Пример #13
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);
}
Пример #14
0
void stop(void)
{
	output_low(PORTB,PB2);
	output_low(PORTB,PB1);	
	output_low(PORTB,PB4);
	BUZZER_ON = 0;
}
Пример #15
0
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;
      }
   }
}
Пример #16
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
}
Пример #17
0
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;
      }
   }
}
Пример #18
0
inline void motors_init (void) {
    set_output(MOTOR0_DDR, MOTOR0_STEP_DD);
    set_output(MOTOR0_DDR, MOTOR0_DIR_DD);
    output_low(MOTOR0_PORT, MOTOR0_STEP);
    output_low(MOTOR0_PORT, MOTOR0_DIR);

    set_output(MOTOR1_DDR, MOTOR1_STEP_DD);
    set_output(MOTOR1_DDR, MOTOR1_DIR_DD);
    output_low(MOTOR1_PORT, MOTOR1_STEP);
    output_low(MOTOR1_PORT, MOTOR1_DIR);

    set_output(MOTOR2_DDR, MOTOR2_STEP_DD);
    set_output(MOTOR2_DDR, MOTOR2_DIR_DD);
    output_low(MOTOR2_PORT, MOTOR2_STEP);
    output_low(MOTOR2_PORT, MOTOR2_DIR);

    set_output(MOTOR3_DDR, MOTOR3_STEP_DD);
    set_output(MOTOR3_DDR, MOTOR3_DIR_DD);
    output_low(MOTOR3_PORT, MOTOR3_STEP);
    output_low(MOTOR3_PORT, MOTOR3_DIR);

    set_output(MOTOR4_DDR, MOTOR4_STEP_DD);
    set_output(MOTOR4_DDR, MOTOR4_DIR_DD);
    output_low(MOTOR4_PORT, MOTOR4_STEP);
    output_low(MOTOR4_PORT, MOTOR4_DIR);

    return;
}
Пример #19
0
int8 RF12_RDFIFO()
{
	int8 	i,Result;

	output_low(_SCK);
	output_low(_SDA);
	RF_EN	= false;

	for (i=0; i<16; i++) { //skip status bits
		SCK		= true;
		SCK		= true;
		SCK		= false;
	}

	Result	= 0;

	for (i=0; i<8; i++) { //read fifo data byte
		Result<<=1;

		if (SDO){
			Result|=1;
		}

		SCK		= true;
		SCK		= true;
		SCK		= false;
	}

	RF_EN		= true;
	return(Result);
}
Пример #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);
      }
   }
}
Пример #21
0
void led_off(){
    output_low(PIN_B0);
    output_low(PIN_B1);
    output_low(PIN_B2);
    output_low(PIN_B3);
    output_low(PIN_B4);
}
Пример #22
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;
}
Пример #23
0
void giro_derecha50() {
   output_high(PIN_B4);
   output_low(PIN_B5);
   output_low(PIN_B6);
   output_low(PIN_B7);
   delay_ms( time );  
   
   output_high(PIN_B4);
   output_high(PIN_B5);
   output_low(PIN_B6); 
   output_low(PIN_B7); 
   delay_ms( time );   
   
   output_low(PIN_B4); 
   output_high(PIN_B5);
   output_low(PIN_B6); 
   output_low(PIN_B7); 
   delay_ms( time );   
   
   output_low(PIN_B4);  
   output_high(PIN_B5); 
   output_high(PIN_B6); 
   output_low(PIN_B7);  
   delay_ms( time );    
}
Пример #24
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);
}
Пример #25
0
// SHT1x Address & Command Mode with address=000 
int SHTWrite(int Data) 
{ 
   int i; 
   
   for (i=0x80;i>0;i/=2)        //shift bit for masking data
   { 
      if(i&Data)
      output_high(SHT1xDATA); 
      else  
      output_low(SHT1xDATA); 
      
      delay_us(2);               //Snend Clock each bit 
      output_high(SHT1xSCK); 
      delay_us(2); 
      output_low(SHT1xSCK); 
   } 
   
   output_float(SHT1xDATA);     //Change DATA Line to Input 
   delay_us(2); 
   
   output_high(SHT1xSCK);       //Clock for Acknowledge 
   delay_us(2); 
   
   i= input(SHT1xDATA);         //Get Acknowledge
   
   output_low(SHT1xSCK); 
   delay_ms(250);
   return (i);
} 
Пример #26
0
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);
   }
}
Пример #27
0
// Purpose:       Turn a pixel on a graphic LCD on or off
// Inputs:        x - the x coordinate of the pixel
//                y - the y coordinate of the pixel
//                color - ON or OFF
// Output:        1 if coordinate out of range, 0 if in range
void glcd_pixel(int x, int y, int1 color)
{
   BYTE data;
   BYTE chip = GLCD_CS1;  // Stores which chip to use on the LCD

   if(x > 63)  // Check for first or second display area
   {
      x -= 64;
      chip = GLCD_CS2;
   }

   output_low(GLCD_DI);                                     // Set for instruction
   bit_clear(x,7);                                          // Clear the MSB. Part of an instruction code
   bit_set(x,6);                                            // Set bit 6. Also part of an instruction code
   glcd_writeByte(chip, x);                                 // Set the horizontal address
   glcd_writeByte(chip, (y/8 & 0b10111111) | 0b10111000);   // Set the vertical page address
   output_high(GLCD_DI);                                    // Set for data
   data = glcd_readByte(chip);

   if(color == ON)
      bit_set(data, y%8);        // Turn the pixel on
   else                          // or
      bit_clear(data, y%8);      // turn the pixel off
   output_low(GLCD_DI);          // Set for instruction
   glcd_writeByte(chip, x);      // Set the horizontal address
   output_high(GLCD_DI);         // Set for data
   glcd_writeByte(chip, data);   // Write the pixel data
}
Пример #28
0
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);
      }
   
   }    
}
Пример #29
0
//---------------------------------------- 
// Send a byte to the LCD. 
void lcd_send_byte(char address, char n) 
{ 
	output_low(LCD_RS); 
	
	#ifdef USE_LCD_RW 
	while(bit_test(lcd_read_byte(),7)) ; 
	#else 
	delay_us(60);  
	#endif 
	
	if(address) 
	   output_high(LCD_RS); 
	else 
	   output_low(LCD_RS); 
	      
	 delay_cycles(1); 
	
	#ifdef USE_LCD_RW 
	output_low(LCD_RW); 
	delay_cycles(1); 
	#endif 
	
	output_low(LCD_E); 
	
	lcd_send_nibble(n >> 4); 
	lcd_send_nibble(n & 0xf); 
} 
Пример #30
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);
}