WORD bug


Closed Thread
Results 1 to 7 of 7

Thread: WORD bug

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Yettie,

    I couldn't get your code to compile without errors. Try this;
    Code:
    @ DEVICE MCLR_OFF,LVP_OFF,HS_OSC,WDT_OFF
    DEFINE  OSC 8
    define  debug_reg    	porta		'nevermind my serial LCD display debugger
    define  debug_bit   	0
    define  debug_baud   	2400
    define  debug_mode   	1
    
    define  inthand     	checkNow
     
    CMCON=7
    TRISB.3=0
    
    'Variables for saving state in interrupt handler
    wsave	           VAR	BYTE $70 system		' Saves W
    ssave	           VAR	BYTE bank0 system	' Saves STATUS
    psave	           VAR	BYTE bank0 system	' Saves PCLATH
    fsave	           VAR	BYTE bank0 system	' Saves FSR
    time	           var	word
    flag               var  byte
    decideTimeInterval var	word
    TIMEINTERVAL       con  600
    
    ;-----------------------
    setup:
      debug   12,"Starting",10,13,"   Program",4
      pause   2000
      
      intcon  = %11000000   ;setting up gie and peie bits
      time    = 3036          	;calibrated to have 31.25ms scale
      tmr1H   = time.highbyte
      tmr1L   = time.lowbyte   	;65536 - time (preload value)
      flag    = 0
      decideTimeInterval = 0
      PIR1.0  = 0
      PIE1.0  = 1
    
      T1CON   = %00110001    ;setting up to 1:8 prescale
                              	;31.25ms x 8 = 250ms/count
    ;--------------------------------
    main:
      if flag = 4 then        	;(250ms x 4 = 1s) second ticker
         flag = 0
         decideTimeInterval = decideTimeInterval + 1
         gosub  updateTime
      endif
    
      if decideTimeInterval = TIMEINTERVAL then		;this one is the notorious routine. it's just a reset condition.
         decideTimeInterval = 0				;It resets unexpectedly.  In contrast to this,
      endif							;changing the decideTimeInterval to BYTE and of course
    							;TIMEINTERVAL <= 255 will function properly
      goto main
    ;----------------------------
    updateTime:
      DEBUG "Time:",#decideTimeInterVal
      return
    ;------------------------
    ;interrupt handler
    asm
    checkNow
        ; Save FSR, PCLATH, STATUS and W registers
        movwf	 wsave          ; Save W
        swapf	STATUS, W   ; Swap STATUS to W (swap avoids changing STATUS)
        clrf	STATUS	     ; Clear STATUS
        movwf	ssave	     ; Save swapped STATUS
        movf	PCLATH, W   ; Move PCLATH to W
        movwf psave	     ; Save PCLATH
    	
    	; isr routine
        bsf STATUS,RP0  ; bank 1
        bcf PIE1,0
        bcf STATUS,RP0  ; bank 0
        incf _flag,f    ; increment flag
        movlw 0x8
        xorwf PORTB,f   ; toggle portb.3
        movf _time,W
        movwf TMR1L
        movf _time+1,W
        movwf TMR1H 
        bcf PIR1,0
        bsf STATUS,RP0  ; bank 1
        bsf PIE1,0
        bcf STATUS,RP0  ; bank 0
        
        ; Restore FSR, PCLATH, STATUS and W registers
        movf	fsave, W      ; retrieve FSR value
        movwf	FSR	     ; Restore it to FSR
        movf	psave, W	     ; Retrieve PCLATH value
        movwf	PCLATH	     ; Restore it to PCLATH
        swapf	ssave, W	     ; Retrieve the swapped STATUS value (swap to avoid changing STATUS)
        movwf	STATUS	     ; Restore it to STATUS
        swapf	wsave, F	     ; Swap the stored W value
        swapf	wsave, W     ; Restore it to W (swap to avoid changing STATUS)
        retfie		     ; Return from the interrupt    
    endasm      
    
        end
    Look in the manual, and at some of the MeLabs examples for assembler interrupts to find out why it works.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Aug 2005
    Location
    antipolo city, philippines
    Posts
    23


    Did you find this post helpful? Yes | No

    Default It's working

    Hi Bruce

    the code is actually working to my circuit. it's just that there might have some differences in our compilers. i'm compiling it in PBP with IDE of microcode. just to study the (bug?), i'm changing the "time" variable to WORD or BYTE modifier. using the WORD seems to be not working properly other than the byte. i already prototyped this program and testing it further. I will share you further info of what more I can find out. thanks!

    Regards,
    Yettie
    yettie

    We should learn "KISS" - Keep It Simple Stupid...

Similar Threads

  1. Read/Write Problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th February 2010, 01:51
  2. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 07:25
  3. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  4. DS2760 Thermocouple Kit from Parallax in PicBasicPro
    By seanharmon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th July 2008, 23:19
  5. calculation problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2006, 15:23

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts