1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Hi-Tech C Compiler: What am I doing wrong?

Discussion in 'Microcontrollers' started by micro571, Jun 28, 2009.

  1. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    I am not sure why you want to write to an analog (input) pin. what circumstances would require something like that.

    yes, reading an analog pin will yield zero - the datasheet typically says something about that.
     
  2. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,007
    Likes:
    316
    Location:
    Brisbane Australia
    ONLINE
    You should try reading my reply(s). If you still don't understand then check the data sheet.

    I'll give you a clue. I didn't mention writing to input pins.

    Mike.
     
  3. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    i am sorry that you got so pissed off by my writing.

    what exactly did you mean when you said "Any pins that are analogue work well as digital outputs"?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,007
    Likes:
    316
    Location:
    Brisbane Australia
    ONLINE

    I didn't get upset by your writing. I got upset by your (lack of) reading.
    Exactly what I said.

    I gave 5 reasons earlier why X=~X may not work. You appear to have missed that post or ignored it.

    Mike.
     
  6. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    which I think is "Any pins that are analogue work well as digital outputs but when you read them they always return zero. Hence why a copy will work."

    I was more interested in what you meant by the 1st part of the sentence: "Any pins that are analogue work well as digital outputs".
     
  7. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,007
    Likes:
    316
    Location:
    Brisbane Australia
    ONLINE
    Well, when a pin is configured as an analogue pin it works very well as a digital output - there is no analogue output mode. When you read it, it always reads zero unless you turn the analogue part off. So, x=~x will always write a 1 to any pins configured as analogue.

    Mike.
     
  8. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,791
    Likes:
    134
    Location:
    morristown,tn
    Just can't toggle them LOL I was just trying the posters code and what millwood posted on what I had plugged in my bread board. When It didn't work on portC I read the data sheet and the chip I have has adc on portC. What Mike said always works for me.
    Most of the time it always 1. or 4. like Mike posted
     
    Last edited: Jun 30, 2009
  9. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    so here goes back to my question that got you mad: why would you write anything to an analog pin? - that's how you use it for digital output.

    we understood that part very well. thanks.
     
  10. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    that sounds like an incorrect port configuration, doesn't it? are those pins always high or always low?
     
  11. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,791
    Likes:
    134
    Location:
    morristown,tn
    There a lot of people that ask why this not working and it most all ways because they left
    the PORT set as analogue. Then when you make the pin high it come on but will not go back off lol. I didn't no that my chip had it on PORTC and I was using ADC on PortA
    All ways need to read the data sheet.
    They come on High
     
    Last edited: Jun 30, 2009
  12. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,007
    Likes:
    316
    Location:
    Brisbane Australia
    ONLINE
    If you read the data sheet you would see that any pin that is configured as analogue but set to output will act as a digital output. However, if you try to read it you will get zero rather than the last value written.

    BTW, it was you that started the writing to analogue pins with your PORTC=~PORTC.

    Also, I wasn't mad. I just couldn't be bothered writing an explanation when some research by yourself would have answered your question. As it happens, answering the question would have been easier.

    Mike
     
  13. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    let's try it one more time: under what circumstance would you envision writing to an analog (input) pin? what kind of purpose do you expect out of that?

    I believe that to be well understood before this discussion started.

    where did that come from?
     
  14. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    this goes to incorrect port / pin configuration. It is always prudent to explicitly set the ports appropriately so you don't run into issues like this.

    it is kind like you crank the engine in a car without gas and you blame the key for the problem.

    the code X=~X will always work, as long as you set the ports correctly - which is a given.

    if you can post your code, maybe we can help fix the port configuration.
     
  15. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,007
    Likes:
    316
    Location:
    Brisbane Australia
    ONLINE
    I have run out of ways to explain this, I've tried the "idiots guide to ..." approach, the quote the data sheet approach and the "put it in simplest terms approach" and you just can't grasp it.

    One last try,
    It is bad practice to set pins to output and to write to them when they are configured as analogue. You presented code earlier in this thread that did just that. I have since been explaining why your code doesn't work. You obviously haven't consulted a data sheet as you keep repeating the same stupid question.

    It's bedtime for me. If you still don't understand it in 8 hours time then please reread this thread or consult a data sheet.

    Mike.
     
  16. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,791
    Likes:
    134
    Location:
    morristown,tn
    I don't need any code fixed lol How many time do I have to say this I no why it wasn't working I no it should of worked I was trying your code you posted and the poster code to see what happen then you run it and what made it not work He had to have the PORTS set wrong and then you post the toggle so I tried it and the led wouldn't blink on portC so i read the data sheet to see what was on portC and it had ADC on it to turned adc off and all is well LOL
     
  17. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    hopefully you have convinced yourself by now that the reason the code did not work is that the port configuration is wrong.

    I reset my case.

    BTW, I am still curious to see the code you used to try my toggle, :).
     
  18. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    that's improvement #1!

    how did "my" code do that?

    you obviously made the wrong assumption about what I did or didn't do.

    that's a nice excuse to get yourself out of a trouble, right?
     
  19. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,791
    Likes:
    134
    Location:
    morristown,tn
    Are you all right
    1. I didn't start this thread
    2. I didn't write the code that was posted
    3. All I did was try the poster code
    4. And your code
    5. I posted why it didn't run.
    6 I said this on page 2 PORT configuration are wrong
    And now we have a baby show of who is right and wrong I don't no about you
    but I was trying to help the poster
     
  20. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,281
    Likes:
    23
    Location:
    Vancouver Canada
    Hi Burt,

    Some people are just very oppositional. Some people on here help others, some just argue. If you take a look at the posts a person makes, then soon you see who helps and who argues.:p
     
  21. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,791
    Likes:
    134
    Location:
    morristown,tn
    BeeBop your so right Mike one of the best to help you with your code he knows the pic
    inside and out. I guess it's all good
     

Share This Page