Example #1
0
/*
void print_char( char c, uint8_t pos ) {
  uint8_t data[32], bitmap[32];

  int i;

  memcpy_P( data, &typeface[32*((c) -32)], 32 );
  for(i=0;i < 16; i++) {
   bitmap[i     ] = data[ i*2     ];
   bitmap[i + 16] = data[ i*2 + 1 ];
  }
 
  if( pos < 2 ) {
    CS1_LOW; 
    write_buffer( bitmap   , 16, pos & 1 ? 16 : 0 );
    CS1_HIGH;

    CS2_LOW;
    write_buffer( bitmap+16, 16, pos & 1 ? 16 : 0 );
    CS2_HIGH;
  } else { 
    CS3_LOW; 
    write_buffer( bitmap   , 16, pos & 1 ? 16 : 0 );
    CS3_HIGH;

    CS4_LOW;
    write_buffer( bitmap+16, 16, pos & 1 ? 16 : 0 );
    CS4_HIGH;
  }
}
*/
void blank() {
  set_mode(write_mode);
  send_address(0);
  int i;
  for(i = 0; i < 0x40; ++i)
    send_data(0x0);
}
Example #2
0
bool twi_get(uint8_t address, uint8_t* data)
{
    if (!send_address(address, TW_WRITE)) {
        uart_send("Send address failed");
        return false;
    }
    
    uart_send("Send GET");
    
    // Send a GET packet
    TWDR = 1;
    SEND_AND_WAIT(1, 0);
    
    if (TW_STATUS != TW_MT_DATA_ACK) {
        DUMP_ERROR();
        return false;
    }
    
    uart_send("Switch to MR");
    if (!send_address(address, TW_READ)) {
        uart_send("MR send_address failed");
        STOP();
        return false;
    }
    
    SEND_AND_WAIT(0, 0);
    
    if (TW_STATUS != TW_MR_DATA_ACK && TW_STATUS != TW_MR_DATA_NACK) {
        DUMP_ERROR();
        return false;
    }
    
    uart_send("Read packet");
    // Read the data packet
    *data = TWDR;
    
    char val[20];
    sprintf(val, "--read = %x", *data);
    uart_send(val);
    
    STOP();
    
    return true;
}
Example #3
0
bool HT1632::read_from_address( uint8_t addr, uint8_t *value ) {
  if( addr >= memory_limit() ) 
    return false;

  set_mode(read_mode);
  send_address( addr );
  *value = read_nibble();
  deselect();
  return true;
}
Example #4
0
bool HT1632::write_to_address( uint8_t addr, uint8_t value ) {
  if( addr >= memory_limit() ) 
    return false;

  set_mode(write_mode);
  send_address( addr );
  send_data( value );
  deselect();
  return true;
}
Example #5
0
void write_buffer( uint8_t *buffer, uint8_t length, uint8_t offset ) {
  uint8_t *pointer = buffer;

  set_mode(write_mode);
  send_address( offset*2 );

  while( length-- ) {
    uint8_t temp = *pointer;
    send_data( temp );
    swap( temp );
    send_data( temp );
    ++pointer;
  }
}
Example #6
0
bool HT1632::write_buffer( uint8_t *buffer, uint8_t length, uint8_t offset ) {
  if( (length + offset)*2 > memory_limit() )
    return false;
  
  uint8_t *pointer = buffer;  

  set_mode(write_mode);
  send_address( offset*2 );
  
  while( length-- ) {
    uint8_t temp = *pointer;
    send_data( temp );
    swap( temp );
    send_data( temp );
    ++pointer; 
  }
  deselect();
  return true;
}
Example #7
0
bool twi_put(uint8_t address, uint8_t data)
{
    send_address(address, TW_WRITE);
    
    // Send a PUT packet
    TWDR = 0;
    SEND_AND_WAIT(1, 0);
    
    if (TW_STATUS != TW_MT_DATA_ACK) {
        return false;
    }
    
    // Send the data packet
    TWDR = data;
    SEND_AND_WAIT(1, 0);
    
    if (TW_STATUS != TW_MT_DATA_ACK) {
        return false;
    }
    
    STOP();
    
    return true;
}
Example #8
0
int main(void) {
   u16 i;
   u08 data[2];
   int j=0;

   init();
   test_motor();
   clear_screen();

   _delay_ms(100);

   data[0] = 0x1; //change to WAKE mode
   send_address(0x2A,0);
   write_register(&data[0], 1);
   _delay_ms(100);
   unlock_bus();
   //send_address(0x2);
   //read_register(&data[1], 1);
   print_num(data[0]);
   //while(1) {}
   while(1) {
      //X
      send_address(0x1,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ",1);

      //Y
      send_address(0x3,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ", 1);

      //Z
      lcd_cursor(0,1);
      send_address(0x5,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ",1);
      print_num(count);
      _delay_ms(50);
      clear_screen();
      OCR2A = 28;

   }





/*



   USI_TWI_Master_Initialize();
   i2cMessageBuf[0] = 0x1c << 1; // Odd numbers for read
   i2cMessageBuf[1] = 0x0d; // Register 0 contains version number
   i2cMessageBuf[2] = (0x1c << 1) + 1; // Odd numbers for read
   i2cMessageBuf[3] = 0x00; // Register 0 contains version number
   USI_TWI_Start_Read_Write( i2cMessageBuf, 1 );

   */
   while(get_sw1() == 0) {}

   DDRD |= _BV(IR_PIN);

   led_on(1);
   led_on(0);

   clear_screen();

   while(1) {
      _delay_ms(1500);

      if (j) {
         clear_screen();
         print_string("test",4);
         led_on(1);
         led_off(0);
         //sbi(PORTC,LCD_E_PIN);
         //sbi(PORTC,LCD_RS_PIN);
         //PORTA = 0xff;

         sbi(PORTD,IR_PIN); //turn on IR pin

         sbi(PORTC,SERVO0_PIN); //set servo pins
         sbi(PORTC,SERVO1_PIN);
         sbi(PORTC,SERVO2_PIN);
         sbi(PORTF,SERVO3_PIN);

         //test i2c pins
         //sbi(PORTE,4);
         //sbi(PORTE,5);
         
         //motor test
         sbi(PORTB,MOTOR0_EN_PIN);
         sbi(PORTB,MOTOR1_EN_PIN);
         sbi(PORTD,MOTOR0_DIR0_PIN); 
         sbi(PORTD,MOTOR0_DIR1_PIN);
         sbi(PORTD,MOTOR1_DIR0_PIN);
         sbi(PORTD,MOTOR1_DIR1_PIN);
         j=0;
      } else {
         led_off(1);
         led_on(0);
         clear_screen();
         print_string("program",7);
         j=1;
         //cbi(PORTC,LCD_E_PIN);
         //cbi(PORTC,LCD_RS_PIN);
         //PORTA = 0;

         cbi(PORTD,IR_PIN); //turn off IR pin

         cbi(PORTC,SERVO0_PIN); //clear servo pins
         cbi(PORTC,SERVO1_PIN);
         cbi(PORTC,SERVO2_PIN);
         cbi(PORTF,SERVO3_PIN);
         
         //test i2c pins
         //cbi(PORTE,4);
         //cbi(PORTE,5);
         
         //motor test
         cbi(PORTB,MOTOR0_EN_PIN);
         cbi(PORTB,MOTOR1_EN_PIN);
         cbi(PORTD,MOTOR0_DIR0_PIN); 
         cbi(PORTD,MOTOR0_DIR1_PIN);
         cbi(PORTD,MOTOR1_DIR0_PIN);
         cbi(PORTD,MOTOR1_DIR1_PIN);
      }

   }

   return 0;
}
Example #9
0
int main(void) {
  DDRB |= _BV(DDB5); // debug LED

  // PIR Sensor input
  // make sure C0 is set to input and it's pullup is on
  DDRC  &= ~_BV(DDC0);
  PORTC |=  _BV(PORTC0);

  // HT1632 data bus
  DDRB |= _BV(DDB0);
  DDRB |= _BV(DDB1);
  DDRB |= _BV(DDB2);
  
  // HT1632 Chip Selects
  DDRD |= _BV(DDD3); //cs1
  DDRD |= _BV(DDD5); //cs2
  DDRD |= _BV(DDD6); //cs3
  DDRD |= _BV(DDD7); //cs4

  // Pull all the Chip Selects on the HT1632s high
  PORTD |= _BV(PORTD3) | _BV(PORTD5) | _BV(PORTD6) | _BV(PORTD7);
  
  // LPD8806 data bus
  DDRC |= _BV(DDC4);
  DDRC |= _BV(DDC5);

  // Setup each of the HT1632 displays
  CS1_LOW;
  init();
  CS1_HIGH;
 
  CS2_LOW;
  init();
  CS2_HIGH;
 
  CS3_LOW;
  init();
  CS3_HIGH;
 
  CS4_LOW;
  init();
  CS4_HIGH;
 
  CS1_LOW;
  blank();
  CS1_HIGH;

  CS2_LOW;
  blank();
  CS2_HIGH;

  CS3_LOW;
  blank();
  CS3_HIGH;

  CS4_LOW;
  blank();
  CS4_HIGH;


  // Set up the timer to tick every second
  cli();
  TCCR1A = 0;
  TCCR1B = 0;

  // set compare match register to desired timer count:
  OCR1A = 156;
  TCCR1B |= (1 << WGM12);
  TCCR1B |= (1 << CS10) | (1 << CS12); // 1024 perscaler
  TIMSK1 |= (1 << OCIE1A);

  sei();

  // Setup the data for the LPD8806 based string of LEDs.
  uint8_t buffer[32*3];
  uint16_t i;
  for(i=0;i<32*3;i++) { buffer[i] = 0; }
  LPD8806_write(buffer,32*3);
  

  while(1) {
    
    for(i = 0; i < 32; ++i ) {
      HSVtoRGB(
        (int)((360/32)*i+j) % 360, 255, 255,
        buffer+1+i*3, buffer+0+i*3, buffer+2+i*3
      );
    }

    LPD8806_write(buffer,32*3);

    uint16_t leds = lrint(163.292 * log(22*OCCUPY/3600+1));

    uint16_t row;
    for( row = 0; row < 128; row ++ ) {
      switch( row ){
        case 0:
          CS4_HIGH;
          CS1_LOW;
          set_mode(write_mode);
          send_address(0);
          break;
        case 32:
          CS1_HIGH;
          CS2_LOW;
          set_mode(write_mode);
          send_address(0);
          break;
        case 64:
          CS2_HIGH;
          CS3_LOW;
          set_mode(write_mode);
          send_address(0);
          break;
        case 96:
          CS3_HIGH;
          CS4_LOW;
          set_mode(write_mode);
          send_address(0);
          break;
      }
      if( (row+1) * 8 <= leds ) {
        send_data(0xFF);
        send_data(0xFF);
      } else if( row * 8 > leds ) {
        send_data(0x0);
        send_data(0x0);
      } else {
        uint8_t temp = _BV(7);
        uint8_t lights_left = leds % 8;
        while( lights_left > 0 ) {
          --lights_left;
          temp >>= 1;
          temp |= 128;
        }
        send_data( temp );
        swap(temp);
        send_data( temp );
      }
    }
    CS4_HIGH;
  }
  return 0;
}
Example #10
0
int main(void) {
   u16 i;
   u08 data[2];
   int j=0;

   init();
   test_motor();
   clear_screen();

/*   while(1){
      set_position(0,0);
      set_position(1,0);
      set_position(2,0);
      set_position(3,0);
      _delay_ms(1000);

      set_position(0,255);
      set_position(1,255);
      set_position(2,255);
      set_position(3,255);
      _delay_ms(1000);
   }
   */



   _delay_ms(100);

   for (i=0;i<1;i++) {
      led_on(1);
      _delay_ms(100);
      led_off(1);
      _delay_ms(100);
   }

   data[0] = 0x1; //change to WAKE mode
   send_address(0x2A,0);
   write_register(&data[0], 1);
   _delay_ms(100);
   unlock_bus();
   //send_address(0x2);
   //read_register(&data[1], 1);
   print_num(data[0]);
   //while(1) {}
   while(1) {
      //X
      send_address(0x1,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ");

      //Y
      send_address(0x3,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ");

      //Z
      lcd_cursor(0,1);
      send_address(0x5,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ");
      print_num(count);
      count++;
      _delay_ms(50);
      clear_screen();
      OCR2A = 28;

   }

   while(get_sw() == 0) {}

   led_on(1);
   led_on(0);

   clear_screen();

   while(1) {
      _delay_ms(1500);

      if (j) {
         clear_screen();
         print_string("test");
         led_on(1);
         led_off(0);
         //sbi(PORTC,LCD_E_PIN);
         //sbi(PORTC,LCD_RS_PIN);
         //PORTA = 0xff;

         sbi(PORTC,SERVO0_PIN); //set servo pins
         sbi(PORTC,SERVO1_PIN);
         sbi(PORTC,SERVO2_PIN);
         sbi(PORTF,SERVO3_PIN);

         //test i2c pins
         //sbi(PORTE,4);
         //sbi(PORTE,5);
         
         //motor test
         sbi(PORTB,MOTOR0_EN_PIN);
         sbi(PORTB,MOTOR1_EN_PIN);
         sbi(PORTD,MOTOR0_DIR0_PIN); 
         sbi(PORTD,MOTOR0_DIR1_PIN);
         sbi(PORTD,MOTOR1_DIR0_PIN);
         sbi(PORTD,MOTOR1_DIR1_PIN);
         j=0;
      } else {
         led_off(1);
         led_on(0);
         clear_screen();
         print_string("program");
         j=1;
         //cbi(PORTC,LCD_E_PIN);
         //cbi(PORTC,LCD_RS_PIN);
         //PORTA = 0;

         cbi(PORTC,SERVO0_PIN); //clear servo pins
         cbi(PORTC,SERVO1_PIN);
         cbi(PORTC,SERVO2_PIN);
         cbi(PORTF,SERVO3_PIN);
         
         //test i2c pins
         //cbi(PORTE,4);
         //cbi(PORTE,5);
         
         //motor test
         cbi(PORTB,MOTOR0_EN_PIN);
         cbi(PORTB,MOTOR1_EN_PIN);
         cbi(PORTD,MOTOR0_DIR0_PIN); 
         cbi(PORTD,MOTOR0_DIR1_PIN);
         cbi(PORTD,MOTOR1_DIR0_PIN);
         cbi(PORTD,MOTOR1_DIR1_PIN);
      }

   }

   return 0;
}
Example #11
0
HT1632::HT1632( 
  volatile uint8_t *cs_dir,   volatile uint8_t *cs_output_reg,   volatile uint8_t *cs_input_reg,   uint8_t cs_pin, 
  volatile uint8_t *wclk_dir, volatile uint8_t *wclk_output_reg, volatile uint8_t *wclk_input_reg, uint8_t wclk_pin, 
  volatile uint8_t *rclk_dir, volatile uint8_t *rclk_output_reg, volatile uint8_t *rclk_input_reg, uint8_t rclk_pin, 
  volatile uint8_t *data_dir, volatile uint8_t *data_output_reg, volatile uint8_t *data_input_reg, uint8_t data_pin,
  Command commons, 
  bool master 
) {
  this->cs_dir = cs_dir;
  this->cs_output_reg = cs_output_reg;
  this->cs_input_reg = cs_input_reg;
  this->cs_pin = cs_pin;
  
  this->wclk_dir = wclk_dir;
  this->wclk_output_reg = wclk_output_reg;
  this->wclk_input_reg = wclk_input_reg;
  this->wclk_pin = wclk_pin;
  
  this->rclk_dir = rclk_dir;
  this->rclk_output_reg = rclk_output_reg;
  this->rclk_input_reg = rclk_input_reg;
  this->rclk_pin = rclk_pin;
  
  this->data_dir = data_dir;
  this->data_output_reg = data_output_reg;
  this->data_input_reg = data_input_reg;
  this->data_pin = data_pin;
  
  this->commons = commons;
  this->mode = no_mode;
  
  _mhv_setOutput(cs_dir,cs_output_reg,cs_intput_reg,cs_pin);
  _mhv_setOutput(wclk_dir,wclk_output_reg,wclk_intput_reg,wclk_pin);
  _mhv_setOutput(rclk_dir,rclk_output_reg,rclk_intput_reg,rclk_pin);
  _mhv_setOutput(data_dir,data_output_reg,data_intput_reg,data_pin);
  
  _mhv_pinOn(cs_dir,cs_output_reg,cs_intput_reg,cs_pin);
  _mhv_pinOn(wclk_dir,wclk_output_reg,wclk_intput_reg,wclk_pin);
  _mhv_pinOn(rclk_dir,rclk_output_reg,rclk_intput_reg,rclk_pin);
  
  set_mode( command_mode );
  send_command(disable_system_oscillator);
  send_command((Command)commons);
  
  if( master ) {
    send_command(master_mode); // Does nothing on HT1632C
    send_command(clock_source_internal); // Sets master mode on HT1632C
  } else {
    send_command(slave_mode);
  }
  
  send_command(enable_system_oscillator);
  send_command(leds_on);
  send_command(blink_off);
  send_command(pwm_16);
  
  set_mode( HT1632::write_mode );
  send_address( 0 );
  for( uint8_t i =0; i < 0x60; ++i ) {
    send_data( 0x00 );
  }
  deselect();
}