View previous topic :: View next topic |
Author |
Message |
mutevaggil
Joined: 29 May 2008 Posts: 8
|
How can i use PORTB instead of output_b() |
Posted: Tue Jun 10, 2008 6:56 am |
|
|
hi,
i want to use PORTB as output directly, i mean, when i write:
PORTB=1; first led of PORTB will ON.
i defined my registers in main.h:
Code: | #include <16F877A.h>
#byte PORTB = 0x06
#byte TRISB = 0x86
#byte OUTPUT = PORTB
#byte OUTPUT_DIR = TRISB |
and main.c:
Code: |
OUTPUT_DIR=0x00;
while(1)
{
OUTPUT=0;
delay_ms(100);
OUTPUT=1;
} |
it compiles good. but doesnt work in simulation. |
|
|
Guest
|
|
Posted: Tue Jun 10, 2008 7:47 am |
|
|
Never used the simulator,but if I was testing this on a scope I would have a delay after output=1.
regards |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Tue Jun 10, 2008 9:30 am |
|
|
You can either use the Output_bit() function or #bit preprocessor directive
from page 90 of the current manual:
Quote: | #BIT
Syntax: #bit id = x.y
Elements: id is a valid C identifier,
x is a constant or a C variable,
y is a constant 0-7.
Purpose: A new C variable (one bit) is created and is placed in memory at byte x and bit
y. This is useful to gain access in C directly to a bit in the processors special
function register map. It may also be used to easily access a bit of a standard
C variable.
Examples: #bit T0IF = 0xb.2
...
T0IF = 0; // Clear Timer 0 interrupt flag
int result;
#bit result_odd = result.0
...
if (result_odd)
Example Files: ex_glint.c
Also See: #byte, #reserve, #locate, #word
|
|
|
|
|