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 support@ccsinfo.com

H E L P - 12F629 LED BLINK CODE NEEDED, PLEASE, PLEASE
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 16, 2006 3:53 pm     Reply with quote

The following program will blink an LED. This program was compiled
with PCM vs. 3.249. The anode of the LED must go to pin 7, and the
cathode must connect to a resistor (220 to 470 ohms) that goes to
ground. The 12F629 must be connected to a power supply, as follows:
+5v on pin 1, and Ground on pin 8.
Code:

#include <12F629.h>
#fuses INTRC_IO, NOWDT, NOMCLR, PUT, BROWNOUT
#use delay(clock=4000000)

//==========================
void main()
{

while(1)
   {
    output_high(PIN_A0);
    delay_ms(500);
    output_low(PIN_A0);
    delay_ms(500);
   }

}
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

Re: read up on C language
PostPosted: Wed Aug 16, 2006 3:54 pm     Reply with quote

kender wrote:
Funky_Banana wrote:
When I try and compile the above code it says in red bar at bottom of program: Expect ;

Homie had left out all necessary semicolons, which the compiler is expecting. My suggestion: read up on C language.


Funky_Banana :

There are example programs that come with (or used to anyway) the CCS compiler. Don't know what the V4 nonsense has done to those.

Also, go get yourself a copy of K&R's "The C Language, 2nd Edition". Read it, learn it, love it.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Funky_Banana



Joined: 16 Aug 2006
Posts: 9

View user's profile Send private message

PostPosted: Wed Aug 16, 2006 4:12 pm     Reply with quote

pcm programmer, many thanks, that compiled first time, this is furthest ive got! I will make it now and see if the led flashes, then i can have a play with the code.

I will try and find that book and buy it, if any one wants to put a copy on ebay I will buy it, let me know!

Thanks for your help guys, could not have got this far without you!!!!

If this works, I will then try adding other pins etc and try and get the hang of of it.
Funky_Banana



Joined: 16 Aug 2006
Posts: 9

View user's profile Send private message

PostPosted: Wed Aug 16, 2006 4:26 pm     Reply with quote

When the pic starts up are all pins set at low, Because the above code says sets RA0 High, so I presume it is low when first switch on. Or do they float and its pot luck?

Im so sorry to keep asking but cant seem to find anything I understand on the net as im so new to this.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

read the datasheet
PostPosted: Wed Aug 16, 2006 4:39 pm     Reply with quote

Funky_Banana wrote:
When the pic starts up are all pins set at low, Because the above code says sets RA0 High, so I presume it is low when first switch on. Or do they float and its pot luck?

When the PIC starts up, the pins go to the high impedance state, in other words, they float. If you connect an LED to a floating pin, it will never light up, so it's not even a pot luck. When you set the pin high or low, it automatically leaves the high impedance state.

Here's another thing you have to read, or at least skim though: datasheet for the PIC, which you're using.
Funky_Banana



Joined: 16 Aug 2006
Posts: 9

View user's profile Send private message

PostPosted: Wed Aug 16, 2006 4:55 pm     Reply with quote

Excellant, im learning fast! Ill be better than you lot before you know it lol!

so far
output_high(PIN_A0);
switches A0 High!

Is there a quick way of switching multiple pins high in 1 go. maybe

output_high(PIN_A0, A1, A2);

Would this work, probably not, but how can this be done?

I will soon find some examples and buy the book etc.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Wed Aug 16, 2006 5:51 pm     Reply with quote

Funky_Banana wrote:
Is there a quick way of switching multiple pins high in 1 go. maybe

output_high(PIN_A0, A1, A2);

Would this work, probably not, but how can this be done?

If all of the pins you want to write to are on the same port, you can use an output_a(0xYY). If the pins are not on the same port, probably, the easiest way would be to #define a macro that would aggregate the calls to output_() functions and take the pin constants as agruments.

Funky_Banana wrote:
I will soon find some examples...

The examples are, actually, very easy tofind. They are in the <program>\picc\examples directory.
Homie



Joined: 11 Aug 2006
Posts: 11

View user's profile Send private message

PostPosted: Wed Aug 16, 2006 7:42 pm     Reply with quote

sorry Banana for the syntax errors, i made the code while i was writing. In C you all way have to finish your statements with a ; Execpt if it is a function, define, include or likes. And the the error rwyoung was talking about (and you also found yourself) was that there also have to be a delay after the toggle comand, or else it will toggle low and then high so fast that you cant see it Smile

And a ICD is a In Circuit Debugger, the thing i ment was that if you program your chip ICSP (In Circuit Seriel Programming) you use some of your pins for that..

The blue text just mean that the compiler reconize the comand, all variables will be blue (integers, chars, bytes, void etc etc)

And as kender says if you want to write to the whole port at a time youll have to se it as a byte (hex) just like the set_tris comand i wrote (LessSignificantBit = port 0, the next = port 1 and so on. Just remember that with 6 ports the two MostSignificantBits have to be 0)

Hope i havent made you too confused with my bad syntax :P
-Thomas
Jakin
Guest







PostPosted: Thu Aug 17, 2006 2:43 pm     Reply with quote

Hi,All:
Can anyone tell how #fuse works for C language ? Thank you very much .
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 17, 2006 2:49 pm     Reply with quote

See this thread on fuses:
http://www.ccsinfo.com/forum/viewtopic.php?t=24336
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 17, 2006 3:06 pm     Reply with quote

Jakin wrote:
Hi,All:
Can anyone tell how #fuse works for C language ? Thank you very much .


It has nothing to do with C. The #fuses statement is an extension in the CCS compiler to allow the setting of a PIC's configuration bits.

Refer to the CCS C Compiler Reference Manual March 2006 page 42.

To learn about the configration bits for a particular PIC (for example a PIC18F2550) then go to
www.microchip.com, download the appropriate PIC's datasheet and read (and re-read, and re-re-read etc).
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 17, 2006 4:56 pm     Reply with quote

Funky_Banana wrote:
Excellant, im learning fast! Ill be better than you lot before you know it lol!


Doubt it Cool


Last edited by Mark on Thu Aug 17, 2006 9:52 pm; edited 1 time in total
Guest








PostPosted: Thu Aug 17, 2006 6:07 pm     Reply with quote

Mark wrote:
Funky_Banana wrote:
Excellant, im learning fast! Ill be better than you lot before you know it lol!


Doubt is Cool


we all srated somewhere >> you probably asked the same questions when starting out
theteaman



Joined: 04 Aug 2006
Posts: 98

View user's profile Send private message

PostPosted: Thu Aug 17, 2006 6:19 pm     Reply with quote

Anonymous wrote:
Mark wrote:
Funky_Banana wrote:
Excellant, im learning fast! Ill be better than you lot before you know it lol!


Doubt is Cool


we all srated somewhere >> you probably asked the same questions when starting out

Man arrives as a novice at each age of his life. -- Sebastien Chamfort
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Fri Aug 18, 2006 7:10 am     Reply with quote

Anonymous wrote:
Mark wrote:
Funky_Banana wrote:
Excellant, im learning fast! Ill be better than you lot before you know it lol!


Doubt is Cool


we all srated somewhere >> you probably asked the same questions when starting out


I think you missed out on the Cool smiley, the international "Wisenheimer" symbol.

I asked the same questions but to myself and then RTFM'd them. But enthusiasm counts, even more so when tempered by the discipline to read the manual and datasheet first.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
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, 3  Next
Page 1 of 3

 
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