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 CCS Technical Support

ACCESSING REGISTER

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
indiansiva555@gmail.com



Joined: 23 Jun 2012
Posts: 22

View user's profile Send private message

ACCESSING REGISTER
PostPosted: Sat Dec 22, 2012 9:17 am     Reply with quote

I am a beginner.
Please post some examples for accessing the OPTION register and different ways of accessing the registers in PIC using CCS compiler.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sat Dec 22, 2012 9:34 am     Reply with quote

Don't.
99.9% of the time there is no need to directly access registers. Doing so is a 'sure sign' of a programmer thinking in assembler terms, rather than thinking "I'm using a relatively higher level language now".
Function that set the options for you (depend on the chip concerned), but are:

port_b_pullups()
ext_int_edge()
setup_timer_0()

It is like driving an automatic, and insisting on manually changing gear. There are a _few_ occasions, where this may be sensible (manually changing down before overtaking, or on hill descent to give engine braking), but the whole point of paying for the automatic, is to not have to do such things for most of the time....

#byte OPTION=("SFR:OPTION")

Then gives you a variable 'OPTION' that directly accesses the register, but generally, don't do this.

Best Wishes
indiansiva555@gmail.com



Joined: 23 Jun 2012
Posts: 22

View user's profile Send private message

PostPosted: Sat Dec 22, 2012 10:51 am     Reply with quote

Code:
#include <16F877A.h>
#FUSES HS
#FUSES NOWDT
#FUSES NOLVP

#case

#use delay(clock=20MHz)

#define LED       PIN_B4
#define SWITCH1   PIN_B7

void port_b_pullups(char value);

void main()
{
   setup_adc_ports(NO_ANALOGS);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_comparator(NC_NC_NC_NC);
   
   //Example blinking LED program
   while(TRUE)
   {
      port_b_pullups(1);
      if (input(SWITCH1))
      {
         output_high(LED);
         delay_ms(1000);
         output_low(LED);
         delay_ms(1000);
      }
   }
}

This is my program.
The LED blinks without any response to the pin B7. I have used a pull down resistor also.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sat Dec 22, 2012 11:08 am     Reply with quote

Hi,

This thread should be locked, as it's essentially identical to your previous
'Logical AND is not working' thread.... Now, all the same questions, and
troubleshooting suggestions have to be repeated over again....

Frankly, I have serious doubts about a 'C' programmer that shows such little
ability to help themselves.....

Good Luck,

John
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Dec 22, 2012 5:29 pm     Reply with quote

The last code posted was fixed and solved by you in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=49474&start=11
Just add the ! to your program above.

With the internal PortB pullups, the circuit below will work:
Code:
                   
                      ___  Switch 
To                   _|_|_
PIC -----------------o   o------
pin                            |             
B7                            --- Ground
                               -   
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sat Dec 22, 2012 5:51 pm     Reply with quote

Ttelmah wrote:


#byte OPTION=("SFR:OPTION")




I think you meant:

#byte OPTION = getenv("SFR:OPTION")
(i.e. #byte LATB = getenv("SFR:LATB") )

No?
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
indiansiva555@gmail.com



Joined: 23 Jun 2012
Posts: 22

View user's profile Send private message

PostPosted: Sat Dec 22, 2012 11:29 pm     Reply with quote

I got it working with the use of ! but I want to know why I don't get proper results without the use of it. I have also disabled the pull up resistors of PORT B and pulled down PIN B7 externally.
I tried with PIN A0 which does not have any internal pull-ups, but I get the same result for that. Sad
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sun Dec 23, 2012 1:24 am     Reply with quote

If it works with direct access to option, but port_b_pullups doesn't work, then it suggests you are using some 'antique' compiler. Possibly an early V4 version.
If the code doesn't work at all with the internal pullups, but does with an external resistor, then it suggests noise. The internal pullups are _weak_ a few uA only. If you have a reasonable length of wire feeding an input pulled up with these, in a noisy environment, then you will see both 1's and 0's being detected...

Best Wishes
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sun Dec 23, 2012 2:42 am     Reply with quote

bkamen wrote:
Ttelmah wrote:


#byte OPTION=("SFR:OPTION")




I think you meant:

#byte OPTION = getenv("SFR:OPTION")
(i.e. #byte LATB = getenv("SFR:LATB") )

No?

Absolutely. Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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