CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC16F887 code help needed--- for C in CCS
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



Joined: 01 Jul 2010
Posts: 9658
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 9:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 9:31 pm     Reply with quote

Maybe there is a way...I just know that I found a way and that's all that matters Very Happy

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

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 9:37 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 10:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 10:48 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Thu Feb 09, 2012 4:34 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Feb 09, 2012 7:22 am     Reply with quote

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?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group