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

set_tris_x PIC16F877A

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



Joined: 11 Oct 2007
Posts: 12

View user's profile Send private message

set_tris_x PIC16F877A
PostPosted: Tue Jun 11, 2013 7:17 am     Reply with quote

I am having a trouble in using set_tris_x function to the PIC16F877A.
I am using the recent version of the compiler (v5.006).

When I use set_tris_x function, it seems that the value is being applied to the PORTx register and no in the TRISx register.

Bellow is my code and the C/ASM list too.
Code:
#include <16F877A.h>
#use delay(clock = 8000000)
#fuses HS,NOWDT,NOLVP,PUT

#use fast_io(A)
#use fast_io(D)

#define LED1 PIN_D3

void main(){

set_tris_a(0x00);
set_tris_d(0x00);

output_a(0);
output_d(0);

   
while(true)  {
output_toggle(PIN_D0);
delay_ms(1000);

}

}


C/ASM List:
Code:

.................... void main(){
001A:  BSF    03.5
001B:  BSF    1F.0
001C:  BSF    1F.1
001D:  BSF    1F.2
001E:  BCF    1F.3
001F:  MOVLW  07
0020:  MOVWF  1C
0021:  BCF    03.7
0022:  MOVLW  1F
0023:  ANDWF  03,F
.................... 
.................... set_tris_a(0x00);
0024:  MOVLW  00
0025:  MOVWF  05
.................... set_tris_d(0x00);
0026:  MOVWF  08
.................... 
.................... output_a(0);
0027:  BCF    03.5
0028:  CLRF   05
.................... output_d(0);
0029:  CLRF   08


Please, somebody could answer me what could be happening?
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Jun 11, 2013 7:31 am     Reply with quote

this looks NORMAL to me -
what is going wrong in the code ??

you need to read about the BANK select bits in the status register
and you will be illuminated re the .LST file Very Happy Very Happy Very Happy
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Tue Jun 11, 2013 7:37 am     Reply with quote

and somebody asked exactly this inside the last couple of weeks, and it was explained then.

Stinky, in the thread 'accidental code protect'. Was a secondary question he asked.
sandrini



Joined: 11 Oct 2007
Posts: 12

View user's profile Send private message

PostPosted: Tue Jun 11, 2013 7:43 am     Reply with quote

asmboy,

The right address to the TRISD for example is 0x85 and when I use set_tris_d, the selected address is being 0x05.
The address 0x05 is the PORTD's address...
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Jun 11, 2013 7:55 am     Reply with quote

the logic you are attempting to follow would be true if this was a PIC18F part, but it is NOT!

YOU DON'T UNDERSTAND BANK SELECT at all, do you ??

addr 85 is only accessed by selecting BANK 1 in the status register
then using the SAME offset as the actual port registers.

this is 16F family addressing , quite familiar to ASM programmers - and covered in PIC course 101 !!!
RTFM!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Tue Jun 11, 2013 8:17 am     Reply with quote

Look at the thread I mentioned.

Key point to understand is as Asmboy says. The PIC16 instructions, can't actually access an address '0x85'. They can access 0, to 0x7F only. To talk to address '85', you have to set the bank offset to '1' (which adds 0x80, to the address used), and then access 0x5. This is what the compiler is doing.

Best Wishes
sandrini



Joined: 11 Oct 2007
Posts: 12

View user's profile Send private message

PostPosted: Tue Jun 11, 2013 10:24 am     Reply with quote

Thank you asmboy and Ttelmah,

Yes, I understand BANK Select and you are right, I really was wrong....
But the problem is in the compiler...This C code was made in v4.140 of the compiler and it is working properly, but when I make this code in new version v5.006, the PIC doesn't work anymore.
There something wrong with the directive #use fast_io.... when I use in version v5.006 the PIC doesn't work
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Tue Jun 11, 2013 11:18 am     Reply with quote

Tell CCS.
Unfortunately, everyone who knows CCS, understands that their new versions are at 'best' beta. V5 will I expect be beta for at least a couple of months. They are on their sixth version in only a few weeks.
Historically they always had the 'last known good' version also available for downloads, but like criminal idiots, they have got rid of this, and after only a couple of versions, have got rid of the beta designation.
Hopefully you have kept the older version. If not, ask for it, and keep it on your machine to go back to, while testing V5....

Best Wishes
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