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
Funky_Banana



Joined: 16 Aug 2006
Posts: 9

View user's profile Send private message

H E L P - 12F629 LED BLINK CODE NEEDED, PLEASE, PLEASE
PostPosted: Wed Aug 16, 2006 1:24 pm     Reply with quote

Hi,

im new to this forum and just come across it!

I havnt a clue with pic programming and am very keen to learn. Im very good with electronics and have made many pic projects but never understood the code, so far ive made PLL units and RDS encoders but with pre made code and just slapped it onto the chips.

As far as im aware you write a source code and then convert to hex for the chip to understand? Correct me if im wrong

What im looking for is a SIMPLE CODE to turn on and off a pin on a 12f629 which will have an led connected to it. Ive tried doing it in assembly code but failed and am ready to slit my wrists, ive been trying now for several nights.

I want the LED to flash on and off and I want to be able to adjust the timings in the code.

Once im familiar with this I then want to add a push button to make it flash at different rates, but for now if somebody could point me in the direction of a simple on/off flasher i would be so gratefull!!

PLEASE HELP, IM VERY KEEN TO LEARN

IVE HEARD FROM A CLOSE FRIEND THAT YOU GUYS ARE VERY HELPFULL SO THANX IN ADVANCE
Funky_Banana



Joined: 16 Aug 2006
Posts: 9

View user's profile Send private message

Re: H E L P - 12F629 LED BLINK CODE NEEDED, PLEASE, PLEAS
PostPosted: Wed Aug 16, 2006 1:26 pm     Reply with quote

ALSO, If somebody can help with this can you also tell me what pin to connect the led to and where that pin is referenced to in the code?

Thanx
Homie



Joined: 11 Aug 2006
Posts: 11

View user's profile Send private message

PostPosted: Wed Aug 16, 2006 2:38 pm     Reply with quote

I dont know if it is in asembler or just i any language toy want some code help..

but heres in C
Code:
/*you start with adding your device header file (holds all the info over the pic, such as pins, timers etc etc)..*/
#include <12f629.h>

/*then in the datasheet over the pic you see what i/o pins you have avaible..*/
/*Lets use GP2 pin 5 makes room for ICD if youre using that.
in the CCS compiler, the device header file calls GP2 for PIN_A2 (#Define  PIN_A2       42) where 42 is the internal address that defines GP2*/
void main()//starts your main program
{
    set_tris_a(0x3b) /*set port 2 to output(0) the rest to input(1) port 0 = LSB, port 1 = the next bit and so on. bit 6 and 7 is 0 because of only 6 i/o ports*/
    while (1)//starts an infinite loop
    {
        output_high(PIN_A2)/*sets GP2(pin 5) high*/
        delay_ms(500)/*makes at delay on 500ms*/
        output_toggle(PIN_A2)/*invert the state on GP2(pin 5) (if 1 -> 0 and if 0 ->1)*/
    }
}


I hope it helps
-Thomas
Funky_Banana



Joined: 16 Aug 2006
Posts: 9

View user's profile Send private message

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

Many thanks Thomas,

I will attemt that code now!!!!!!1

you wrote 'makes room for ICD if youre using that'

What is ICD? im a real beginner!

Is there any good tutorial website you know of where I can learn?

Thanks
rwyoung



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

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

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

Yea, except what you posted will toggle the pin but not such that you could see much on a LED. I leave it as homework for you to figure out why... Wink
_________________
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 3:15 pm     Reply with quote

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

and it higlights: while from the line: while (1)//starts an infinite loop

viod and while is also in blue before i try and compile it. what does the blue text mean?


Also, what does this do: output_toggle(PIN_A2) , I understand it inverts the pin from high to low or vice versa 0 - 1, but do you not need another delay after this before it loops to the top, because at the top it says make that pin high. So it starts the cycle, sends the pin high, delay, then output toggle (reverse state of pin to 0), but then loops to top and immediately changes to 1. Or have I got it all wrong?



Sorry to ask so many questions lol.
Funky_Banana



Joined: 16 Aug 2006
Posts: 9

View user's profile Send private message

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

Im running CCS C IDE Version 4.43 if this helps.

Im clicking new, creting a new file in new folder, then I get blank page, im then pasting the above code into there and then clicking compile (F9)
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 up on C language
PostPosted: Wed Aug 16, 2006 3:29 pm     Reply with quote

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.
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.
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