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

Newbie
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
iou_82



Joined: 14 Jun 2004
Posts: 7

View user's profile Send private message

Newbie
PostPosted: Mon Jun 14, 2004 1:59 am     Reply with quote

Hi,

I am totally new to this Pic Programming, could anyone please help me, wether where should I begin. I will need to work on the chip 16F877. But I have no idea where to begin.
Please advice on what software should I use.

Thank you
Ttelmah
Guest







Re: Newbie
PostPosted: Mon Jun 14, 2004 3:42 am     Reply with quote

iou_82 wrote:
Hi,

I am totally new to this Pic Programming, could anyone please help me, wether where should I begin. I will need to work on the chip 16F877. But I have no idea where to begin.
Please advice on what software should I use.

Thank you

This is a bit like asking 'I want to learn to drive, where should I start'. It is a very open ended question, and one whose answer will depend on what you allready know. You don't say whether you have any other programming experience (once you have learn't one programming language, learning a second one is a lot easier), or whether you have any experience in electronics at all (programming a 'microcontroller', does require some understanding of it's basic operations, if you are not going to waste a lot of time...).
Now the 'chip', doesn't really matter in this regad, since most of the peripheral components are 'common' on the different models in the line. If you were in the UK, and have no programming experience, I'd probably suggest getting one of the basic Magenta PIC tutorial kits, and learning enough about operating the chip, to get you started, using assembler, and only once you can do basic operations with this, consider using a 'high level' language. There are hundreds of books on C' programming (rather than C++). However if you allready have high level experience, then I'd probably suggest going the other way, and getting one of the demo boards, programming a very basic 'hello world' type operation, and then seeing if you can understand how this works from the assembler.
The 'key' with the PIC, is that though the CCS compiler tries to hide the hardware from you (automatically switching the pins data directions etc.), you have to be aware of what is really going on, and that there isn't an 'OS' sitting protecting your work from the vagaries of the hardware.
So (for instance), there was a poster recently, who was having problems sending serial data, while receiving data. The problem here was that on a PC for instance, the 'getc', and 'putc' functions, don't talk directly to the port, but to a relatively large serial buffer, with flow control being operated by the OS for you. Yet on the PIC, these same functions, are talking directly to the hardware, and if a long string is sent, inside the 'receive' handler, received data will then potentially be lost if it arrives while this is going on. So you need to have a very real undertsanding that you are talking directly to the hardware, and the limitations of this.

Best Wishes
Guest








PostPosted: Mon Jun 14, 2004 6:04 am     Reply with quote

jds-pic wrote:



you can not learn C by looking at an i2c driver.

first, purchase the book "The C Programming Language" by Kernighan and Ritchie. you can get it online for about US$30. this is *the* book when it comes to learning practical C. amazingly, it is not a thick, unwieldy text.

next, write a hello world program in C for your PIC.

then, write a program that stores and retrieves values from a generic i2c EEPROM. this will give you a foundation for the "master-slave" nature of i2c communications.

finally, you can move on to having two pics talk over i2c, with one acting as the master and the other as the slave.

if you are trying to skip directly to the last step, i think you will have a frustrating road. if it's any consolation, i made the same mistake when i learned java -- especially with java's native handling of error conditions. i was in too much of a hurry to bother with learning the fundamentals of throwing/catching exceptions; subsequently, i became increasingly frustrated until i went back and really dug into how it all worked.

all that said, why don't you just connect the your pics with two wires and speak TTL-level serial at 19,200bps between them? debugging is trivial compared to master/slave i2c, and you just need to learn the printf() and getc() functions.

jds-pic


http://www.ccsinfo.com/forum/viewtopic.php?t=19555&sid=d4d9cda38fc40a4a02d6251e7e70ea06
iou_82



Joined: 14 Jun 2004
Posts: 7

View user's profile Send private message

Re : Newbie
PostPosted: Tue Jun 15, 2004 2:12 am     Reply with quote

Thanks for the infomation. I dun really have much expereince with C, but i am studying it at the moment. I also have the Hardware ( Pic Programmer - Pic16F84A - 7X16 LED Running Light Signboard ) with me.

I would like to try the ' Hello World ' , would you please post a sample programe that run the ' Hello World ' using C for me to try to download into my Chip. Thanks in advance.

Regards.

Eugene
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Re : Newbie
PostPosted: Tue Jun 15, 2004 8:11 am     Reply with quote

iou_82 wrote:
Thanks for the infomation. I dun really have much expereince with C, but i am studying it at the moment. I also have the Hardware ( Pic Programmer - Pic16F84A - 7X16 LED Running Light Signboard ) with me.

I would like to try the ' Hello World ' , would you please post a sample programe that run the ' Hello World ' using C for me to try to download into my Chip. Thanks in advance.

Regards.

Eugene


Read the manual. All of it. Cover to cover. There is a list of example programms in it. You will find what you are looking for and be better prepaired to solve problems in the future.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 8:25 am     Reply with quote

I have found that the best, not necessarily the easiest, way to learn things like this is simply to dive in and start messing around. Pull out the book, read what you can, dig around this forum (doing searches) and start writing your own code. Make it simple at first. Maybe just make an output toggle high and low. Then, print something out on the display. Each time, you'll bang your head against the monitor trying to figure out what you did wrong. When you finally realize what you did and then fix it, you'll most likely remember it from then on. Whereas, if somebody just told you how to do it you'll need to be reminded on how to do it again each time. I know I have a flat forehead from smacking it so much. Twisted Evil

Good luck.

Ronald
iou_82



Joined: 14 Jun 2004
Posts: 7

View user's profile Send private message

RE:
PostPosted: Wed Jun 16, 2004 10:12 pm     Reply with quote

Thank for the info, I am getting more familiar with it , I would like to know one more thing is that do I need to use a different version of compiler each time I work with a different type of Chip.

I am currently using 16f84a, which version of compiler should I use.

Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 16, 2004 10:32 pm     Reply with quote

Quote:
I am currently using 16f84a, which version of compiler should I use.

CCS has a page that shows which compiler is used for each PIC.
In the table, "M" means the PCM compiler, "H" means PCH, and
"B" means PCB.
http://www.ccsinfo.com/devices.shtml
iou_82



Joined: 14 Jun 2004
Posts: 7

View user's profile Send private message

LED
PostPosted: Wed Jun 23, 2004 2:29 am     Reply with quote

HI,


I am getting more familiar with the chip 16f84a currently, and using C language to programme it. I would like to know wether is it posible to make the LED - On and Off ' slowly ' , something like DIMMER.

Thank you
Joan



Joined: 29 May 2004
Posts: 41
Location: Barcelona, Spain

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

Re: LED
PostPosted: Wed Jun 23, 2004 3:34 am     Reply with quote

iou_82 wrote:
HI,


I am getting more familiar with the chip 16f84a currently, and using C language to programme it. I would like to know wether is it posible to make the LED - On and Off ' slowly ' , something like DIMMER.

Thank you


Hi iou_82:

you can write a routine for a variable PWM.

Regards;
Joan
_________________
I Came. I Saw. I Won.
iou_82



Joined: 14 Jun 2004
Posts: 7

View user's profile Send private message

RE:
PostPosted: Wed Jun 23, 2004 10:14 pm     Reply with quote

HI, Joan

I dun really understand what u mean, can u please advice more.

Thank you

Regards,
Eugene
Ttelmah
Guest







Re: RE:
PostPosted: Thu Jun 24, 2004 2:19 am     Reply with quote

iou_82 wrote:
HI, Joan

I dun really understand what u mean, can u please advice more.

Thank you

Regards,
Eugene

At 'heart', logic outputs on the chips, can only be either 'off', or 'on'. The way to make a light 'dim', is to flash it fast enough that the eye cannot see the flashes. If (for instance), the light is flashed at a rate of 1000 times per second, and at each 'on flash, is turned on for just 1uSec, then this on time is increased steadily over the course of perhaps a second, till at the end of the tme, the light is now 'on' for 999uSec, then the effect will be for the light to brighten over the second. This process of changing a pulse width like this, is called 'Pulse Width Modulation' (PWM).
Many of the larger chips, have 'hardware PWM' circuitry built in, allowing flash rates of many kHz. The 16F84, does not have this ability, but even on these, the processors are so fast (relative to the rate that the human eye can see), that it is possible to generate a 'soft PWM', to give a dimming effect.
Do a seach on PWM', on this group, and you will find hundreds of examples, with some covering the 'soft PWM' approach.

Best Wishes
iou_82



Joined: 14 Jun 2004
Posts: 7

View user's profile Send private message

Blinking LED
PostPosted: Fri Jun 25, 2004 3:10 am     Reply with quote

Ttelmah,

Thank for the info, I will need to put that as my second assignment.

I am working on 16f628 chip right now, and i have write a simple code to make 1(A) LED blinking and the other 1(B) ON all the time,while (A) is blinking, but when i want to make 2 LED blinking at the same time but at different blinking rate it was not archivable.

What i mean :- (A)LED to blink at 1 SEC Normal blink
(B)LED to blink at 10 SEC Slow blink
(C)LED to blink at 0.5 SEC Fast blink

Is it posible??

Please advice and if posible please provide me with a sample code.

Thank you
Regards,
Eugene
Joan



Joined: 29 May 2004
Posts: 41
Location: Barcelona, Spain

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

Re: Blinking LED
PostPosted: Fri Jun 25, 2004 5:13 am     Reply with quote

iou_82 wrote:
Ttelmah,

Thank for the info, I will need to put that as my second assignment.

I am working on 16f628 chip right now, and i have write a simple code to make 1(A) LED blinking and the other 1(B) ON all the time,while (A) is blinking, but when i want to make 2 LED blinking at the same time but at different blinking rate it was not archivable.

What i mean :- (A)LED to blink at 1 SEC Normal blink
(B)LED to blink at 10 SEC Slow blink
(C)LED to blink at 0.5 SEC Fast blink

Is it posible??

Please advice and if posible please provide me with a sample code.

Thank you
Regards,
Eugene


Hi io_82:

yes, you can blink 3 led at the same time ... but .... you have 3 solutions:

A) With a soft routine. that means that the only thing that PIC can do ( in essential ) is to generate these blinking.

