First test program, but strange results


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189

    Unhappy First test program, but strange results

    I've programmed the 12F629 chip with this simple program to test the I/O for my larger program:

    start:

    high 0 : pause 2000
    high 1 : pause 2000
    high 2 : pause 2000
    high 4 : pause 2000
    high 5 : pause 2000
    low 0 : pause 2000
    low 1 : pause 2000
    low 2 : pause 2000
    low 4 : pause 2000
    low 5 : pause 2000

    goto start

    end

    Should be straight forward, but this is what happens.

    Port 0 goes high and lights a LED.

    Port 1 then goes high and lights a LED <em>BUT</em> port 0 then goes low at the exact same time and stays off.

    Port 2 goes high and lights an LED, but at the same time port 1 goes low and stays off.

    The rest of the results are as you would expect so it is port 0 and port 1 that are acting strange. They obviously are going high and low, but somehow are linked to each other??

    Some advice would be appreciate. I'm happy that I have got something to light up, but with such a simple program I was not expecting these odd results.

    Thanks.

    Bart

  2. #2
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    Okay, I think I figured this out myself.

    Port 0 and 1 also are comparitor ports. I added <b>poke $19,00000111</b> to the beginning of the program and now it works perfectly. From the chip data sheet I decided that this command would turn off that feature and I hoped that with it off, the new default would become general I/O ports.

    I am beginning to love this <b>poke</b> command!

    But this does raise another question in my mind. How does one know what is default for a port and what isn't? If I read the data sheet all the I/O functions are listed first on the pin call out as well as each pin description. To me that suggest they are the default, but apparently not. Trial and error to discover the results seem odd.

    Bart

  3. #3
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Hi Bart,

    I assume you're using the "old" PBC since you use Poke. If you use PBP you can write "CMCON = $07", it does the same thing but is much easier to read.

    If you look at Table 2-1(on page 9 in my datasheet) you can see a column on the right side that's called "Value on POR Reset". That's your overview, for more details you need to check each register. "CMCON" is listed in chapter 6.0(page 33 in my datasheet). There you'll find a description of what each bit does to your PIC, also if it's read/writeable and POR/"default" value.

    /Ingvar

  4. #4
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Yes, I'm using pbc NOT the pro version. Too much cash (over $300.00 Canadian). The "crippled" cheap version was bad enough for cost.

    I'll check out the datasheet again for future reference. I think I have all the appropriate pokes in place now. The test program was working anyway.

    Thanks.

    Bart

  5. #5
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    Ingvar -

    I can find the table you refer to and I have looked at the tables in more detail. I'm still hard pressed to see where it is determined what the "default" pin settings are. Possibly in a terminology that I do not recognize as such.

    Bart

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


    Did you find this post helpful? Yes | No

    Default

    Hi Bartman,

    Usual terminology POR=Power On Reset=Default value

    this is what you are finding in datasheet Table 2-1, page 9.
    Steve

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

  7. #7
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    If you want a descripion that tells you that ......GPIO.0 will start up as an analogue comparator input pin .... or whatever, you're in bad luck. No such table, you'll have to write your own. The clostest one is Table 3-1(page 24) , that table lists all register associated with GPIO, it also lists their POR("default") values. From there you need to check each register separatley, to see how the individual bits affect each pin on your Pic.

    /Ingvar

  8. #8
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    Okay. I see what you guys are saying. I'll look at that again and see if I can now decode it.

    Thanks.

    Bart

  9. #9
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    So, when it comes to general I/O settings it is just the TRISIO that needs poking correct? GPIO is a function within and requires no other setting?

    I went back to the table now that I know what to look for and that helped a lot.

    Thanks.

    Bart

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


    Did you find this post helpful? Yes | No

    Default

    So, when it comes to general I/O settings it is just the TRISIO that needs poking correct?
    correct!!!


    GPIO is a function within and requires no other setting?
    correct too. the only thing you have to be carefull is the POR default on some pin. Ex some have internal analog pin. If you don't need them in analog, you must turn them to digital. But you already know that!!!

    regards
    Steve

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

  11. #11
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    Is it the TRISIO that tells them to be digital or the poke I used to turn off the comparator?

    The thing is flashing lights so I have to assume it is pulsing properly with what I have done (which is set TRISIO to output and turn off the comparator operation).

    Bart

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


    Did you find this post helpful? Yes | No

    Default

    TRISIO set the pin direction: input or output

    your POKE to ANSEL or CMCON: is set the input mode, digital or analog.
    Steve

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

  13. #13
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    All good then. The ANSEL isn't applicable to this chip as it has no analog capabilities.

    Thanks. I'll need to remember this for the future if I built anything else using different chips.

    Bart

Similar Threads

  1. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  2. RC - connection using RCTime produces strange results
    By selbstdual in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th February 2007, 16:16
  3. Searches
    By bearpawz in forum Forum Requests
    Replies: 11
    Last Post: - 7th November 2005, 18:47
  4. Help! - Very strange results with ShiftIn/ShiftOut
    By khufumen in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd February 2005, 22:21
  5. I'm getting strange Results using POT or RCTIME on PortB (or GPIO Port)
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 20:01

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