hi & tfyt, im trying to incorporate hysteresis when an input changes for gpio2 (12c508). when then pin changes state i cant figure out how to get the hysteresis code to operate. i think its something to do with the status register because it wont pick the change of the pin register also when it goes to down count it wont skip (decfsz) when the count register = 0 ive physically coded bsf & bcf code & still cant get it to operate correctly. I'M ABSOLUTELY LOST !!! any help would be appreciated. ------ its for an LDR sensor gpio 0&5 supply permanent power to the ldr circuit gpio 1&4 are to drive the transistor gpio2 ldr sensor input ------ heres the to entire code between the ############ to help point out (if possible) where i'm going wrong thankyou very kindly for your time & guidance, i appreciate it ! glen ############################# list p=12c508a ; list directive to define processor #include ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _MCLRE_OFF & _IntRC_OSC ;****************** REGISTERS ***************************** indf equ 0x00 ; tmro equ 0x01 ; pcl equ 0x02 ; status equ 0x03 ;CPU equates (program memory map) fsr equ 0x04 ; osccal equ 0x05 ; gpio equ 0x06 ; gpio2 equ 2 ; ;****************** VARIABLES ***************************** CntrA equ 0x07 ; CntrB equ 0x08 ; CntrC equ 0x09 ; count equ 0x0A ; newst equ 0x0B ;gpio2 current state oldst equ 0x0C ;gpio2 old state w equ 0 ; destination designators f equ 1 ; destination designators z equ 2 ; c equ 0 ; cntmin equ 0x00 ; cntmax equ 0x05 ;count up value when reached relay on pinst equ gpio2 ;input pin state swon equ 0x23 ;switch = 1 - b'00100011' swoff equ 0x21 ;switch = 0 - b'00100001' ;********************* calibration value ****************************** ; ; ORG 0x1FF ; processor reset vector ; Internal RC calibration value is placed at location 0x1FF by Microchip ; as a movlw k, where the k is a literal value. ORG 0x000 ; coding begins here ; movwf OSCCAL ; update register with factory cal value ;remaining code goes here ;******************* program start ******************************** goto start ; ;**************** prescaler setup ********************************* ######################################################### ;is it more wise to change bit 5 in the option reg below to make gpio2 permanent input ! ######################################################### start movlw b'11000111' ;pullups disabled ,scale 1:256 option ; ;**************** gpio port set-up ********************************* movlw b'00001100' ;i/p PINS 5 --- o/p PINS 2,3,4,6,7 tris gpio ;********************************************************************** movlw cntmin ; movwf count ; ; ============= initialise test setup ============== ; ******** pins 2&7 (gpio0&5) permanently on ******** ; call tmdel ; 1 second delay ; call tmdel ; 1 second delay movlw b'00110011' ;also turn rly on (gpio1&4)for 2 secs tris gpio ; call tmdel ; 1 second delay ; call tmdel ; 1 second delay movlw b'00100001' ;turn rly off (gpio1&4) tris gpio ; movlw 0x00 movwf oldst ; ;============== check if gpio2 changes state ============= ;if gpio2 changes state go to hysteresis , else goto lw chkpin movf gpio,w ;read gpio andlw pinst ;except gpio2 xorwf oldst,w ;are they same btfsc status,z ; goto lw ; xorwf oldst ;store new value of gpio2 call adhyst ;yes add hysteresis goto lw goto chkpin ;********************* sub-routines ******************************* ; ============== check pin state ============= lw btfsc gpio,2 ;chk gpio2 fr 0,skip nxt if 0 goto hi ; goto dwncnt ; hi btfss gpio,2 ;chk gpio2 fr 1,skip nxt if 1 goto lw ; goto upcnt ; ; ============== up/down counters ============= upcnt incf count,f ;increment count movlw 0x02 ;is count subwf count,w ;within the btfsc status,c ;range of subwf count,f ;0 to cntmax btfss status,c ; goto chkpin ; goto on ; dwncnt decfsz count,f ;dec count down #### wont skip if count is zero goto chkpin ; goto off ; ; ============== hysteresis delay ============= adhyst nop ;goto tmdel ; ;goto tmdel return ; ; ============== output controls ============= off movlw b'00100001' ;turn rly off (gpios 1&4) tris gpio ; goto chkpin ; on movlw b'00110011' ;turn rly on (gpios 1&4) tris gpio ; goto chkpin ; ; ============== ontime delay ============= ;Time Delay = 1,000002 s with Osc = 4 MHz tmdel movlw 0x01 ;0x06 movwf CntrA ; lpa decfsz CntrA,f ; goto lpa ; movlw 0x01 ;0x18 movwf CntrB ; lpb decfsz CntrB,f ; goto lpb ; movlw 0x01 ;0xA8 movwf ############################# once again thankyou kindly for your guidance glen -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads