pic16f876a problem

 comp.robotics.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
pic16f876a problem Adam.crash.brown 06-06-2008
Posted by on June 6, 2008, 9:23 pm
Please log in for more thread options
Hi,

I'm trying to use a pic 16f876a to control an automated gutter
cleaner. Unfortunately I can't even compile my code. I was trying to
use sdcc as my compiler, but it doesn't look like it allows for
bitwise manipulation and reading of the I/O ports (i.e.
PORTBbits.RB2). So I guess I'm looking for a suggestion on a better
FREE compiler or a way to do bitwise manipulation of the ports using
sdcc. Any suggestions would be greatly appreciated.

Posted by Rich Webb on June 7, 2008, 8:22 am
Please log in for more thread options
On Fri, 6 Jun 2008 18:23:37 -0700 (PDT), Adam.crash.brown@gmail.com
wrote:

>Hi,
>
>I'm trying to use a pic 16f876a to control an automated gutter
>cleaner. Unfortunately I can't even compile my code. I was trying to
>use sdcc as my compiler, but it doesn't look like it allows for
>bitwise manipulation and reading of the I/O ports (i.e.
>PORTBbits.RB2). So I guess I'm looking for a suggestion on a better
>FREE compiler or a way to do bitwise manipulation of the ports using
>sdcc. Any suggestions would be greatly appreciated.

The "Port.BitNum" syntax is a construct that's used by some, but by no
means all, embedded compilers to manipulate I/O ports.

You might try a more portable approach, like "Port |= (1 << BitNum)"
or "Port &= ~(1 << BitNum)" and so on.

Adjust as necessary for the target processor; I don't recall whether
that generation of PICs uses separate registers for "the value of the
port is" and "set the value of the port to".

--
Rich Webb Norfolk, VA

Posted by on June 8, 2008, 3:30 pm
Please log in for more thread options
> On Fri, 6 Jun 2008 18:23:37 -0700 (PDT), Adam.crash.br...@gmail.com
> wrote:
>
> >Hi,
>
> >I'm trying to use a pic 16f876a to control an automated gutter
> >cleaner. Unfortunately I can't even compile my code. I was trying to
> >use sdcc as my compiler, but it doesn't look like it allows for
> >bitwise manipulation and reading of the I/O ports (i.e.
> >PORTBbits.RB2). So I guess I'm looking for a suggestion on a better
> >FREE compiler or a way to do bitwise manipulation of the ports using
> >sdcc. Any suggestions would be greatly appreciated.
>
> The "Port.BitNum" syntax is a construct that's used by some, but by no
> means all, embedded compilers to manipulate I/O ports.
>
> You might try a more portable approach, like "Port |= (1 << BitNum)"
> or "Port &= ~(1 << BitNum)" and so on.
>
> Adjust as necessary for the target processor; I don't recall whether
> that generation of PICs uses separate registers for "the value of the
> port is" and "set the value of the port to".
>
> --
> Rich Webb Norfolk, VA

Hi,

Thanks so much for the help. I tried both your comments, but still
had problems with MPLAB and a few other compilers. So I've switched
my code to the bitwise operators, and have had success with clearing,
setting, and toggling bits. But, I still can't figure out how to read
an individual bit from the register. Is there an easy way to do this
using bitwise operators, or any other means?

Thanks in advance!

Posted by Rich Webb on June 8, 2008, 4:14 pm
Please log in for more thread options
On Sun, 8 Jun 2008 12:30:34 -0700 (PDT), Adam.crash.brown@gmail.com
wrote:

>Thanks so much for the help. I tried both your comments, but still
>had problems with MPLAB and a few other compilers. So I've switched
>my code to the bitwise operators, and have had success with clearing,
>setting, and toggling bits. But, I still can't figure out how to read
>an individual bit from the register. Is there an easy way to do this
>using bitwise operators, or any other means?

For instances like
if (bit 3 is set in FOO_REG) then do something
you can use
#define BAR_BIT 3
if (FOO_REG & (1 << BAR_BIT))
or, equivalently
if ((FOO_REG & (1 << BAR_BIT)) != 0)

Most compilers will produce identical code for the two constructs but
the latter, explicit compare with zero makes it clear to a later
reader what the intent is. Be kind to your maintenance programmers;
they may be *you*.

You can use a function-like macro to cut down on typing.
#define TestBit(reg,bitnum) ((reg) & (1 << (bitnum)))
to use
if (TestBit(FOO_REG, BAR_BIT) != 0)

--
Rich Webb Norfolk, VA

Posted by Philipp Varley on June 7, 2008, 11:30 am
Please log in for more thread options

Why not using the Microchip software? MPLab for example. Or microC, which
is free I think (use google to find, or give me a note via email and I'll
send it over)

Cheers,
Phil

--
---
Philipp Varley, TU Darmstadt, Mechatronik
** Posted from http://www.teranews.com **

Similar ThreadsPosted
PIC16F876A June 22, 2005, 10:12 pm
Programming a PIC16F876A with GPICD June 19, 2005, 9:26 pm
PIC usart problem June 26, 2006, 10:52 am
video cam problem December 8, 2006, 5:54 am
Re: Problem with libraries September 23, 2007, 8:02 pm
Re: oxidation problem September 23, 2007, 11:33 pm
CRM: solutions to our problem? December 5, 2007, 1:23 pm
Re: Lighting problem December 25, 2007, 6:26 pm
Re: OWA image problem January 16, 2008, 1:42 am
Re: OWA image problem January 23, 2008, 7:25 pm

The site map in XML format XML site map
other useful resources:
Official Robosapien Website
Lego Mindstorms Website

Contact Us | Privacy Policy