user_hooks.h
Go to the documentation of this file.
00001 /*
00002  * This file can be used to define custom register addresses
00003  * Just use addresses 100 and above
00004  */
00005  
00006 #define REG_COUNTER_VALUE_L    100
00007 #define REG_COUNTER_VALUE_H    101
00008 #define REG_COUNTER_DIRECTION  102
00009 
00010 unsigned char lift_direction;
00011 int lift_counter;
00012 void userSetup()
00013 {
00014   PCICR |= (1 << PCIE0);  // enable PC interrupt on port A
00015   PCMSK0 |= 1;            // enable interrupt A0
00016   lift_direction = 0;
00017   lift_counter = 0;
00018 }
00019 
00020 ISR(PCINT0_vect){ 
00021   if(lift_direction > 0)
00022     lift_counter++;
00023   else
00024     lift_counter--;
00025 }
00026 
00027 unsigned char userWrite(int addr, unsigned char param)
00028 {
00029   if(addr == REG_COUNTER_DIRECTION){
00030     lift_direction = param;
00031   }else if(addr == REG_COUNTER_VALUE_L){
00032     lift_counter = (lift_counter&0xff00)+param;
00033   }else if(addr == REG_COUNTER_VALUE_H){
00034     lift_counter = (lift_counter&0x00ff)+(param<<8);
00035   }else{
00036     return ERR_INSTRUCTION;
00037   }
00038   return ERR_NONE;
00039 }
00040 
00041 /* Read one byte from register located at addr */
00042 int userRead(int addr)
00043 {
00044   if(addr == REG_COUNTER_DIRECTION){
00045     return lift_direction;    
00046   }else if(addr == REG_COUNTER_VALUE_L){
00047     return lift_counter%256;
00048   }else if(addr == REG_COUNTER_VALUE_H){
00049     return ((unsigned int)lift_counter>>8)%256;
00050   }
00051   return 0; 
00052 }


maxwell_defs
Author(s): Michael Ferguson
autogenerated on Mon Oct 6 2014 02:15:02