Address half PORTB

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
sifran
Posts: 2
Joined: 22 Sep 2009 11:38

Address half PORTB

#1 Post by sifran » 22 Sep 2009 11:43

Hi everyone!
I have PORTB on a DSPIC 33F which is connected to two 8 bit DACs, one on PORTB 0-7 and the other on PORTB 8 - 15.
How can I directly access, with one intruction, the two halfs of the port as if they were two 8 bit ports?

Thank you very much!

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

#2 Post by anikolic » 24 Sep 2009 09:29

Hi,
Can you specify what dsPIC33 are you using? This family of microcontrollers has 16-bit operations, so all assembly lines use 16-bit word operands, unless specified to use byte operands, by extending asm directives with .B suffixes. This means that if you write, for example:

Code: Select all

unsigned int PORTVal;

void main(){
  PORTVal = 0x0000;
  PORTB = 0x1234;
  PORTVal = PORTB;
}
assembly equivalent generated by the compiler would be:

Code: Select all

;void main(){
;PORTVal = 0x0000;
	MOV	#0, W0
	MOV	W0, _PORTVal
;PORTB = 0x1234;
	MOV	#4660, W0
	MOV	W0, PORTB
;PORTVal = PORTB;
	MOV	PORTB, W0
	MOV	W0, _PORTVal
Of course, you must use two assembly instructions to copy one 16-bit value from one register to another, by using W0 working register as a mediator. Only W registers can be copied directly in a single cycle with MOV commands, but other registers must be copied using two clock cycles.
If this is not the answer to your question, please rephrase and paste a piece of commented code that gives you trouble, and I'll do my best to help.

Best regards,
Aleksandar
Web Department Manager

sifran
Posts: 2
Joined: 22 Sep 2009 11:38

#3 Post by sifran » 24 Sep 2009 09:48

Thank you Aleksandar, the machine is Dspic33fj128G710, I am not so practical with assembly, I will try to implement the code you suggested.
My question was maily related ti MikroC code.

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”