| View previous topic :: View next topic |
| Author |
Message |
temtronic
Joined: 01 Jul 2010 Posts: 9658 Location: Greensville,Ontario
|
|
Posted: Wed Feb 08, 2012 9:15 pm |
|
|
I would have thought you could program the PIC in the same pull down menu as the 'programmer choice/enable/etc.)
I still use my PicstartPlus and can read/write/etc. from that selection...
Then again it's almost 20 years old.... |
|
 |
rems
Joined: 02 Feb 2012 Posts: 56
|
|
Posted: Wed Feb 08, 2012 9:31 pm |
|
|
Maybe there is a way...I just know that I found a way and that's all that matters
I have been searching for a cpl hours and reading code examples on the forum and in the manuals and still cant find anything on controlling a whole port.
This is getting back to my original inquiry.
I want to do something like:
output_portD ( bx00000001);
that way it will enable pin D0 as high and the rest of the pins low. The problem is that I cant use what I just wrote. Is now the time when I need to use "tris" and set the direction of D to output?
or maybe
OUTPUT_D(0x00);
I just don't know how to write it properly..I have looked everywhere. Can someone point me in the direction to look? Once I can do that, I can just come up with 10 binary sequences, put them in a loop and voila. I can exercise the decoder. |
|
 |
rems
Joined: 02 Feb 2012 Posts: 56
|
|
Posted: Wed Feb 08, 2012 9:37 pm |
|
|
This is what I am trying
| Code: |
#include <16F887.h>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, MCLR, NOLVP
#use delay(clock=8000000)
//===============================
void init_io()
{
OUTPUT_D(0x00);
}
void main()
{
while(1)
{
PORTD = bx00000001;
delay_ms(1000);
}
} |
But it no work yet.
Any advice or direction? |
|
 |
rems
Joined: 02 Feb 2012 Posts: 56
|
|
Posted: Wed Feb 08, 2012 10:13 pm |
|
|
I got it...After more careful inspection of the header file
| Code: |
#include <16F887.h>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, MCLR, NOLVP
#use delay(clock=8000000)
//===============================
void main()
{
while(1)
{
SET_TRIS_D(0x00); // set direction to be output
OUTPUT_D(0b00000001); // Enable PIN_D0 only
}
}
|
It works |
|
 |
rems
Joined: 02 Feb 2012 Posts: 56
|
|
Posted: Wed Feb 08, 2012 10:48 pm |
|
|
Here is my final product. It will "exercise a 4 to 10 decoder"
| Code: |
#include <16F887.h>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, MCLR, NOLVP
#use delay(clock=8000000)
void main()
{
while(1)
{
SET_TRIS_D(0x00); // set direction to be output
//LSB IS D0 & MSB IS D7
OUTPUT_D(0b00000000); // Binary # 0
delay_ms(4000);
OUTPUT_D(0b00000001); // Binary # 1
delay_ms(4000);
OUTPUT_D(0b00000010); // Binary # 2
delay_ms(4000);
OUTPUT_D(0b00000011); // Binary # 3
delay_ms(4000);
OUTPUT_D(0b00000100); // Binary # 4
delay_ms(4000);
OUTPUT_D(0b00000101); // Binary # 5
delay_ms(4000);
OUTPUT_D(0b00000110); // Binary # 6
delay_ms(4000);
OUTPUT_D(0b00000111); // Binary # 7
delay_ms(4000);
OUTPUT_D(0b00001000); // Binary # 8
delay_ms(4000);
OUTPUT_D(0b00001001); // Binary # 9
delay_ms(4000);
}
}
|
I just attach pins D0 to D3 as inputs to the decoder and as the program counts through from 0 to 9, the o/p's 0 through 9 of the decoder shall be activated respectively. |
|
 |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Thu Feb 09, 2012 4:34 am |
|
|
| Most don't use set_tris.......the compiler is perfectly capable of doing the job for you with its input and output statements . Sure, set tris will work but most use it only in very specific situations. |
|
 |
rems
Joined: 02 Feb 2012 Posts: 56
|
|
Posted: Thu Feb 09, 2012 7:22 am |
|
|
Okay...Great....I wasn't sure. I never tried it without. That's good to know.
Maybe it's used more when someone has some ports/pins as i/p and some as o/p, as a way to keep track. Not to sure...
In the case of designating ports/pins as inputs, it is needed though right? |
|
 |
|