• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic 16F505

Status
Not open for further replies.

be80be

Well-Known Member
Ok it's been a bit but I figured Id mess a bit with asm on this chip

There is no TRISC or TRISB in the inc file. It list them bit by bit like this
TRISC0 TRISC1 and so on.

But I guess this is the only way to load the TRIS with I/0 setting
Code:
movlw B'00000001'
tris portc
Is that right.

Then the next thing I did the same code in xc8 and it's using 16 more cycles
to toggle a led.
with a bunch of FSR gunk thats not needed
 

be80be

Well-Known Member
You could load tris but there no trisc in the .ins file all my old code don't work LOL
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Once upon a time I used pic12c508's... Using the TRIS command was how it was done.. Incredibly I was using the tris command on the pic16f84... I think it was a macro for "ye olde programmers" to make it easier for them...
 

be80be

Well-Known Member
Yes the TRIS PORTC works or setting each input or output .

Looks like they would of left TRISC lol

I didn't think about using tris PORTC for about a hour LOL

I was testing ASM code to see if a pin toggle could be.
xc8 was way longer
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
The baseline pics had no bank switching and therefore no tris or option registers. These were accessed with the two instructions TRIS and OPTION which move W to the two registers.

Mike.
 

be80be

Well-Known Member
I know that but at one time i could do a
movlw b'xxxxxxxx'
movwf TRISC

The newer mplab-x .inc pops up now you can't
I think i had at one time copied a .inc from a older mplab or something.

You can't write a port like I have done it want's you to
use RC0 RC1 like

If you try a movwf PORTC it errors.
It want's you to set them one at a time.
The TRIS PORTC works.
Code I used before don't work now to do whole tris writes or port writes
 
Last edited:

Nigel Goodwin

Super Moderator
Most Helpful Member
I was testing ASM code to see if a pin toggle could be.
xc8 was way longer
Are you using the free version of XC8?, if so it deliberately adds loads of bogus (and useless) extra code, in order to make the file sizes much bigger and for it to run much slower - in order to try and convince you to pay the huge sum for the full version. It's not just 'less optimised', it deliberately cripples the result.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Here is the professional listing

Code:
                #include<xc.h>
2:                 
3:                 void main(void)
   1F5     C00     MOVLW 0
4:                 {
5:                 char x;
6:                 
7:                 TRISC = 0;
   1F6     007     TRIS 0x7
8:                 while(1)
9:                  {
10:                  RC1 = 1;
   1F7     4A4     BCF 0x4, 0x5
   1F8     4C4     BCF 0x4, 0x6
   1F9     527     BSF 0x7, 0x1
11:                  NOP();
   1FA     000     NOP
12:                  RC1 = 0;
   1FB     4A4     BCF 0x4, 0x5
   1FC     4C4     BCF 0x4, 0x6
   1FD     427     BCF 0x7, 0x1
13:                  NOP();
   1FE     000     NOP
Only as many lines as the the asm version

here's the C code
C:
#include<xc.h>
void main(void)
 {
 char x;
 
 TRISC = 0;
 while(1)
  {
  RC1 = 1;
  NOP();
  RC1 = 0;
  NOP();
  }
 }
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Well to be fair, there's not much difference on that code with the free compiler version:

Code:
11:            #include<xc.h>
12:            void main(void)
13:             {
14:             char x;
15:             
16:             TRISC = 0;
01F5  0C00     MOVLW 0x0
01F6  0007     TRIS PORTC
17:             while(1)
01FF  0BF7     GOTO 0x1F7
18:              {
19:              RC1 = 1;
01F7  04A4     BCF FSR, 0x5
01F8  04C4     BCF FSR, 0x6
01F9  0527     BSF PORTC, 0x1
20:              NOP();
01FA  0000     NOP
21:              RC1 = 0;
01FB  04A4     BCF FSR, 0x5
01FC  04C4     BCF FSR, 0x6
01FD  0427     BCF PORTC, 0x1
22:              NOP();
01FE  0000     NOP
01FF  0BF7     GOTO 0x1F7
23:              }
24:             }
 

Pommie

Well-Known Member
Most Helpful Member
The 12F508 doesn't have any bank select bits!!!!! Or did I miss something?

Mike.
Edit, noticed we're talking 16F505 - however, I still thought the Tris register wasn't memory mapped.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
The 12F508 doesn't have any bank select bits!!!!! Or did I miss something?

Mike.
Edit, noticed we're talking 16F505 - however, I still thought the Tris register wasn't memory mapped.
Kinda!!

The FSR still can Throw a spanner in so the code above just clears the indirect address..
( I doubt I will ever use these chips ever again!! So who cares!! )
 

be80be

Well-Known Member
I just like messing with that chip i had a inc that let you use trisc i upgraded mplax x and now its gone lol been like 8 years since i used tris portc i had to read the data sheet . And then i remmbered it.

The thing thst gave me a loop was xc8 lets you write the trisc for i/0
Where as in asm there no trisc only each reg by bit.
Thanks i got it figured out how i did it before
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top