USBPIC User System and Library Functions defines: int_disable; // disable interrupts, use sparingly int_enable; // enable interrupts maincode.c -- Initialization and timer interrupt: void setTicks( word val ); // set the tick counter word getTicks(); // get the tick counter timer code may be configured to call or post: USE_TickFunc( word T0ticks ); // Called on every tick USE_TickTask( word T0ticks ); // Posted on every tick USE_WrapTask( word T0ticks ); // Posted every 65K ticks main() calls: userInit(); // set up user stuff before interrupts are enabled scheduler.c -- User task scheduler: void postTask( // put a user task in the schedule queue word ticks, // timer ticks until execution -- // 0==now, -1==empty, -2== busy PFV func, // pointer to function to execute word arg ); // function argument, may be pointer void repostTask( // repost the current task in schedule queue word ticks, // ticks until exec word arg ); // (new) argument value scheduler loop will post: USE_MessageTask( UPIC_Msg *data ); // when a USB message is received p18adc.c -- ADC control and interrupt: ADC code may be configured to call or post: USE_ADCFunc( word ADCnum ); // called on each conversion, // arg == ADC number 0-3 USE_ADCTask( word ADCnum ); // posted on each conversion // arg == ADC number 0-3 USE_ADCLoopTask( USE_NumADC ); // posted after each set of convs // arg == total number of ADC channels results are in: byte ADCvalues[USE_NumADC]; // ADC results, high order 8-bits only matrix.c -- MATRIX board output control: void clrMout(void); // clear all output bits void togYBit( byte bit, byte val ); // set Y bit=val -- pullup, U4 void togXBit( byte bit, byte val ); // set X bit=val -- pulldown, U5 for matrix scan interrupt behavior: void clrMBuf(void); // clear the output buffer to 0's void setMBuf(void); // set the output buffer to 1's void setMBit( byte x, byte y ); // set x,y coordinate, 0-7x0-7 void clrMBit( byte x, byte y ); // clear x,y coordinate, 0-7x0-7 void setOutBit( byte n ); // set by bit number, 0-63 void clrOutBit( byte n ); // clear by bit number, 0-63 p18pwm.c -- mostly useless initialization for MCC18 library functions if configured will be called from main() then use MicroChip lib funcitons in: MCC18/src/pmc_common/PWM stepper.c -- TRANS and HBSW board Stepper motor sequencing, done in timer interrupt: note: call with speed==0 to stop driver void startStepper1( // start Stepper driver 1 byte steps, // steps to do, 0-254, or 255 forever byte speed, // timer ticks per step byte dir ); // direction 0,1 void startStepper2( // start Stepper driver 1 byte steps, // steps to do, 0-254, or 255 forever byte speed, // timer ticks per step byte dir ); // direction 0,1 Stepper code may be configured to post: USE_Step1Task( word steps ) // on each step USE_Step1DoneTask( word steps ) // after completion of all steps USE_Step2Task( word steps ) // on each step USE_Step2DoneTask( word steps ) // after completion of all steps Accessible data structures: StepperControl StepControl1; StepperControl StepControl2; tswitch.c - TRANS and HBSW board direct Switch control: void tsw_allstop(void); // turn off all switches byte tsw_get( // return value bit-mask of specified switches byte mask ); // bitmask of switches of interest void tsw_set( // set switch values byte mask, // bitmask of switches of interest byte state ); // state: 0,1 Off,On tswtime.c -- TRANS and HBSW board timer-task Switch control: void tsw_switch( // turn ON specified switches for time byte mask, // bitmask of switches of interest byte state, // state: 0,1 Off,On -- if OFF then no timer is used word time ); // timer ticks to remain ON Switch code may be configured to call this from Off Task: USE_TswDone( // notify that switch(es) are Off word mask ); // bitmask of switches of interest hbridge.c -- HBSW board H-bridge motor control note: call with speed==stop* to stop driver void startHbridgeA( // start Hbridge driver A byte steps, // steps to do, 1-254, or 255 forever byte speed, // timer ticks per ON phase of step // 1-100, 0=stopfree, 0x80=stopbrake byte dir ); // direction 0,1 void startHbridgeB( // start Hbridge driver B byte steps, // steps to do, 1-254, or 255 forever byte speed, // timer ticks per ON phase of step // 1-100, 0=stopfree, 0x80=stopbrake byte dir ); // direction 0,1 Hbridge code may be configured to post: USE_HBATask( word steps ) // on each PWM on "step" USE_HBADoneTask( word steps ) // after completion of all steps USE_HBBTask( word steps ) // on each PWM on "step" USE_HBBDoneTask( word steps ) // after completion of all steps data structures: HbridgeControl HbControlA; HbridgeControl HbControlB; USB messaging functions -- sendmsg.c -- Lookup and manage sending of specific message types: UPIC_Msg* getSendMsg( // return an active message of given type byte type ); // user message type byte postSendMsg( // send message if it exceeds the given length UPIC_Msg *msg, // message buffer byte length ); // trigger at given length USBAppendMsg.c -- Message data buffer write: byte USBAppendMsg( // write data into message buffer UPIC_Msg *msg, // message buffer byte *data, // data to copy byte len ); // length of data USBGetTxMsg.c -- Low level message buffer management: UPIC_Msg *USBGetTxMsg( // create and return message of given type byte type ); // user message type USBmsg.c -- Utility funcitons: BOOL USBReady(void); // return TRUE if USB is operational void USBPostTxMsg( // send whatever is in the message now UPIC_Msg *msg ); // message buffer In stub directory: Stub functions to be replaced by user as needed.... ADCFunc.c -- Function called on each ADC conversion. ADCTask.c -- Task posted on each ADC conversion. ADCLoopTask.c -- Task posted at end of each set of conversions. messageTask.c -- Task posted when a USB message is received. tickFunc.c -- Function called on each timer tick. tickTask.c -- Task posted on each timer tick. wrapTask.c -- Task posted on each timer wrap-around, ~65K ticks. Util functions sendout.c -- Put a value on all the transistor switch outputs