How does everyone debug their code?


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Are you using MPLAB or MicroCodeStudio ?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Just some footnotes on this (as one newbie to others who may find this thread via google etc).

    If you have a PICKIT2 programmer... you can use it to connect your PIC to your PC (no need to buy MAX232 interfacing chips etc). The Uart tool, is in your pickit2 programmer menu under tools.

    To get text/info out of your PIC & onto your PC using the UArt tool, well, as far as I can gather you have two options...

    1, The DEBUG command - from my understanding this uses software to get the data out your PIC & onto your PC screen via the Pickit2 Uart tool ...the benefit being it's simple to set up, but don't go this route if you venture into 'interupt' territory else you'll end up with all manner of garble onscreen. Take a look at Bruce's answer to my post further up for sample code that works well.

    2. The HSerout command - this uses hardware in my opinion a much better route. Programming wise, it's not really anymore difficult to set up & you shouldn't have problems with interrupts messing with your text. Alas, the downside of using this method with your Pickit2 is that you'll need to wire a switch into your circuit (take a look at the diagram I posted further up to see what I mean)

    If you happen to have a 16f690, then the code below will get you started (I haven't commented each line because, truthfully I haven't got much idea what they all do - but I do know that this code works in setting up HSEROUT with a 16F690!)...

    @MyConfig = _XT_OSC & _WDT_ON & _MCLRE_ON & _CP_OFF
    @MyConfig = MyConfig & _MCLRE_ON & _BOR_OFF
    @ __config MyConfig

    Include "modedefs.bas"

    DEFINE OSC 4
    ' the following three lines set the serial port up as 9600 working with the 4Mhz oscillator freq above
    DEFINE HSER_SPBRG 25
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_CLROERR 1
    ANSELH=0
    ANSEL=0
    CM1CON0 =0
    CM2CON0 =0
    CM2CON1 =0
    adcon1=0
    TRISB.6 = 1
    TRISB.7 = 0
    TRISC=%00000000 ; set all Port C pins as outputs
    rcsta.7=1 'SPEN serial port enable bit
    low Portc.1
    low Portc.2
    low Portc.3

    txsta.7=1 'CSRC : Clock Source Select bit 1 = internal clock
    txsta.6=0 'TX9 : 9-bit Transmit Enable bit 0 = 8 bit.
    txsta.5=1 'TXEN : Transmit Enable bit
    txsta.4=0 'SYNC : USART Mode Select bit 0=asynch
    txsta.3=0 ' N/A
    txsta.2=1 'BRGH : High Baud Rate Select bit
    txsta.1=0 'TRMT : Transmit Shift Register Status bit ( Read only )
    txsta.0=0 'TX9D : 9th bit of transmit data. Can be parity bit.

    loop:
    hserout ["Hello ", 13, 10]
    pause 400
    goto loop
    end


    (the ISCP connector header that the PIC mates with, needs a switch to 'break' Header pin 4 of from PIC pin 19 to pin 10 & Header pin 5 from PIC pin 18 to 12 - flick the switch to go from 'programming mode' to HSEROUT mode)
    Last edited by HankMcSpank; - 20th May 2009 at 17:03.

  3. #3
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Fiy

    Hi,

    Yesterday I hooked up a 16F676 with the PICKIT2 as I always do. Debug didn't work!! Only garbage on the PICKIT2 UART window.

    After hours and hours of struggle I realized, I didn't include the OSCAL Define.

    FIY : 19200 bps works fine with internal 4 MHz
    Code:
            DEFINE OSCCAL_1K 1               ' MUST INCLUDE
            DEFINE OSC 4                         ' USES INTERNAL 4 MHz OSCILLATOR
            DEFINE DEBUG_REG PORTA        ' PORTA.2 IS PGD/AND Rx AS WELL
            DEFINE DEBUG_BIT 0                ' PICKIT2 Rx (Pin 4) 
            DEFINE DEBUG_BAUD 19200       ' Max Baud on Internal Osc ???
            DEFINE DEBUG_MODE 0             ' True
    BTW, PICKIT2 can Regenerate OSCAL through the same ICSP pins. Find it under the tools menu.
    Last edited by sougata; - 22nd May 2009 at 08:19. Reason: Inclusion
    Regards

    Sougata

  4. #4
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    951


    Did you find this post helpful? Yes | No

    Default PIC-Simulator can help too

    Hi there,

    For most of my debugging, I use the PIC-Simulator from OSHONSOFT.

    I can track variables and/or any other info I need, emulate an LCD display, set port states and AD values and lots more.

    Most of the time, I don't even have to build a proto on the breadboard and it is really time-saving.

    IMHO, it is worth the few € it costs and can be an alternative to "hardware" debugging tools.

    http://www.oshonsoft.com/pic.html
    Roger

Similar Threads

  1. N-Bit_MATH
    By Darrel Taylor in forum Code Examples
    Replies: 38
    Last Post: - 16th December 2010, 15:48
  2. debug not working with MPASM assempler
    By santamaria in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th March 2009, 08:51
  3. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 22:31
  4. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  5. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26

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