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

Reading a Register of a PICmicro

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
chingB



Joined: 29 Dec 2003
Posts: 81

View user's profile Send private message

Reading a Register of a PICmicro
PostPosted: Sun Nov 07, 2004 5:33 am     Reply with quote

Hello,

How would you be able to read a specific register of a PICmicro... say, PIC18F452 -- register PORTA?

I understand using :
#byte PORTA = 0xF80 --> can be use to write a certain value to a PORTA register?

Anyone can provide me info or a sample code snippet?

BTW would this be also applicable to other PICmicro register?

Thanx
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sun Nov 07, 2004 5:46 am     Reply with quote

Here are a couple of examples. The first is writing to PORTB using the standard output_x() functions. The compiler is responsible for knowing the location of PORTB in the example.

Code:
   output_b(PB_DefData);
   set_tris_b(PB_DefTRIS);


The second methid is more flexible except you need to tell the compiler the location (address) of the register which means the code is processor dependent.

Code:
byte   TXREGM; #locate TXREGM = 0x10 // Transmit Register

//.....
   TXREGM = TxChar;

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
chingB



Joined: 29 Dec 2003
Posts: 81

View user's profile Send private message

PostPosted: Sun Nov 07, 2004 6:00 am     Reply with quote

Thank u asmallri...

The information you provide would be of great help.
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

More info....
PostPosted: Sun Nov 07, 2004 8:06 am     Reply with quote

This question is covered in the FAQ section and shows a more straight forward way of doing it... It also shows how to map a struct to a port.

http://www.ccsinfo.com/faq/?18

<and>

http://www.ccsinfo.com/faq/?1
valemike
Guest







PostPosted: Sun Nov 07, 2004 8:15 am     Reply with quote

I prefer to do bit manipulation the following way:

#byte PIC_THIS_REG 0x20 // for example

If I want to set bit 3:
PIC_THIS_REG |= 0x08; // 0000 1000

If I want to clear bit 3:
PIC_THIS_REG &= ~0x08; // 0000 1000

In fact, there is only one assembly instruction generated by this.
bsf or bcf.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sun Nov 07, 2004 8:39 am     Reply with quote

All these examples really show writing. The really simple answer is

Code:

PORTA = var;  // write to register
var = PORTA; // read from register
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sun Nov 07, 2004 8:47 am     Reply with quote

Quote:
All these examples really show writing. The really simple answer is

This is only simple for registers that have been defined. By default CCS only defines a few. If you want anything else you end up with the second example being a good fit.

Code:
byte   TXREGM; #locate TXREGM = 0x10 // Transmit Register

//.....
   TXREGM = TxChar;

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sun Nov 07, 2004 9:56 am     Reply with quote

Quote:
This is only simple for registers that have been defined. By default CCS only defines a few. If you want anything else you end up with the second example being a good fit.


Read his orginal post. He knows how to do that. He just didn't understand that reading a value was just as simple as writing one.

Quote:
How would you be able to read a specific register of a PICmicro... say, PIC18F452 -- register PORTA?

I understand using :
#byte PORTA = 0xF80 --> can be use to write a certain value to a PORTA register?
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