View previous topic :: View next topic |
Author |
Message |
chingB
Joined: 29 Dec 2003 Posts: 81
|
Reading a Register of a PICmicro |
Posted: Sun Nov 07, 2004 5:33 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Sun Nov 07, 2004 5:46 am |
|
|
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!! |
|
![](templates/subSilver/images/spacer.gif) |
chingB
Joined: 29 Dec 2003 Posts: 81
|
|
Posted: Sun Nov 07, 2004 6:00 am |
|
|
Thank u asmallri...
The information you provide would be of great help. |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
![](templates/subSilver/images/spacer.gif) |
valemike Guest
|
|
Posted: Sun Nov 07, 2004 8:15 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Nov 07, 2004 8:39 am |
|
|
All these examples really show writing. The really simple answer is
Code: |
PORTA = var; // write to register
var = PORTA; // read from register
|
|
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Sun Nov 07, 2004 8:47 am |
|
|
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!! |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Nov 07, 2004 9:56 am |
|
|
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?
|
|
|
![](templates/subSilver/images/spacer.gif) |
|