Help with code


Closed Thread
Results 1 to 8 of 8

Thread: Help with code

  1. #1

    Question Help with code

    Hello, the code is :
    Code:
    '// PIC 16F877A
    ADCON1=7
    CMCON=7
    OPTION_REG=%00000111
    TRISA=%111111 : TRISE=%111
    TRISB=0 : PORTB=0
    TRISC=%10001111 : PORTC=0
    TRISD=%00000011 : PORTD=0
    CCP1CON=0
    @ ERRORLEVEL -306
    B VAR BYTE
    C VARY BYTE
    D VAR BYTE
    		B=PortB : C[0]=PortC.5
    		for q=2 to 7
    			D[q]=PortD[q]
    		next q
    	IF B=0 and C=0 and D=0 then
    		toggle BUZ: pause 20
    	endif
    As you can see I am trying to load ports into the variables. All ports above are outputs.
    The problem:
    When any of portB is made high in the main program then buzzer is off, as it should be, same is true for portc.5, but PortD is not being read properly. Even if lets say I make PortD.2 to D.7 high, one by one in the code for lets say 2 sec each (2 sec high/ 2 sec low) the buzzer is toggling non-stop. Though it should only toggle during 2 sec Low period.
    Can someone help please? Thanks
    ___________________
    WHY things get boring when they work just fine?

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Post

    Hi Finance

    1) C VARY Byte

    2) Your program loops ... only because there's no END in the END ... and program counter continues to count, overflows, then program restarts @ address 0000 ...

    That's why Buzzer toggles ...


    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3


    Did you find this post helpful? Yes | No

    Question

    Thanks for the reply. Sorry it was a typing mistake @ vary
    This is not my full code. My actual code runs fine with reading port c.5 & Port B.

    My problem is correctly reading Port D.2 to D.7 into variable D. and if any of the pin is high, the buzzer should NOT toggle.
    But for some reason Variable D=0 is true even if Lets say PortD.2 or D.3 to D.7 is high i.e.=1

    I picked important lines from my code to explain the Problem.
    Is there any other way which can load PortD.2 to D.7 into variable D?
    ___________________
    WHY things get boring when they work just fine?

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Ok

    so ...

    reading PORTD ...

    Code:
    		
    B=PortB : C=PortC.5
    
    D = PORTD & %11111100 ' read PORTD and mask port D.0 and D.1
    
    IF B=0 and C=0 and D=0 then
    		toggle BUZ: pause 20
    	endif
    should fit ... no indexing necessary !

    ( BTW ... not sure it was working so fine ... lol )

    Alain
    Last edited by Acetronics2; - 11th April 2010 at 10:27.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Thanks a lot. Problem solved.
    ___________________
    WHY things get boring when they work just fine?

  6. #6


    Did you find this post helpful? Yes | No

    Question 1 MOre Problem

    This time the problem is with 16F676. While compiling I get the following errors
    Code:
    ERROR: Unable to fit variable RM2_Save
    ERROR: Unable to fit variable RR1_Save
    ERROR: Unable to fit variable RR2_Save
    ERROR: Unable to fit variable RS1_Save
    ERROR: Unable to fit variable RS2_Save
    I am using DT-Interrupts in this code. Can some1 help me to get rid of these problems and what can I comment out in the ReEnterPBP or the other DT_INTS-14. Thanks
    ___________________
    WHY things get boring when they work just fine?

  7. #7


    Did you find this post helpful? Yes | No

    Question

    The only thing I am doing in the ISR is the following:
    Code:
    ToggleLEDF:
         If F1=1 then Toggle PortA.0
         If F2=1 then Toggle PortA.1
         If F3=1 then Toggle PortA.2
    @ INT_RETURN
    
    '---[TMR2 - interrupt handler]--------------------------------------------------
    ToggleLEDS:
         If S1=1 then Toggle PortA.0
         If S2=1 then Toggle PortA.1
         If S3=1 then Toggle PortA.2
    	pause 100
    @ INT_RETURN
    ___________________
    WHY things get boring when they work just fine?

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink too small a RAM !!!

    Sure 64 Bytes of SRAM is a bit weak to handle DT-Interrupts ....

    Try to spare (re-use ) 5 of your byte variables ... may be you can re-use B,C,D and two other temporary variables elsewhere in your Program ...

    @ first C can be declared as a BIT ... probably others too ...


    Or change for a Wider RAM Chip

    Or Ask Darrel for a "Fast Interrupt" Option saving only the " live " registers and letting you choose which variables really need to be saved ... such C " #pragma disablecontexsaving " directive ( I'd love such an option !!! )

    Alain
    Last edited by Acetronics2; - 11th April 2010 at 14:09.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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