Continue to Site

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.

  • 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.

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

Status
Not open for further replies.
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.
 
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.
 
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"?
 
i am sorry that you got so pissed off by my writing.
I didn't get upset by your writing. I got upset by your (lack of) reading.
what exactly did you mean when you said "Any pins that are analogue work well as digital outputs"?

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.
 
Exactly what I said.

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".
 
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.
 
Any pins that are analogue work well as digital outputs".
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.
If PORTC=~PORTC doesn't work then some possible reasons are,

1. You have the pins still set to analogue as pointed out by Burt.
2. You have overloaded the pins and this is forcing them high/low. Normally by connecting LEDs without series resistors.
3. You forgot to switch the pins to output.
4. The pins are configured for some other peripheral.
5. One of the other reasons for pics not working - not programmed, no oscillator, no power etc.

Mike.
Most of the time it always 1. or 4. like Mike posted
 
Last edited:
Well, when a pin is configured as an analogue pin it works very well as a digital output - there is no analogue output mode.

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.

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.

we understood that part very well. thanks.
 
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

that sounds like an incorrect port configuration, doesn't it? are those pins always high or always low?
 
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.
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.
are those pins always high or always low?
They come on High
 
Last edited:
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
 
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.

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?

However, if you try to read it you will get zero rather than the last value written.

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

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

where did that come from?
 
There a lot of people that ask why this not working and it most all ways because they left
the PORT set as analogue.

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.
 
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.
 
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
 
the led wouldn't blink on portC ... turned adc off and all is well LOL

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, :).
 
It is bad practice to set pins to output and to write to them when they are configured as analogue.

that's improvement #1!

You presented code earlier in this thread that did just that.

how did "my" code do that?

You obviously haven't consulted a data sheet as you keep repeating the same stupid question.

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

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.

that's a nice excuse to get yourself out of a trouble, right?
 
hopefully you have convinced yourself by now that the reason the code did not work is that the port configuration is wrong.
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
 
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
 
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
 
Status
Not open for further replies.

Latest threads

Back
Top