I/O output

Status
Not open for further replies.
Manie said:
How do I change a single bit value of a port? What is the syntax?

Depends what processor you're talking about, and what laguage you're using, your question is far too vague to answer!.
 
Manie said:
I am using a PIC16f737 and programming in C

Can't help you with C, but in assembler it's simply:

bsf Port, pin

to set a pin high

bcf Port, pin

to clear a pin.

As it's such a basic thing to do, you should have suitable examples with your C compiler?.
 
Check your C-compiler. Many of them have a declaration syntax for bits. If they do then the statement is just something like

Code:
bit  GIE  INTCON.7

GIE = 0 ; /* Disable Interrupts */
...
GIE = 1 ; /* Enable Interrupts */
The declaration syntax is not part of the C language standard, but several compilers for processors that support bit addressing have invented such extensions. You do have to look carefully in the compiler documentation though.

Look for #pragma keyword=extended or something similar to see if there is a switch that enables or disables the extended language features.

If you think you've found something then write a short test program and look at the compiler output to see if it matches both your understanding and Nigel's example.

On real ports with a mixture of inputs and outputs you need to be careful with bsf and bcf instructions because in hardware they read all 8 bits of a port, modify the single bit, and write back all 8 bits. This can be problematic and there are warnings in the PIC data sheets.

Let us know what you find.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…