Continue to Site

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.

  • 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.

I/O output

Status
Not open for further replies.
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?.
 
example:

setting PORTB bit 0
PORTB|=(1<<0);

setting PORTB bit 2
PORTB|=(1<<2);


clearing PORTB bit 2
PORTB&=~(1<<2);
 
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.

Latest threads

New Articles From Microcontroller Tips

Back
Top