B) A more acurate solution is to use 3 Timers with their interrupts, but in your case this solution is not possible because F628 doesn't have 3 Timers interrupts, it only have Timer0 interrupt.

C) Configure Timer0 interrupt for 0.25 sec interrupt and use counters for blinking ( Perhaps quite complicated but possible ).
in this case

isr_timer0
{
if (Counter = multiple of 2)
{
change state LED_A;
}
if (Counter = multiple of 4)
{
change state LED_B;
}
if (Counter = multiple of 40)
{
change state LED_A;
counter=0;
}
}

You choose ...

Best Regards;
Joan Idea
_________________
I Came. I Saw. I Won.
Joan



Joined: 29 May 2004
Posts: 41
Location: Barcelona, Spain

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

Re: Blinking LED
PostPosted: Fri Jun 25, 2004 5:16 am     Reply with quote

iou_82 wrote:
Ttelmah,

Thank for the info, I will need to put that as my second assignment.

I am working on 16f628 chip right now, and i have write a simple code to make 1(A) LED blinking and the other 1(B) ON all the time,while (A) is blinking, but when i want to make 2 LED blinking at the same time but at different blinking rate it was not archivable.

What i mean :- (A)LED to blink at 1 SEC Normal blink
(B)LED to blink at 10 SEC Slow blink
(C)LED to blink at 0.5 SEC Fast blink

Is it posible??

Please advice and if posible please provide me with a sample code.

Thank you
Regards,
Eugene

Hi io_82:

yes, you can blink 3 led at the same time ... but .... you have 3 solutions:

A) With a soft routine. that means that the only thing that PIC can do ( in essential ) is to generate these blinking.

B) A more acurate solution is to use 3 Timers with their interrupts, but in your case this solution is not possible because F628 doesn't have 3 Timers interrupts, it only have Timer0 interrupt.

C) Configure Timer0 interrupt for 0.25 sec interrupt and use counters for blinking ( Perhaps quite complicated but possible ).
in this case

isr_timer0
{

if (Counter = multiple of 2)
{
change state LED_A;
}

if (Counter = multiple of 4)
{
change state LED_B;
}

if (Counter = multiple of 40)
{
change state LED_C;
counter=0;
}
}

You choose ...

Best Regards;
Joan Idea
_________________
I Came. I Saw. I Won.
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