Strange Behaviour - Simple code+DT_INT+16F676


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1

    Question Strange Behaviour - Simple code+DT_INT+16F676

    Hi, I am facing unexpected behaviour from my PIC.
    I am trying to run a simple code for accepting serial data & checking the state of input pins in between using DT_Interrupts. I have tried to debug by blinking some leds on PICKit only but result is dissapointing again and again. Please help...
    I have attached the code here:

    Code:
    @ __Config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN & _CP & _CPD
    
    pin13  VAR  PortA.0
    pin12   VAR  PortA.1
    pin11  VAR  PortA.2
    'pin4  VAR  PortA.3
    pin3  VAR  PortA.4
    pin2  VAR  PortA.5
    pin10  VAR  PortC.0
    pin9   VAR  PortC.1
    pin8   VAR  PortC.2
    pin7   VAR  PortC.3
    pin6   VAR  PortC.4
    pin5   VAR  PortC.5
    
    '----------Variables declared here----------------
    code  VAR  byte
    
    Include "modedefs.bas"
    INCLUDE "DT_INTS-14.bas"
    INCLUDE "ReEnterPBP.bas"
    '----------Processor Initialisation---------------
    PAUSE 50
    TRISA = %111111
    TRISC = 0
    PORTC = 0
    CMCON = 7
    ANSEL = 0
    OPTION_REG.7=0
    WPUA=%110111
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,     _CHECK,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    T1CON=$31
    
    BB:
    @ INT_ENABLE TMR1_INT
    
    '--------------Main Program starts here-----------
    start:
    
      Serin PORTA.3,N2400,["o9"],code
    @ INT_DISABLE TMR1_INT
      pause 500
      if code=42 then pin5=1
      if code=44 then pin6=1  '.........and so on for portc
    
    goto BB
    
    CHECK:
    toggle portc.0
    toggle portc.1
    if pin2=0 then pin5=0
    while pin2=0
    wend
    if pin3=0 then pin6=0
    while pin3=0
    wend
    if pin13=0 then PORTC=0
    while pin13=0
    wend
    @ INT_RETURN
    The leds at portc.0 & 1 should toggle at regular interval. BUT they show random behaviour, sometimes steady on, then off, then just 1 is on and so on.
    when I remove especially this statement 'if pin13=0 then PORTC=0
    while pin13=0
    wend', chances are good that LEDs will behave normal.
    My DT_INTS-14.bas looks like this:


    Code:
    wsave       var byte    $20     SYSTEM      ' location for W if in bank0
    ;wsave       var byte    $70     SYSTEM     ' alternate save location for W 
                                                ' if using $70, comment out wsave1-3
    '
    ' --- IF any of these three lines cause an error ?? ---------------------------- 
    '       Comment them out to fix the problem ----
    ' -- It depends on which Chip you are using, as to which variables are needed --
    ;wsave1      var byte    $A0     SYSTEM      ' location for W if in bank1
    ;wsave2      var byte    $120    SYSTEM      ' location for W if in bank2
    ;wsave3      var byte    $1A0    SYSTEM      ' location for W if in bank3
    I assume because of this problem only, the serin command is not acting as well when it receives the data.
    Can someone please advise me what am I doing wrong here...?Thanks
    __________________
    ___________________
    WHY things get boring when they work just fine?
    ___________________
    WHY things get boring when they work just fine?

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    What else did you comment out?
    Since it won't fit in a 16F676 as is.
    <br>
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Question

    Quote Originally Posted by Darrel Taylor View Post
    What else did you comment out?
    Since it won't fit in a 16F676 as is.
    <br>
    I also commented in ReEnter...
    T3_SAVE
    T4_SAVE

    I didn't comment out anything else as far as I can remember. I am new to your interrupts, I attach my ReEnter & DT-14 with this reply so you can have an better idea of where I am going wrong. Thanks a lot for the help.

    If you can please also advise me of what more I can comment out to have more space for writing code in ISR.
    Last edited by Darrel Taylor; - 15th February 2010 at 18:29. Reason: Files removed after viewing
    ___________________
    WHY things get boring when they work just fine?

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Well ....

    For a 16F676, you should add ...
    DEFINE OSCCAL_1K 1
    Assuming the chip still has it's calibration value.

    Other than that, I see nothing wrong. Except what you're doing.
    Here's what it does in the simulator.

    <object id='stUkhdQ01IR19ZQlhVXFxaVVFR' width='425' height='344' type='application/x-shockwave-flash' data='http://www.screentoaster.com/swf/STPlayer.swf' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0'><param name='movie' value='http://www.screentoaster.com/swf/STPlayer.swf'/><param name='allowFullScreen' value='true'/><param name='allowScriptAccess' value='always'/><param name='flashvars' value='video=stUkhdQ01IR19ZQlhVXFxaVVFR'/></object>

    I have seen the PICkit2 intermittently interfere with my 44-pin demo board. (complete randomness).
    Disconnecting the PICkit helped.
    <br>
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help.

    Interesting software, is this simulation software available to buy anywhere?

    You mentioned
    DEFINE OSCCAL_1K 1
    Assuming the chip still has it's calibration value
    I use MPLAB wit PBP, could you advise me what settings are required in the software(MPLAB) so it does not delete this value in the PIC please or guide me to any article explaining such detail. Thanks
    ___________________
    WHY things get boring when they work just fine?

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The simulator is Proteus.
    http://www.labcenter.co.uk/index.cfm

    And whether it keeps the calibration intact or not depends on the Programmer.
    PBP, MCS or MPLAB cannot control that.

    Both the PICkit and meLabs programmers will retain the OSCCAL values, but it does it by re-writing the value after erasing.
    If a program cycle fails after erasing, the value can still be lost.

    The PICkit software allows you to recreate an OSCCAL value if lost.
    (I've never tried it though)
    <br>
    DT

Similar Threads

  1. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. 16f819 - acting strange... only does first line of code
    By 4Lewis in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th May 2006, 22:53
  4. hopefully simple code
    By hoyles in forum General
    Replies: 3
    Last Post: - 8th September 2005, 23:24
  5. Timer PIC16F57
    By leonel in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 1st July 2005, 08:14

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