Beispiel #1
0
void eeprom_read(void* sram_dest, uint16_t eeaddr, uint16_t size)
{
 uint8_t _t;
 uint8_t *dest = (uint8_t*)sram_dest;
 do
 {
  _t=_SAVE_INTERRUPT();
  _DISABLE_INTERRUPT();
  __EEGET(*dest,eeaddr);
  _RESTORE_INTERRUPT(_t);

  eeaddr++;
  dest++;
 }while(--size);

 EEAR=0x000; //this will help to prevent corruption of EEPROM
}
Beispiel #2
0
/*****************************************************************************
*
*   Function name : vCard
*
*   Returns :       char ST_state (to the state-machine)
*
*   Parameters :    char input (from joystick)
*
*   Purpose :       Puts the name in EEPROM on the LCD
*
*****************************************************************************/
char vCard(char input)
{
    static char enter = 1;

    if (enter)
    {
        enter = 0;

        __EEGET(index, EEPROM_START);           // Load the length if the name
        
        if((index < 1) | (index > STRLENGHT))   // if illegal length     
        {
            index = 0;
            Name[0] = 'A';
            
            enter = 1;
            return ST_VCARD_ENTER_NAME;               //enter new name
        }
        else
        {
            LoadEEPROM(Name, index, EEPROM_START + 1);  // Load name 
            LCD_puts(Name, 1);
        }
    }

    else if (input == KEY_NEXT)
    {
        enter = 1;
        return ST_VCARD_ENTER_NAME;
    }
    else if (input == KEY_PREV)
    {
        enter = 1;
        return ST_VCARD;
    }
    
    return ST_VCARD_FUNC;
}
Beispiel #3
0
void readDataFromEeprom() {
    unsigned int hour;
    unsigned int min;

    // sequence 1
    hour = eeprom_read_byte((uint8_t*)0);
    if (hour > 23) { hour = 0; }
    on[0] = hour;

    min = eeprom_read_byte((uint8_t*)1);
    if (min > 59) { min = 0; }
    on[1] = min;

    // sequence 2
    hour = eeprom_read_byte((uint8_t*)2);
    if (hour > 23) { hour = 0; }
    on[2] = hour;

    min = eeprom_read_byte((uint8_t*)3);
    if (min > 59) { min = 0; }
    on[3] = min;

    // sequence 3
    hour = eeprom_read_byte((uint8_t*)4);
    if (hour > 23) { hour = 0; }
    on[4] = hour;

    min = eeprom_read_byte((uint8_t*)5);
    if (min > 59) { min = 0; }
    on[5] = min;

    // sequence 4
    hour = eeprom_read_byte((uint8_t*)6);
    if (hour > 23) { hour = 0; }
    on[6] = hour;

    min = eeprom_read_byte((uint8_t*)7);
    if (min > 59) { min = 0; }
    on[7] = min;

    // sequence 5
    hour = eeprom_read_byte((uint8_t*)8);
    if (hour > 23) { hour = 0; }
    on[8] = hour;

    min = eeprom_read_byte((uint8_t*)9);
    if (min > 59) { min = 0; }
    on[9] = min;

    // sequence 6
    hour = eeprom_read_byte((uint8_t*)10);
    if (hour > 23) { hour = 0; }
    on[10] = hour;

    min = eeprom_read_byte((uint8_t*)11);
    if (min > 59) { min = 0; }
    on[11] = min;

    // co2 on
    hour = eeprom_read_byte((uint8_t*)12);
    if (hour > 23) { hour = 0; }
    co2[0] = hour;

    min = eeprom_read_byte((uint8_t*)13);
    if (min > 59) { min = 0; }
    co2[1] = min;

    // co2 off
    hour = eeprom_read_byte((uint8_t*)14);
    if (hour > 23) { hour = 0; }
    co2[2] = hour;

    min = eeprom_read_byte((uint8_t*)15);
    if (min > 59) { min = 0; }
    co2[3] = min;


    // save switch and day status
    __EEGET(switchStatus, (uint8_t*)STATUS_EEPROM_POS);
    if (switchStatus > 5) {
        switchStatus = 0;
    }

    __EEGET(dayStatus[0], (uint8_t*)STATUS_EEPROM_POS + 1);
    if (dayStatus[0] > 2) {
        dayStatus[0] = 0;
    }

    __EEGET(dayStatus[1], (uint8_t*)STATUS_EEPROM_POS + 2);
    if (dayStatus[1] > 2) {
        dayStatus[1] = 0;
    }

    __EEGET(dayStatus[2], (uint8_t*)STATUS_EEPROM_POS + 3);
    if (dayStatus[2] > 2) {
        dayStatus[2] = 0;
    }

    __EEGET(dayStatus[3], (uint8_t*)STATUS_EEPROM_POS + 4);
    if (dayStatus[3] > 2) {
        dayStatus[3] = 0;
    }

    __EEGET(dayStatus[4], (uint8_t*)STATUS_EEPROM_POS + 5);
    if (dayStatus[4] > 2) {
        dayStatus[4] = 0;
    }

    __EEGET(dayStatus[5], (uint8_t*)STATUS_EEPROM_POS + 6);
    if (dayStatus[5] > 2) {
        dayStatus[5] = 0;
    }
}
void main(void){
  __disable_interrupt();
  //Anolog mux channel select output
  DDRA = 0x3B;
  
  DDRB = 0xFF;          //initialize LCD
  SETBIT(PORTB, 0);     //deselect slave
  init_lcd_dog();
  clear_dsp();
  
  DDRD = 0x01;                  //  initialize PortD for interrupt
  PORTD = 0x02;
  
  SETBIT(DDRD, 7);    //enable buzzer output
  SETBIT(PORTD, 7);   //disable buzzer
  
  EIMSK = 0x0F;                 // enable individual interrupt
  EICRA = 0x53;
  
  __enable_interrupt();
  
  //infinite loop -- approximately 1 second for each loop
  while(1){
    if(present_state == Limit){
      __EEGET(temp_limit,channel_display);
      if(flag & (1 << 0)){
        temp_int = ((signed int)(temp_limit)*9)/5 + 32;
        unit_temp = 'F';
      }else{
        temp_int = (signed int)temp_limit;
        unit_temp = 'C';
      }
      
      clear_dsp();
      printf("Limit: %d ",temp_int);
      putchar(unit_temp);
      update_lcd_dog();
      
    }else{
      for(channel_conv = 0; channel_conv < 8; channel_conv++){
        DG528_driver(channel_conv);       //select channel
        for(i = 0; i < 10; i++){  //conv for each channel 10 times
          channel_voltage[channel_conv][i%8] = ADC161_conv();
        }
      }
      
      if(present_state == Auto){
        if(current_time == 3){
          current_time = 0;     //reset timer;
          channel_display = (channel_display + 1)%8;
        }else
          current_time ++ ;
      }else
        current_time = 0;      //always reset timer on man state
      
      if(present_state == Alert && counter == 0)
        CLEARBIT(PORTD, 7);
      else{
        SETBIT(PORTD, 7);
        if(counter > 0)
          counter --;
      }
      //summing ADC reading for a particular channel
      adc_sum = 0;
      for(i = 0; i<8; i++)
        adc_sum += (unsigned long int)channel_voltage[channel_display][i];
      
      //average the sum and look up the temperature in the table  
      temperature = tb_lookup(((unsigned int)(adc_sum >> 3)));
      
      if(flag & (1 << 0)){
        temperature = (temperature* 9)/5 + 320;
        unit_temp = 'F';
      }else
        unit_temp = 'C';
      if(temperature < 0)
         temp_tenth = (0 - temperature)%10;
      else
         temp_tenth = temperature%10;
      temperature = temperature/10;
      clear_dsp();
      printf("%s: %d.%d ", a[channel_display], temperature, temp_tenth);
      putchar(unit_temp);
      update_lcd_dog();
      __EEGET(temp_limit, channel_display);
       if(flag & (1 << 0))
          temp_int = ((signed int)(temp_limit)*9)/5 + 32;
       else
         temp_int = (signed int)temp_limit;
       
       if(((temp_int != 0) && 
          (temp_int <= temperature)) || present_state == Alert)
      {
        index = 16;
        printf("LIMIT EXCEEDED!!");
        update_lcd_dog();
        SETBIT(PORTD, 0);
        CLEARBIT(PORTD, 0);
      }
      __delay_cycles(8000000);    //delay_for_1 second
    }
  }
}
char eeprom_getchar(int addr)   
{   
  char data; 
  __EEGET(data, addr);
  return data;
}