View previous topic :: View next topic |
Author |
Message |
Colin_Brenton
Joined: 10 Feb 2011 Posts: 2
|
16F631 port C problems |
Posted: Thu Feb 10, 2011 7:09 am |
|
|
Hi,
I wondered if anyone could help me with a problem I have with PIC 16F631?
I've used the code below to switch on all eight pins of port C, but 0-3 pulse between zero and 5 volts when instructed to be 'on'. The waveform is a square wave, frequency of around 11Khz, on for 10uS, off for around 80uS.
Bits 4-7 work correctly, producing 5v.
Should I disable the comparator and or analog that shares the pins...?
Code: |
#include<16F631.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#define AVDNEG09 PIN_C0
#define AVDDBB PIN_C1
#define VDD PIN_C2
#define ADDADC PIN_C3
#define AVDD1V8 PIN_C4
#define AVDD1V8A PIN_C5
#define AVDNEG1V8 PIN_C6
#define VDE PIN_C7
#use delay(clock=8000000)
setup_comparator_(NO_COMPARATORS);
setup_adc_(NO_ANALOGS);
#use standard_IO(C)
void main (void)
{
while(1==1)
{
output_high(AVDNEG09);
output_high(AVDDBB);
output_high(VDD);
output_high(ADDADC);
output_high(AVDD1V8);
output_high(AVDD1V8A);
output_high(AVDNEG1V8);
output_high(VDE);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 10, 2011 1:58 pm |
|
|
These two lines in bold need to be placed at the start of main(). They
don't do anything when placed above main().
Quote: |
setup_comparator_(NO_COMPARATORS);
setup_adc_(NO_ANALOGS);
#use standard_IO(C)
void main (void)
{
while(1==1)
{
output_high(AVDNEG09);
output_high(AVDDBB);
output_high(VDD);
output_high(ADDADC);
output_high(AVDD1V8);
output_high(AVDD1V8A);
output_high(AVDNEG1V8);
output_high(VDE);
}
}
|
Also, always post your compiler version. This allows us (the forum
members, not CCS), to check the .LST file and look for bugs in your
version. |
|
|
Colin_Brenton
Joined: 10 Feb 2011 Posts: 2
|
|
Posted: Thu Feb 17, 2011 2:34 am |
|
|
Hi,
For those who like to know the outcome of these things, it transpired there was a bug in the CCS compiler, such that the analouge pins were not being set to digital. Adding an instruction to manually write zeros to the correct register solved the problems.
Thanks PCM programmer for your advice
BR,
Colin |
|
|
|