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

Beginner's problems with 16F747

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



Joined: 17 Apr 2007
Posts: 17

View user's profile Send private message

Beginner's problems with 16F747
PostPosted: Mon Sep 26, 2011 11:44 pm     Reply with quote

Hello,

I just started to program PIC microcontrollers so I don't have many experiences with programing. I read some datasheets and manual for programming with CCS.

In past I already made a "project" called knightrider - LED running left and right - this worked ok with 16F747. Now I'm trying to make a program with a few digital inputs and about 20 digital outputs. I started my project as a copy of the knightrider project and than just changed the functions after the #include, #define, #use ... lines.

Pins on port C and D work ok as outputs and inputs, but on port A and B I have problems reading inputs A0-A5, I also cannot read pins B4-B1. I guess some things are missing in my first lines because if I change my inputs from mentioned pins to D0 or D1 program works without problems...

My CCS version is 4.20.

I really hope someone can help me with this basic problems.

Program:
Code:

#include <16F747.h>

#fuses INTRC_IO, NOWDT, NOPROTECT, NOMCLR, NOPUT, NOFCMEN
#use delay(clock=4000000)

#define RA0 PIN_A0
#define RA1 PIN_A1
  .
  .
  .
  .
#define RE2 PIN_E2
#define RE3 PIN_E3

SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
SETUP_CCP2(CCP_OFF);

void xxxxx()
{
//code
}

void main()
{
xxxxx();
}
temtronic



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

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 5:38 am     Reply with quote

Be sure to turn off, disable ANY internal peripherals associated with the pins you wnat to use as digital I/O. Also some pins are one direction only(in OR out NOT both !).
Newer PICs can have 4 or more peripherals associated with one pin so read the datasheet to see what the defaults are as well as the dotheader file.Most won't default to plain old digital I/O!
taubek



Joined: 17 Apr 2007
Posts: 17

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 5:56 am     Reply with quote

I have turned off analog signals, i also tried with CMCON1 0x07 like someone told me to try..

can someone write exactly which lines should be on the begining of my program to have all pins like digital inputs or outputs. I know that some of them cannot be both, output and input.

In examples are everywhere just fuses and than adc setup set to no analog..

help please, Taubek
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 12:18 pm     Reply with quote

Quote:
My CCS version is 4.20.

That's not a version. These are version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo

What is your real version number ?

You can find the version at the top of the .LST file, in your project
directory, after a successful compilation.
taubek



Joined: 17 Apr 2007
Posts: 17

View user's profile Send private message

PostPosted: Fri Oct 07, 2011 10:50 pm     Reply with quote

Hi,

sorry for late reply, I didn't have any time to work with PIC and CCS because of my job.

I checked the version. It is 3.203. Hope that helps.

br.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 07, 2011 11:32 pm     Reply with quote

Are these 3 lines of code (in bold) really stuck out in space like this ?
Quote:

#define RE2 PIN_E2
#define RE3 PIN_E3

SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
SETUP_CCP2(CCP_OFF);


void xxxxx()
{


}

void main()
{
xxxxx();
}

Because if they are, that's wrong. All lines of code must be in a function.
In your case those 3 lines should be at the start of the main() function.

Vs. 3.203 is an old version, and it's buggy because CCS did some major
changes in the compiler starting with vs. 3.200. They didn't get all the
bugs out for several more versions after that. Your compiler version
does not give an error if you put lines of code outside a function.
If that's the problem, you need to fix it.
taubek



Joined: 17 Apr 2007
Posts: 17

View user's profile Send private message

PostPosted: Mon Oct 10, 2011 9:35 am     Reply with quote

PCM programmer, thank you so much for all your help, the problem was that those lines were outside of main function.

thanks again,

Taubek
taubek



Joined: 17 Apr 2007
Posts: 17

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 2:43 am     Reply with quote

Hello again,

I finally have time to make progress on this project again. I also have an analog input on this PIC. I can read it, but the value is only 0-255 (8bit). In datasheets is written that there should be 10bits for it, values 0-1024.

Here is my code:
Code:

int ref2=0; // I also tryed with double ref2=0;

void read_temp()
{
set_adc_channel(0); //read analog input AN0
delay_ms(5);
ref2=read_adc();

if ((ref2>50)&&(ref2<200)) // here I would like resolution 0-1024
  {
   output_high(RD6); //test output
  }

if ((ref2<=50)||(ref2>=200))
  {
   output_low(RD6);
  }
}

void main()
{
SETUP_ADC_PORTS(AN0_TO_AN2_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);

while(1)
  {
   read_temp();
  }
}


Hope someone can tell me how to get 10bit number out of that.

Thanks. Taubek
taubek



Joined: 17 Apr 2007
Posts: 17

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 11:44 am     Reply with quote

Somebody help me please, I'm trying to figure out this thing for the whole day and no progress... It looks that I read only register ADRESL without ADRESH...

Is it possible to read register directly? Something like:
value1=read (ADRESL);
value2=read (ADRESH);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 12:03 pm     Reply with quote

Look at the #device statement in this sample program:
http://www.ccsinfo.com/forum/viewtopic.php?t=37023&start=3

Download the CCS manual for future reference. Look in the sections
on read_adc() and also #device:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
taubek



Joined: 17 Apr 2007
Posts: 17

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 12:43 pm     Reply with quote

Thanks a lot PCM programmer, it was missing statement #device adc=10 in my program.
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