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

set_tris_a problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ellrod



Joined: 14 Dec 2004
Posts: 6
Location: Boston, Ma

View user's profile Send private message

set_tris_a problem
PostPosted: Tue Dec 14, 2004 3:47 pm     Reply with quote

Here's one I've been beating on for a couple of hours now....

#include <16F88.H>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOBROWNOUT,NOMCLR,NOFCMEN,NOIESO,NOLVP,CCPB3

#use fast_io(a)
#use fast_io(b)

#byte trisa_x = 0x85
#byte trisb_x = 0x86


The following sets trisa properly, to 0xE2

void main() {

trisa_x = 0xe2;
trisb_x = 0xd1;

// body of code here

}

This next code does not work correctly, it sets trisa to 0x22

void main() {

set_tris_b(0xd1);
set_tris_a(0xe2);

// body of code here
}

In looking at the assembly language I see this:

262: set_tris_b(0xd1);
000625 30D1 MOVLW 0xd1
263:
264: set_tris_a(0xe2);
000627 30E2 MOVLW 0xe2
265

The actual instuctions that write the tris registers is hidden (locs 263 and 265) so I don't know what CCS is doing there.

Anybody know what's going on here ?
Thanks !
_________________
Arnie Jones
Contract Embedded Systems Developer
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 3:50 pm     Reply with quote

Those are not address locations. Those are line numbers in the .LST file.

Also, be aware that TRISA only uses the lower 6 bits of the register.
The upper two bits are not used, and are likely read back as zeros.
Hence, 0xE2 becomes 0x22.
ellrod



Joined: 14 Dec 2004
Posts: 6
Location: Boston, Ma

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 4:45 pm     Reply with quote

Sorry, I meant to say lines 626 and 628, which are code locs, are not included anywhere in the disassembly listing.

Both A and B ports on the 16F88 are full eight bits wide so the upper tris bits are utilized.
_________________
Arnie Jones
Contract Embedded Systems Developer
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 4:52 pm     Reply with quote

You are right. I clicked on 16F688 by mistake in my list of data sheets.
(Trying to answer too quickly...)


What version of the compiler are you using, and what IDE are you using ?
(MPLAB or CCS PCW)
ellrod



Joined: 14 Dec 2004
Posts: 6
Location: Boston, Ma

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 5:12 pm     Reply with quote

MPLAB 6.62 and CCS 3.209
_________________
Arnie Jones
Contract Embedded Systems Developer
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 5:20 pm     Reply with quote

Here is something disturbing. If I install PCM vs. 3.209 and compile the
test file shown below, I get illegal TRIS instructions shown in the .LST file.
Code:

#include <16F88.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

void main()
{
set_tris_b(0xd1);
set_tris_a(0xe2);

while(1);
}


Code:
// Part of the .LST file follows:
CCS PCM C Compiler, Version 3.209, xxxxx       14-Dec-04 15:16

0000                00298 ....................   
0000                00299 .................... set_tris_b(0xd1);   
0011 30D1       00300 MOVLW  D1
0012 0066       00301 TRIS   6
0000                00302 .................... set_tris_a(0xe2);   
0013 30E2       00303 MOVLW  E2
0014 0065       00304 TRIS   5
0000                00305 ....................   
0000                00306 .................... while(1); 
0015 2815       00307 GOTO   015


Can you go into your Project/ Build Options menu and select "MPASM
Format" for the List File format ? Then re-compile and see if you get
the output as shown above ?
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 5:29 pm     Reply with quote

There is some information about CCS using the TRIS instructions in the Q&A section of the manual. There really don't explain why they use it though.
_________________
David
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 5:39 pm     Reply with quote

Yes, but the TRIS instruction is not even in the 16F88 data sheet.
They shouldn't be using it. I compiled the program above with
several other versions of the compiler (3.168, 3.188, 3.214) and
it has the same problem. That's why I wanted to see if he also
sees the TRIS instruction in his .LST file. I want some confirmation
that I'm really seeing a bug here.
ellrod



Joined: 14 Dec 2004
Posts: 6
Location: Boston, Ma

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 6:44 pm     Reply with quote

That's the odd thing, as you can see in the original fragment of the .lst file I posted the instuction immediately following the MOVLW <tris value> is not included in the listing, it's just skipped over. I know there's something there since the address is incremented. I will look at some way of disassembling the object file to see what is put there.
_________________
Arnie Jones
Contract Embedded Systems Developer
Mark



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

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

PostPosted: Tue Dec 14, 2004 6:52 pm     Reply with quote

Quote:
I will look at some way of disassembling the object file to see what is put there.

View\Program Memory
Guest








PostPosted: Tue Dec 14, 2004 8:27 pm     Reply with quote

Out of the office till tomorrow, will check it out first thing in the morning....
adrian



Joined: 08 Sep 2003
Posts: 92
Location: Glasgow, UK

View user's profile Send private message

PostPosted: Wed Dec 15, 2004 7:01 am     Reply with quote

Quote:

Here is something disturbing. If I install PCM vs. 3.209 and compile the
test file shown below, I get illegal TRIS instructions shown in the .LST file.


From the CCS online help
Quote:

The use of TRIS causes concern for some users. The Microchip data sheets recommend not using TRIS instructions for upward compatibility. If you had existing ASM code and it used TRIS then it would be more difficult to port to a new Microchip part without TRIS. C does not have this problem, however; the compiler has a device database that indicates specific characteristics for every part. This includes information on whether the part has a TRIS and a list of known problems with the part. The latter question is answered by looking at the device errata.

CCS makes every attempt to add new devices and device revisions as the data and errata sheets become available.

PCW users can edit the device database. If the use of TRIS is a concern, simply change the database entry for your part and the compiler will not use it.
ellrod



Joined: 14 Dec 2004
Posts: 6
Location: Boston, Ma

View user's profile Send private message

PostPosted: Wed Dec 15, 2004 7:50 am     Reply with quote

Here is the C code:

#include <16F88.H>

#fuses INTRC_IO,NOWDT,NOPROTECT,NOBROWNOUT,NOMCLR,NOFCMEN,NOIESO,NOLVP,CCPB3

#use fast_io(a)
#use fast_io(b)

#byte trisa_x = 0x85
#byte trisb_x = 0x86

void main()
{

trisa_x = 0xd1;
trisb_x = 0xe2;

set_tris_b(0xd1);

set_tris_a(0xe2);

}

Here is the assembly that is generated

1 0000 3000 MOVLW 0
2 0001 008A MOVWF 0xa
3 0002 2804 GOTO 0x4
4 0003 0000 NOP
5 0004 0184 CLRF 0x4
6 0005 301F MOVLW 0x1f
7 0006 0583 ANDWF 0x3, F
8 0007 1683 BSF 0x3, 0x5
9 0008 121F BCF 0x1f, 0x4
10 0009 129F BCF 0x1f, 0x5
11 000A 081B MOVF 0x1b, W
12 000B 3980 ANDLW 0x80
13 000C 380F IORLW 0xf
14 000D 009B MOVWF 0x1b
15 000E 3007 MOVLW 0x7
16 000F 1283 BCF 0x3, 0x5
17 0010 009F MOVWF 0x1f
18 0011 30D1 MOVLW 0xd1
19 0012 1683 BSF 0x3, 0x5
20 0013 0085 MOVWF 0x5
21 0014 30E2 MOVLW 0xe2
22 0015 0086 MOVWF 0x6
23 0016 30D1 MOVLW 0xd1
24 0017 0066
25 0018 30E2 MOVLW 0xe2
26 0019 0065
27 001A 0063 SLEEP

Instructions 66 and 65 are TRISA and TRISB instructions !
Single stepping through this code I find that when the TRISA instruction is executed instead of E2 being loaded into TRISA 22 is loaded. Using a movf instruction to load TRISA it gets loaded properly.

Another thing that pops out at me when looking at this code is that it messes around with location 0x1b ! Which is a reserved location in the 16F88, if I try to assemble this code with MPASM it warns of an illegal address at 0x1b.
_________________
Arnie Jones
Contract Embedded Systems Developer
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 15, 2004 10:01 am     Reply with quote

Regarding the quote from the CCS manual, the issue is that
CCS doesn't use TRIS for 16F877. See the code below, compiled
with PCM 3.214. They fixed it years ago for the 16F877. Therefore
I think it's a bug for the 16F88, and should be reported to CCS.
That quote in the manual has been in there for years and doesn't
really apply anymore, in my opinion.

Code:
0000                00293 ......... void main() 
0000                00294 ......... { 
0004 0184       00295 CLRF   04
0005 301F       00296 MOVLW  1F
0006 0583       00297 ANDWF  03,F
0007 1683       00298 BSF    03.5     // Select Bank 1
0008 141F       00299 BSF    1F.0
0009 149F       00300 BSF    1F.1
000A 151F       00301 BSF    1F.2
000B 119F       00302 BCF    1F.3   
0000                00303 .........   
// Notice how the TRIS registers are loaded with MOVWF
// instructions for the 16F877, and not the obsolete TRIS:
0000                00304 ......... set_tris_b(0xd1);   
000C 30D1       00305 MOVLW  D1
000D 0086       00306 MOVWF  06 
0000                00307 ......... set_tris_a(0xe2);   
000E 30E2       00308 MOVLW  E2
000F 0085       00309 MOVWF  05
0000                00310 .........   
0000                00311 ......... while(1); 
0010 2810       00312 GOTO   010
0000                00313 .................... } 
Guest








PostPosted: Wed Dec 15, 2004 11:57 am     Reply with quote

I checked the 16F88 in the Device Selector under Tools (I am using PCW) and the under the heading for "other features" the first item is TRIS. This is set to TRUE. I checked the f877 and the TRIS feature is set to FALSE. I am almost certain that whoever created the device in the selector just copied the format from some other part.

I compiled the original program with the default device selector entries and the TRIS instruction was used. I then used the device selector and changed the TRIS feature to FALSE, and sure enough, the result was as follows: (the following is hand typed since my compiler is on another machine)

Code:

....................  set_tris_b(0xd1);
0011:  MOVLW  D1
0012:  BSF    03.5
0013:  MOVWF  06
....................  set_tris_a(0x02)
0014:  MOVLW  02
0015:  MOVWF  05


I am not certain how to edit the device if you are using the command line version. PCM Programmer, can you help with that?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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