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 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rems



Joined: 02 Feb 2012
Posts: 56

View user's profile Send private message

PIC16F887 code help needed--- for C in CCS
PostPosted: Thu Feb 02, 2012 11:11 pm     Reply with quote

Hello all,

Brand new member here. I need help with something that may be very simple for experienced person but not for me.

I really want to learn this stuff and feel a good start would be by seeing some sample code for what I want to accomplish.

I'm using a PIC16F887---C language---in MPlab---CCS

All I want to do is cycle 4 o/p pins of the pic to control 4 led's in such a way that they light up in binary sequence. For eg: Say I use pb0 to pb3 fo my 4 o/p's(pb3=msb and pb0=lsb)....I want it to cycle as follows:
1. output a low to all 4 pins for binary 0.
2. output a low to pb3, pb2 and pb1 but HI to pb0 for binary 1
3. so on and forth all the way to 10 or 11....
Basically, I will hook up my leds to these outputs and I want to watch them cycle from 0 to 10 in binary.
So when step one executes---no leds light
when step two executes then just the lsb o/p light the led.

I think everyone knows what I mean...Like I said its quite a simple program. It's just that I'm not to familiar with pics or c but have enough knowledge to work my way through sample code to learn from..

This would be a great deal appreciated by me and I hope someone can help me...Even just do the first couple cycles....say to 5 and I'll fill in the rest....comments would be great to but not completely necessary as I do have minimal experience,,,

Thanks a lot to everyone for this wonderful forum

REMS
temtronic



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

View user's profile Send private message

PostPosted: Fri Feb 03, 2012 6:25 am     Reply with quote

I suggest you take the time to read the examples CCS kindly supplies in the examples folder as well as the manual. Both will show and explain everything you need to accomplish your project.
Once you've created the basic 'blinking LED' program, show us yuor atempts at coding and we'll help out.
rems



Joined: 02 Feb 2012
Posts: 56

View user's profile Send private message

PostPosted: Fri Feb 03, 2012 7:58 pm     Reply with quote

temtronic wrote:
I suggest you take the time to read the examples CCS kindly supplies in the examples folder as well as the manual. Both will show and explain everything you need to accomplish your project.
Once you've created the basic 'blinking LED' program, show us yuor atempts at coding and we'll help out.


Okay, That's completely fair...Thank you very much...I'll see what I can do...
rems



Joined: 02 Feb 2012
Posts: 56

View user's profile Send private message

Starting from scratch
PostPosted: Wed Feb 08, 2012 9:30 am     Reply with quote

am trying to use the following code to just verify that I can at least communicate with my PIC.
Code:

#INCLUDE <16F887.h>
#USE DELAY (CLOCK=4000000)
void main() {


   output_high(pin_C1);
}

But I get the following message when I try to bulid.

Build aborted. The project contains no source files.
BUILD FAILED: Wed Feb 08 10:26:01 2012

I am including the necessary header file and everything.

Can anybody help?

As a reminder I am using a pic16f887 with ccs in mplab.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 9:43 am     Reply with quote

Don't include the header files.
You should have _one_ code file called (say) "main.c", containing the code you have posted (with one extra line - see latter).
This file should be the only one included in the 'project'.
MPLAB will try to compile every file in the 'project' separately. The CCS header files _will not compile like this_. They only work if loaded from a 'main' program.

The extra line, is a _fuse_ line. This is _required:
#FUSES XT,NOWDT,NOPROTECT,NOLVP

So:
Code:

#INCLUDE <16F887.h>
#FUSES XT,NOWDT,NOPROTECT,NOLVP
#USE DELAY (CLOCK=4000000)

void main(void) {
   output_high(pin_C1);
}


This is all assuming you _have_ got a 4Mhz crystal attached to the oscillator pins, with the correct loading capacitors, and MCLR pulled high on the chip.

MPLAB should then compile this.

Best Wishes
rems



Joined: 02 Feb 2012
Posts: 56

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 9:47 am     Reply with quote

I realized I was writing my code in the wrong window...Embarrassed is an understatement.

I am getting the following error though now.

I/O error 103

Any ideas?
rems



Joined: 02 Feb 2012
Posts: 56

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 9:51 am     Reply with quote

Ttelmah wrote:
Don't include the header files.
You should have _one_ code file called (say) "main.c", containing the code you have posted (with one extra line - see latter).
This file should be the only one included in the 'project'.
MPLAB will try to compile every file in the 'project' separately. The CCS header files _will not compile like this_. They only work if loaded from a 'main' program.

The extra line, is a _fuse_ line. This is _required:
#FUSES XT,NOWDT,NOPROTECT,NOLVP

