View previous topic :: View next topic |
Author |
Message |
sandrini
Joined: 11 Oct 2007 Posts: 12
|
set_tris_x PIC16F877A |
Posted: Tue Jun 11, 2013 7:17 am |
|
|
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
|
|
Posted: Tue Jun 11, 2013 7:31 am |
|
|
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 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Tue Jun 11, 2013 7:37 am |
|
|
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
|
|
Posted: Tue Jun 11, 2013 7:43 am |
|
|
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
|
|
Posted: Tue Jun 11, 2013 7:55 am |
|
|
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
|
|
Posted: Tue Jun 11, 2013 8:17 am |
|
|
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
|
|
Posted: Tue Jun 11, 2013 10:24 am |
|
|
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
|
|
Posted: Tue Jun 11, 2013 11:18 am |
|
|
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 |
|
|
|