CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pullups on PIC12F675
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
FJMSoft



Joined: 20 Oct 2013
Posts: 36

View user's profile Send private message

Pullups on PIC12F675
PostPosted: Sun Oct 20, 2013 10:01 pm     Reply with quote

Hello.
I was trying to configure the pullups on PIC12F675.
What I found was using "port_a_pullups" was not working as expected.
Setting to zero pullups are off.
Setting to anything above zero then the pullups are on.
But no way to set pullup on a single port.
Looks like the command "port_a_pullups" is setting only the GPPU bit of microcontroller.
The only way I could set a single was manually declaring and setting the WPU byte using this:
Code:

#byte WPU = 0x95
WPU = 0b00000100; //(example)

Am I doing something wrong?
There is a easier way to do this?

Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 20, 2013 10:25 pm     Reply with quote

Always post your compiler version on a question about a suspected bug.

Last edited by PCM programmer on Sun Oct 20, 2013 11:17 pm; edited 2 times in total
FJMSoft



Joined: 20 Oct 2013
Posts: 36

View user's profile Send private message

PostPosted: Sun Oct 20, 2013 11:10 pm     Reply with quote

I'm sorry, was my first post...
5.008 is this?

Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 20, 2013 11:18 pm     Reply with quote

I just did a little survey. It's been broken for a long time, starting with vs. 4.132.

vs. 4.068:
Code:

.................... port_a_pullups(0x01);
0016:  MOVLW  01
0017:  BSF    STATUS.RP0
0018:  MOVWF  WPU
0019:  BCF    OPTION_REG.GPPU


vs. 4.125:
Code:

.................... port_a_pullups(0x01);
0016:  MOVLW  01
0017:  BSF    STATUS.RP0
0018:  MOVWF  WPU
0019:  BCF    OPTION_REG.GPPU


vs. 4.131:
Code:
.................... port_a_pullups(0x01);
0016:  MOVLW  01
0017:  BSF    STATUS.RP0
0018:  MOVWF  WPU
0019:  BCF    OPTION_REG.GPPU


vs. 4.132 - Broken: (Since April 8, 2012)
Code:

.................... port_a_pullups(0x01);
0016:  BSF    STATUS.RP0
0017:  BCF    OPTION_REG.GPPU


vs. 4.135 - Broken:
Code:

.................... port_a_pullups(0x01);
0016:  BSF    STATUS.RP0
0017:  BCF    OPTION_REG.GPPU


vs. 4.141 - Broken:
Code:

.................... port_a_pullups(0x01);
0013:  BSF    STATUS.RP0
0014:  BCF    OPTION_REG.GPPU


vs. 5.008 - Broken:
Code:

.................... port_a_pullups(0x01);
0016:  BSF    STATUS.RP0
0017:  BCF    OPTION_REG.GPPU


vs. 5.012 - Broken:
Code:

.................... port_a_pullups(0x01);
0016:  BSF    STATUS.RP0
0017:  BCF    OPTION_REG.GPPU
FJMSoft



Joined: 20 Oct 2013
Posts: 36

View user's profile Send private message

PostPosted: Sun Oct 20, 2013 11:29 pm     Reply with quote

Sorry friend, I'm a little new to this...
What this means?
I understood that the command "port_a_pullups" is really not working as expected.
So, how to set the pullups?
The way I said is ok?

Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 21, 2013 12:05 am     Reply with quote

You also need to set the GPPU bit in OPTION_REG = 0. To help you do
that, I've posted a macro that will substitute correct code for the defective
built-in function. Just place the macro code above main(), as shown below
and call the port_a_pullups() function as shown in main(). That's all you
need to fix it.
Code:

#include <12F675.h>
#fuses INTRC_IO, NOWDT, NOMCLR, PUT, BROWNOUT
#use delay(clock=4M)

// This macro will fix a bug by replacing the built-in
// CCS function with the following code.
#byte OPTION_REG = 0x81
#byte WPU = 0x95
#define port_a_pullups(mask) \
WPU=mask;                   \
if(mask)                    \
  bit_clear(OPTION_REG, 7); \
else                        \   
  bit_set(OPTION_REG, 7)

//======================
void main()
{

port_a_pullups(1);

while(1);
}


With that macro, it will produce this code in vs. 5.008. It's correct:
Code:
.................... port_a_pullups(0x01);
0016:  MOVLW  01
0017:  BSF    STATUS.RP0
0018:  MOVWF  WPU
0019:  BCF    OPTION_REG.GPPU


I have emailed CCS Support and reported this bug to them.
FJMSoft



