Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************/
- /*Files to Include */
- /******************************************************************************/
- #if defined(__XC)
- #include <xc.h>
- #elif defined(HI_TECH_C)
- #include <htc.h>
- #endif
- #include <stdint.h>
- #include <stdbool.h>
- #include "delay.h"
- #include "user.h"
- unsigned short int ITERATION_SCALING_VALUE = 64; //yields 1024 to 0 iterations
- /******************************************************************************/
- /* Interrupt Routines */
- /******************************************************************************/
- #ifndef _PIC12
- void interrupt isr(void)
- {
- //if it's the AD interrupt
- if(ADIF==1)
- {
- //delay for some number of NOPs
- doDelay( (((unsigned short int)ADRESH)<<8) + ((unsigned short int)ADRESL) );
- //reset AD int flag
- ADIF = 0;
- }
- }
- #endif
- void doDelay(unsigned short int ANALOG_VALUE)
- {
- unsigned short int GARBAGE_VAL = 0;
- unsigned char TEMP;
- //0 to 65536 value range for unsigned 16 bit int, scalingValue of 64 yields 1024 to 0 iterations
- unsigned short int SCALED_ITERATIONS = ANALOG_VALUE/ITERATION_SCALING_VALUE;
- //iteration period proportional to analog value
- while(GARBAGE_VAL<SCALED_ITERATIONS)
- {
- GARBAGE_VAL++; //to make sure we don't optimize NOPs into nothingness
- }
- if(RB0==0)//toggle PORTB on
- {
- PORTB = TEMP = 0xFF; //make sure PORTB has time to process the change
- }
- else //toggle PORTB off
- {
- PORTB = TEMP = 0x00; //make sure PORTB has time to process the change
- }
- INTF=0; //unset INTF if set
- }
Advertisement
Add Comment
Please, Sign In to add comment