Help with configuring


Closed Thread
Results 1 to 10 of 10
  1. #1

    Default Help with configuring

    Hello there. I have written a simple code but it seems not to work properly. I am not sure what I am missing here and any help will be appreciated.

    The code is as follows:
    Code:
    #CONFIG
        ifdef PM_USED
            device  pic16F688, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
        else
            __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_ON & _CPD_ON & _BOD_ON & _IESO_ON & _FCMEN_ON
        endif
    #ENDCONFIG
    DEFINE OSC 8       ' OSCCON defaults to 8MHz on reset
    DEFINE NO_CLRWDT 1
    Include   "modedefs.bas"
    
    ' declare the interrupt handler
    define INTHAND _ISR
    
    goto main
    
    ISR:
    asm
    
    ; my asm code
    
    endasm
    
    main:
            PAUSE 50
    	OSCCON = %01110001 ' Internal Oscillator 8MHz
            TRISA = %000100
            TRISC = %000010
            CMCON0 = 7
            ANSEL = 0               ' NO ANALOGS
            OPTION_REG = %10000011  ' RAPU = off, PS 1:16 to TMR0
            PORTA=0
            PORTC=0
            
            ' setup iZCD to interrupt on change
    '        INTCON= %10110000
            '         |         Global interrupts enabled
            '           |       Timer0 interrupt enabled
            '            |      Zero Crossing interrupt enabled
            '             ----  Flags are cleared
     while 1
    	toggle PortA.4
    	pause 500
    wend
    When I comment the INTCON, my led blinks fine @ 500mS. When I uncomment it, the timings go out.
    I want to run my PIC16F688 at internal 8MHz and not sure if I am missing any configuration register.
    Last edited by financecatalyst; - 15th August 2014 at 08:03.
    ___________________
    WHY things get boring when they work just fine?

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Help with configuring

    Anyone?????
    ___________________
    WHY things get boring when they work just fine?

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Help with configuring

    if you enable interrupts and provide no code to service the interrupt and worse still provide no code to reset the interrupt flag what do you expect to happen ?

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Help with configuring

    Here you are:
    Code:
    ISR:
    asm
            movwf   wsave           ; Save WREG
            swapf   STATUS, W
            clrf    STATUS          ; Point to bank 0
            movwf   ssave           ; Save STATUS
            movf    FSR,w
            movwf   fsave          ; save FSR
            movf    PCLATH, W       ; Save PCLATH
            movwf   psave
    
    
            ; get ready to jump within the ISR page
            movlw   ((INTHAND) >> 8) ; Set PCLATH for jump
            movwf   PCLATH
            btfsc   INTCON, INTF
            goto    ZeroCrossingInt
    
    T0Overflow
            bcf     INTCON, T0IF    ; clear the timer overflow flag
    
            goto    EndInt
    
    ZeroCrossingInt
            bcf     INTCON, INTF    ; clear the interrupt
    
    EndInt  ; restore the machine state and return from interrupts
            movf    fsave,w
            movwf   FSR             ; restore FSR
            movf    psave,w
            movwf   PCLATH          ; restore PCH
            swapf   ssave,w
            movwf   STATUS          ; restore Status
            swapf   wsave,f
            swapf   wsave,w         ; restore WREG
            retfie
    endasm
    ___________________
    WHY things get boring when they work just fine?

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Help with configuring

    I cant see that you have declared wsave ,ssave and psave vars ?

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Help with configuring

    I missed that.

    Code:
    wsave       var byte    $70     SYSTEM          ' safe for W in all banks
    ssave       var byte    BANK0   SYSTEM          ' save STATUS
    psave       var byte    BANK0   SYSTEM          ' save PCLATH
    fsave       var byte    BANK0   SYSTEM          ' save FSR
    ___________________
    WHY things get boring when they work just fine?

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Help with configuring

    dt ints is easier

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: Help with configuring

    I know that. But latency causes problem.
    ___________________
    WHY things get boring when they work just fine?

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Help with configuring

    Quote Originally Posted by financecatalyst View Post
    I know that. But latency causes problem.
    What latency? I have never noticed any with DT's INTS.
    Dave
    Always wear safety glasses while programming.

  10. #10


    Did you find this post helpful? Yes | No

    Default Re: Help with configuring

    Suggestion: Simplify your job by switching to a 16F1823. Same pinout as your present PIC but with automatic context saving.

Similar Threads

  1. configuring AD converter in a 12F615
    By tekart in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 1st June 2011, 03:38
  2. Configuring 16F616
    By Tobias in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th February 2009, 16:28
  3. Configuring register problem
    By shawn in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd January 2005, 20:03
  4. configuring the internal oscillator
    By bartman in forum General
    Replies: 12
    Last Post: - 30th November 2004, 00:41
  5. need help configuring 16F628
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd March 2004, 18:59

Members who have read this thread : 1

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