View previous topic :: View next topic |
Author |
Message |
andyd
Joined: 08 Mar 2007 Posts: 30
|
Making a whole port an output? |
Posted: Thu Mar 22, 2007 10:43 am |
|
|
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
|
|
Posted: Thu Mar 22, 2007 10:49 am |
|
|
PORTA is always 0 since you continually set i = 0 within the while loop.
r.b. |
|
|
andyd
Joined: 08 Mar 2007 Posts: 30
|
|
Posted: Thu Mar 22, 2007 12:16 pm |
|
|
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
|
|
Posted: Thu Mar 22, 2007 12:25 pm |
|
|
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
|
|
Posted: Fri Mar 23, 2007 6:13 am |
|
|
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
|
|
Posted: Fri Mar 23, 2007 7:32 am |
|
|
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
|
|
Posted: Fri Mar 23, 2007 8:25 am |
|
|
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
|
|
Posted: Fri Mar 23, 2007 9:23 am |
|
|
Have a look at 'fuses.txt' in the compiler's home directory.
Best Wishes |
|
|
andyd
Joined: 08 Mar 2007 Posts: 30
|
|
Posted: Fri Mar 23, 2007 11:05 am |
|
|
Thanks Ttelmah, just what I was looking for! |
|
|
|