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

Toggle Port B 16f877

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



Joined: 31 Dec 2003
Posts: 9
Location: United Kingdom Devon

View user's profile Send private message MSN Messenger

Toggle Port B 16f877
PostPosted: Mon May 11, 2009 4:17 am     Reply with quote

I have been writing code in ASM which all works fine, and now writing the same code using CCS, however I'm having trouble with the basics of simply toggling portb output pins.

When I monitor the special function registers portb in debug they do toggle, however when i blow the pic, and probe with the scope, there is no toggling.

Something basic i'm doing wrong, help please?
Code:
#include <16F877.h>
#use delay(clock=12000000)
Main ()
{
set_tris_b(0xff);   
while (1)
   {
output_b(0x00);
output_b(0xff);
   }
}
horde_fuego



Joined: 31 Mar 2009
Posts: 11

View user's profile Send private message

Re: Toggle Port B 16f877
PostPosted: Mon May 11, 2009 6:15 am     Reply with quote

Peter Mayhew wrote:
I have been writing code in ASM which all works fine, and now writing the same code using CCS, however I'm having trouble with the basics of simply toggling portb output pins.

When I monitor the special function registers portb in debug they do toggle, however when i blow the pic, and probe with the scope, there is no toggling.

Something basic i'm doing wrong, help please?

#include <16F877.h>
#use delay(clock=12000000)
Main ()
{
set_tris_b(0xff);
while (1)
{
output_b(0x00);
output_b(0xff);
}
}



You need to insert a delay so that you will see the toggling effect just like this
Code:
output_b(0x00);
delay_ms(500);
output_b(0xff);
delay_ms(500);

hope it helps Very Happy
andyfraser



Joined: 04 May 2004
Posts: 47
Location: UK

View user's profile Send private message

Toggle Port B 16f877
PostPosted: Mon May 11, 2009 6:19 am     Reply with quote

You don't need a delay unless you have really, really slow scope !

You are setting all the pins to INPUT with set_tris_b(0xFF);

HTH

Andy
Guest








PostPosted: Mon May 11, 2009 8:05 am     Reply with quote

Hi,

Which is why it's a good idea to just let the compiler handle setting the TRIS settings, especially for a beginner. The only time you need to explicitly specify the TRIS settings yourself is when you use FAST_IO.

Chas
Peter Mayhew



Joined: 31 Dec 2003
Posts: 9
Location: United Kingdom Devon

View user's profile Send private message MSN Messenger

PostPosted: Mon May 11, 2009 2:51 pm     Reply with quote

Many thanks for all your advice.
Yes my scope is fast enough, thanks for pointing that out.
You are correct, I did have tris_b set to 0xff, which was a silly mistake. That happened as I was originally reading port B and outputting to port A, but when I found the program wasn't working as expected. just toggled port b but forgot to update tris_b to 0x00. Well spotted, thankyou.
I changed tris_b to an output 0x00. However this didn't solve the problem.
I went through a couple of example files and found the code
#fuses HS,NOWDT,NOPROTECT,NOLVP
So I added #fuses HS and the program works.
Complete code

Code:
#include <16F877.h>
#fuses HS
#use delay(clock=12000000)
Main ()
{
set_tris_b(0xff);   
while (1)
   {
output_b(0x00);
output_b(0xff);
   }
}


Purely out of interest, I experimented with all four fuse options being LP, XT, HS, RC. Only RC caused this problem. So I take it that CCS defaulted to RC mode since I didn't define it. Many thanks again for all your time.
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Mon May 11, 2009 3:22 pm     Reply with quote

Peter use the project wizard for starting a new project. One of my favorite function is setting correct fuses, so you allways know how the PIC is set. Wink
Peter Mayhew



Joined: 31 Dec 2003
Posts: 9
Location: United Kingdom Devon

View user's profile Send private message MSN Messenger

PostPosted: Mon May 11, 2009 3:39 pm     Reply with quote

Funny you should mention that. I did use the menu Project --> Project Wizard. I just checked it again, and can't see any mention of the fuses??? I can only find it in menu configure --> configuration bits? Maybe there is something I missed??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 11, 2009 3:42 pm     Reply with quote

The command line compilers used with MPLAB don't have any
of the CCS Wizards.
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon May 11, 2009 3:51 pm     Reply with quote

Peter,
If you had used the "PIC Wizard" that comes with the CCS IDE, under General Category there is an Options Tab. On that tab you will find the Fuses panel on the bottom half of the tab page right below where you set the Oscillator Frequency. This section sets the fuses automatically according to the speed and type of oscillator along with the other options desired. That's the section I believe he was referring to.

Also, Charles is right, you really should avoid using the TRIS() statements unless you absolutely have to. The compiler will set the port bits automatically.
Peter Mayhew



Joined: 31 Dec 2003
Posts: 9
Location: United Kingdom Devon

View user's profile Send private message MSN Messenger

PostPosted: Mon May 11, 2009 4:36 pm     Reply with quote

I don't know about CCS IDE. My copy of CCS is quite old, which I bought back in 2003. I don't think they had CCS IDE back then?, or you had to avoid using TRIS. All I know is its PCM Software.
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