![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
How do I change a single bit value of a port? What is the syntax?
| |
| |
| | #2 | |
| Quote:
| ||
| |
| | #3 |
|
I am using a PIC16f737 and programming in C
| |
| |
| | #4 | |
| Quote:
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?. | ||
| |
| | #5 | |
| Quote:
or port_value |= (1<< bitposition)
__________________ Gods own Country Incredible !ndia www.flickr.com/photos/_akg/ "Give a man a fish, and he will eat for a day. Teach that man to fish, and he will eat for a lifetime." | ||
| |
| | #6 |
|
example: setting PORTB bit 0 PORTB|=(1<<0); setting PORTB bit 2 PORTB|=(1<<2); clearing PORTB bit 2 PORTB&=~(1<<2);
__________________ Learning is a life-long process... | |
| |
| | #7 |
|
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 */ 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 by Papabravo; 14th June 2006 at 02:52 PM. | |
| |
|
| Tags |
| i or o, output |
| Thread Tools | |
| Display Modes | |
| |