Jump to content
Sign in to follow this  

PIC newbie help

Recommended Posts

I'm working on my senior design project as an electrical engineer.  I'm decently versed in C and C++, and I know the general layout of my program.  The problem is I do not know how to read in information from the ports, and read out info to the ports.  I have a couple of books and they have been little help.  A quick explanation would be of more assistance than a 400 page manual.



My situation is this.  A hex switch will be hooked up to port A of a 16lf874A.  I need to read in this info to store to a char.  I also need to monitor port B for 14 DIP switches.  These will be used for controls.

Share this post

Link to post
Share on other sites

Hi Kaplah,


take a look at the examples here on the homepage.

At the bottom of this section you will find the links to the page of

Julian Winpenny. Your 16F874 is code compatible to the 16F877,

only RAM and FLASH of your device is less.




Share this post

Link to post
Share on other sites

Thanks, but I have a hard time reading and making sense of examples.  What I need is an explanation of some of the comands.  Neither of the books I have on the PIC are very good at explaining these.


TrisX (ie. trisb, trisa, yadda yadda)


And portx (i.e. porta, portb, yadda yadda)


The examples that I read through really didn't explain how these work either.


How does the pic write data to a port, can I raise a single pin value, or does it write out data in binary numbers?  What I'm trying to do is similar to having 8 LED's hooked up all to port b, and I only want one raised at a time for a period of 1 second.

Share this post

Link to post
Share on other sites

Hi, Kaplah


You can try this:

This code on/off bit 1 on PORTB


void main( void )


  TRISB = 00000000b;    // all as output


  set_bit( PORTB, 1 );    // put on bit 1

  delay_s( 1 );              // delay one second

  clear_bit( PORTB, 1);   // put off bit 1  

  delay_1( 1 );              // delay one second





Share this post

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...