So:
Code:

#INCLUDE <16F887.h>
#FUSES XT,NOWDT,NOPROTECT,NOLVP
#USE DELAY (CLOCK=4000000)

void main(void) {
   output_high(pin_C1);
}


This is all assuming you _have_ got a 4Mhz crystal attached to the oscillator pins, with the correct loading capacitors, and MCLR pulled high on the chip.

MPLAB should then compile this.

Best Wishes


Thank you for your response...I will take your advice
rems



Joined: 02 Feb 2012
Posts: 56

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 9:57 am     Reply with quote

I found another poster with the same dilemma and he was told the following

"It was due to the compiler not selecting the correct compiler version in the compile ribbon."

How can I fix this?
rems



Joined: 02 Feb 2012
Posts: 56

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 10:00 am     Reply with quote

And now I found this from delphi

"I/O Error 103:
IO Error 103L
ERROR_TOO_MANY_SEM_REQUESTS
MessageText:
The semaphore cannot be set again.
"
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 3:23 pm     Reply with quote

Are you trying to compile on a network? If so it is likely a network problem.
Try moving the files to your local hard drive.

If not, this can also be caused by one of your compiler files being held open
by another application. Make sure all other programs other than
MPLAB are closed before you compile.
_________________
Google and Forum Search are some of your best tools!!!!
rems



Joined: 02 Feb 2012
Posts: 56

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 6:26 pm     Reply with quote

I'm getting somewhere but still no complete luck.

I finally concluded that for some reason I need to have my test.c file preloaded into a folder. That way when I do "project wizard", I can add it then to my project.
What I was doing was going through "proj wizard" and adding no files. Once through the wizard, I would add my header file and then I would click on the FILE tab and choose" add new file to project". I would name it "anything.c". When the blank screen would come I would just copy and paste text I had waiting for me in a notepad window. This was causing me serious warnings and errors that I couldn't figure out.

Does this sound like"Well of course you idiot" or is this a fluke?

Can Someone clear this up?

I'm not reading anything on the pin that should be activated but at least the build is successful.
John Morley



Joined: 09 Aug 2004
Posts: 97

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 6:51 pm     Reply with quote

Hi Rems,

First of all, why did you start a THIRD thread on this problem?? Your style will quickly alienate people, and you won't get any help before long.....

Based on that now locked thread, here is a comment:

As far as your problem, it looks like you've got multiple source files in your project, 'CCS_44P_Demo.c' AND 'LEDBlink.c', which you cannot do with MPLAB/CCS 'C'. Did you create the MPLAB project from scratch, or just add to an existing project? In any event, you need to specify only one 'Source' file.

John
_________________
John Morley
rems



Joined: 02 Feb 2012
Posts: 56

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 6:58 pm     Reply with quote

Thank you John.

Honestly, I have looked all over for my original thread and couldn't find it. I tried my profile and whatever I could. Sorry to anyone that this caused confusion for.

John, what you said makes a lot of sense. Thank you. I kept doing Project Wizard and I would overwrite files that I tried before. I'm not too sure how it took multiple files but....

I now know that I can grab a pre-existing.c file during project wizard and build is successful.

Lesson learned...

All in all, my chip is pin is not responding on the chip still, but that is another problem I guess. I did program with pickit 2 after successful build. I am using an led to verify if the pin is turning on and off and nothing. The only pins that turn the led on are VDD.
So...Not sure what's up now..but will keep trying

Thank you
rems



Joined: 02 Feb 2012
Posts: 56

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 7:01 pm     Reply with quote

This is the code I am using now
Code:

#include <16F887.h>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, MCLR, NOLVP
#use delay(clock=8000000)

void main()
{

while(1)
   {
    output_high(PIN_D2);
    delay_ms(1000);
    output_low(PIN_D2);
    delay_ms(1000);
   }

}
rems



Joined: 02 Feb 2012
Posts: 56

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 7:56 pm     Reply with quote

I feel quite silly...
I have complete success...

I just realized that I need to import the hex file created by mplab into the PICKIT 2 software and WRITE it to my device...

I though that just by clicking on the PROGRAMMER tab within mplab and choosing my device, that I was done.. I mean it said PICKIT ready and my led would light up on VDD. Just no on the pins it was supposed to.

I went to the PICKIT software and imported the hex file and BAM...Led is blinking....

After sitting here all day, I can't describe the elation I feel right now. I'm sure everyone knows what I mean. Thank you to all who have helped. I'm sure whoever reads this will shake their heads as it was very silly of me. But hey..I wont make that mistake again.

Thanks all
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 1, 2  Next
Page 1 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