Joined: 20 Oct 2013
Posts: 36

View user's profile Send private message

PostPosted: Mon Oct 21, 2013 4:31 pm     Reply with quote

Hello again PCM.
Friend, looks like this code need to be put in my main C file, right?
Could I put it inside 12F675.h and save it?

Looking at datasheet says GPPU set to 0 enables individual pullups, so dont need to set GPPU every time you set the pullups, code could be simplified (and faster).
Code:

// This macro will fix a bug by replacing the built-in
// CCS function with the following code.
#byte WPU = 0x95
#define port_a_pullups(mask) \
WPU=mask;                   \

//======================


Also, can I do this?

Code:

#bit GPPU = 0x81.7
#define port_a_globalpullups(Pullset) \
GPPU=Pullset;


Please give me your opinion.

I know it is a bit offtopic, but I see bit_set and bit_clear commands, there is a command so I can make a bit equal?
Something like: bit_equal(var,bit,value)

Thank you very much!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 21, 2013 5:48 pm     Reply with quote

My advice is to read the 12F675 data sheet very carefully. I can't give
anything more help on this thread. I already posted a solution.
FJMSoft



Joined: 20 Oct 2013
Posts: 36

View user's profile Send private message

PostPosted: Mon Oct 21, 2013 6:04 pm     Reply with quote

Can you at least answer my question?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 21, 2013 6:12 pm     Reply with quote

No. Someone else can continue this. My macro exactly duplicates the
port_a_pullups() function in a working compiler. That's all I want to do.
FJMSoft



Joined: 20 Oct 2013
Posts: 36

View user's profile Send private message

PostPosted: Mon Oct 21, 2013 6:33 pm     Reply with quote

afff... thank you...
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Tue Oct 22, 2013 1:47 am     Reply with quote

PCM_programmer has completely answered your original question.

On 'bit_equal', if you look in PCM_programmers code, line starting 'if(mask', this code would be a matter of an instant, to convert into a generic version, using either a macro, or a function. Think.

On GPPU, normally pull-ups are enabled once at the start of code.
FJMSoft



Joined: 20 Oct 2013
Posts: 36

View user's profile Send private message

PostPosted: Wed Oct 23, 2013 9:27 pm     Reply with quote

I thought I was having a productive conversation with PCM.
I am new to this language, I have many doubts.
I thought I could at least take the doubts related to the original question on the same topic.
If I can not, okay, no problem.

Now I understand that the code is a macro, I was thinking it could be some kind of overrided command.

But I continued with a question, can you help me?
Can I put the macro within 12F675.h then save?
So I will not need to put the macro in all my codes.

This is really a little off topic, but how can I see the code behind the command in the same way that showed PCM? (Posted: Mon Oct 21, 2013 2:18 am)

Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 23, 2013 10:44 pm     Reply with quote

Quote:
Can I put the macro within 12F675.h then save?

You can do it, but you shouldn't do it. If you ever upgrade the compiler
the .h file will be over-written with the new version, losing your edits.
If you copy the .h file to your local project directory and then edit the
copy you will be sabotaging yourself if you ever upgrade the compiler.
Sometimes in newer versions of the compiler, CCS changes or expands
the meaning of the constants in the .h file. If you are using a header
file from an old version with a new compiler, you can possibly get
unstable behavior of previous working code. This happened to me once,
years ago. That's how I know not to do it.

Quote:
but how can I see the code behind the command ?

Look at the .LST file in your project directory after a successful compilation.
Set the .LST file format to Symbolic or "Normal CCS Format" (ie. hex
register addresses) by going into the Project Options menu.


Quote:

I thought I was having a productive conversation with PCM.

Not exactly. I was impatient to leave. I didn't want to answer questions
all afternoon. Also, I felt that reading the PIC data sheet could have
answered most of your questions, adding to my impatience. Those are
the reasons why I was abrupt. My basic attitude is that learning for
yourself is the best way, if at all possible.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 24, 2013 10:32 am     Reply with quote

This bug was fixed in vs. 5.013. The test program shown below now
produces this code, which is correct. The problem is solved:
Code:

.................... port_a_pullups(1); 
0016:  MOVLW  01
0017:  BSF    STATUS.RP0
0018:  MOVWF  WPU
0019:  BCF    OPTION_REG.GPPU


Test program:
Code:

#include <12F675.h>
#fuses INTRC_IO, NOWDT, NOMCLR, PUT, BROWNOUT
#use delay(clock=4M)

//======================
void main()
{

port_a_pullups(1);

while(1);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group