View previous topic :: View next topic |
Author |
Message |
arys
Joined: 09 Mar 2007 Posts: 31
|
set port for 16f873 |
Posted: Wed Mar 05, 2008 11:17 pm |
|
|
hi.
I want to set port b as output port.
here are the code. but it doesnt work. does anybody know? it only work if output_high(PIN_Bx). I do not understand?
Code: |
#byte PORTB=0x06
#byte PORTC=0x07
void main(void)
{
while(1)
{ if (INPUT(PIN_C4))
output_b(0b00000001);
.
.
|
|
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Thu Mar 06, 2008 9:14 am |
|
|
At power up, all ports are inputs. You need to change the portb DIRECTION to outputs. See the SET_TRIS_B() command. _________________ David |
|
|
Ttelmah Guest
|
|
Posted: Thu Mar 06, 2008 9:59 am |
|
|
Not true.
The default mode fo the CCS compiler, is 'standard_io' mode. In this mode, the compiler wll _automatically_ insert TRIS commands for you. It works well, and except for the overhead on speed, is perfectly reliable.
The most likely problem is something else 'not shown' in the code.
Post a runnable 'demo' program, showing the fuses, what processor is involved etc. etc.. It should be the bare minimum to show the problem (only really needs the processor selection, clock setup, fuses, and the terminations of the loops).
There is nothing wrong with what is shown, except that it is incomplete.
Best Wishes |
|
|
arys
Joined: 09 Mar 2007 Posts: 31
|
|
Posted: Thu Mar 06, 2008 6:22 pm |
|
|
drh ; I did set_tris_b(0x00); but the output box said error. s'thing involved with declaration. Still dont know. very simple codes.
Ttelmah; here are the codes.
Code: |
#define (_PCM_)
#include <16F873.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//#use rs232(baud=2400,xmit=pin_c6, rcv=pin_c7, bits=8, ERRORS)
#byte PORTB=0x06
#byte PORTC=0x07
int8 d;
void main(void)
{
while(1)
{ if (INPUT(PIN_C4))
output_b(0b00000001);
if (INPUT(PIN_C5))
output_b(0b00000010);
}
}
|
|
|
|
arys
Joined: 09 Mar 2007 Posts: 31
|
|
Posted: Thu Mar 06, 2008 6:25 pm |
|
|
forgot to tell you. when i use
--> #include <16F877A.h>
no error in output box |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Fri Mar 07, 2008 9:07 am |
|
|
Quote: | Not true.
The default mode fo the CCS compiler, is 'standard_io' mode. In this mode, the compiler wll _automatically_ insert TRIS commands for you. |
I was talking about what the PIC does at power up. Whether or not the compiler sets the direction for you, it still needs to be set. _________________ David |
|
|
|