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

Making a whole port an output?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
andyd



Joined: 08 Mar 2007
Posts: 30

View user's profile Send private message

Making a whole port an output?
PostPosted: Thu Mar 22, 2007 10:43 am     Reply with quote

This is probably really simple but I can't get my head round it - I'm trying to make a whole port (A) represent an integer value in my program (so that it can feed a DAC), but I can't get it to do anything. It's slightly complicated because pin A5 is always an input, so I've tried to make whatever value would be on this pin be output on an unused pin on port B (B6). However, with the test program I've written (just a simple upcounter) I get no output on any of the pins and was wondering if someone could point out the stupid mistake I've probably made!

Code:
#include <16f88.h>
#include <stdio.h>

#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock = 8000000)
#byte PORTA = 0x05


void main()

{

int i;
int x;

set_tris_a (0x00);
set_tris_b (0x00);

SETUP_ADC_PORTS(NO_ANALOGS);
setup_oscillator(OSC_8MHZ|OSC_INTRC);

// Initialise all pins to 0

output_low(PIN_A0);
output_low(PIN_A1);
output_low(PIN_A2);
output_low(PIN_A3);
output_low(PIN_A4);
output_low(PIN_B6);
output_low(PIN_A6);
output_low(PIN_A7);

while(TRUE){

i = 0;

PORTA = i;
x = i&&0b00100000;

if(x != 0) output_high(PIN_B6); // If bit 5 is high, set B6 high
else  output_low(PIN_B6);

delay_ms(10);
i++;   
}

}
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Thu Mar 22, 2007 10:49 am     Reply with quote

PORTA is always 0 since you continually set i = 0 within the while loop.

r.b.
andyd



Joined: 08 Mar 2007
Posts: 30

View user's profile Send private message

PostPosted: Thu Mar 22, 2007 12:16 pm     Reply with quote

Ah ok, that was a stupid mistake! However, I can't get RA6 & RA7 to turn on at all, even when I try to set them high manually using output_high(). Is it anything to do with the fact that they're the pins for the oscillator (even though I'm using the internal one)? Also, B6 stays high the whole time (though that can be toggled on/off manually). Any ideas what could be causing that?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 22, 2007 12:25 pm     Reply with quote

Quote:

However, I can't get RA6 & RA7 to turn on at all.
Is it anything to do with the fact that they're the pins for the oscillator
(even though I'm using the internal one)?

#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT

Get rid of the HS fuse and use INTRC_IO instead.

For future reference, look at the top of the 16F88.H file for a
list of fuse settings.


Quote:
x = i&&0b00100000;

You're doing a logical AND operation here. The single '&' does a
bitwise AND. Also, you should put spaces in between variables,
constants and operators. It makes the code more readable and
less error-prone.
andyd



Joined: 08 Mar 2007
Posts: 30

View user's profile Send private message

PostPosted: Fri Mar 23, 2007 6:13 am     Reply with quote

Thanks, that worked perfectly!

Re: the fuse settings, I knew they were all listed at the top of the device header file, and while a lot of them are fairly self explanitory, is there any documentation that explains what the less obvious ones do? I had a look in the CCS manual but couldn't seem to find anything in there.
frequentguest
Guest







PostPosted: Fri Mar 23, 2007 7:32 am     Reply with quote

The fuse settings are directly related to configurations for the particular PIC you are programming. The best place to look is in the data sheet for your PIC.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Mar 23, 2007 8:25 am     Reply with quote

If you happen to have the compiler IDE you can see the various Fuses for each device by selecting from the menu bar: View > Valid Fuses and then select the device you want to examine.

Ronald
Ttelmah
Guest







PostPosted: Fri Mar 23, 2007 9:23 am     Reply with quote

Have a look at 'fuses.txt' in the compiler's home directory.

Best Wishes
andyd



Joined: 08 Mar 2007
Posts: 30

View user's profile Send private message

PostPosted: Fri Mar 23, 2007 11:05 am     Reply with quote

Thanks Ttelmah, just what I was looking for!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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