View previous topic :: View next topic |
Author |
Message |
harrison_c
Joined: 03 Nov 2006 Posts: 16
|
Please help me????? |
Posted: Tue Mar 06, 2007 11:05 pm |
|
|
Hi, I am a beginner for c program and PIC. I really want to learn PIC and I don't mind to spend time and effort on it, but I have no idea how and where to start learning it. Actually, I bought a book called, Embedded C Programming and the Microchip PIC by Barnett Cox & O'Cull. I also bought a development tools from Mikroelektronika - EasyPIC 4. When I got those two stuff, I was so excited.....
But after few experiments (examples from the tools) I tried to do, I really feel frustrated.
I have no idea what do the commands do like,
void interrupt() {
if (PIR1 & TMR2IF) {
i++ ;
PIR1 &= ~(1<<TMR2IF);
}
PORTB = 0xFF;
TRISB = 0;
PORTD = 0x00;
TRISD = 0;
T2CON = 0xFF;
TMR2 = 0;
PIE1 |= (1 << TMR2IE);
INTCON = 0xC0;
There is no enough explanation. Can you guys please please give me some comments on that? And actually, I like this online http://mikroe.com/en/books/picbook/0_Uvod.htmbook, but unfortunately,
it uses Basic instead of C. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
harrison_c
Joined: 03 Nov 2006 Posts: 16
|
No explanation |
Posted: Tue Mar 06, 2007 11:54 pm |
|
|
Thank you so much!
Yes, I am looking for something like that, http://www.ccsinfo.com/content.php?page=compspecific
but how come there is no explanation again!!!
I have another question....I am really wondering how you guys got started when you guys were beginner????? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Mar 07, 2007 10:04 am |
|
|
Download any PIC datasheet from Microchip, for example the PIC16F88
http://ww1.microchip.com/downloads/en/DeviceDoc/30487c.pdf
Reading the Chapter 15 you will find the explanation of all this "strange" words.
if (PIR1 & TMR2IF)
PIR1 = PERIPHERAL INTERRUPT REGISTER
TMR2IF = TIMER2 INTERRUPT FLAG
Quote: |
I have another question....I am really wondering how you guys got started when you guys were beginner?????
|
This is a nice question that surely has multiples and complex answer.
I propose you to open a new (off topic) thread with this question, it will be interesting
to know the folks answers.
Humberto |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Mar 07, 2007 12:37 pm |
|
|
Quote: | I have no idea what do the commands do like,
void interrupt() {
if (PIR1 & TMR2IF) {
i++ ;
PIR1 &= ~(1<<TMR2IF);
}
PORTB = 0xFF;
TRISB = 0;
PORTD = 0x00;
TRISD = 0;
T2CON = 0xFF;
TMR2 = 0;
PIE1 |= (1 << TMR2IE);
INTCON = 0xC0;
|
void interrupt() will usually be a routine that is executed when an interrupt has happened, ie. reception of a character on the serial port or a signal on a pin that is tied to some hardware, inside of the PIC, that indicates that it needs to be taken care of right now, something like that. The syntax #int_TIMER1, #int_RDA or #int_AD will always be placed on the line _before_ the routine. This tells the compiler that this is the routine to execute when Timer1's interrupt is flagged or the Receved Data Available interrupt tells us that there is something coming in on the serial port and so forth.
Terms like INTCON, T2CON or PIE1 are physical locations, within the PIC, that are a byte(8 bits) at specific locations. Somewhere at the beginning of the code there would have been declarations something like:
#byte T2CON = 0x12
#byte ADCON0 = 0x1F
These are registers that you can access (read or write) during the execution of your program. If you look up a spec. sheet on a PIC you will see these terms thoughout the document. Individual bits can be read or manipulated to control different parts of the PIC. The evaluation: if(PIR1 & TMR2IF) look at two bits, that have been defined earlier in the code, if they are both set to a '1' then the if() code is entered and excecuted. If either one of them were set to '0' then it would have skipped that code.
I would suggest you look at some _very_ simple code and try to get an understanding of what's going on before you try to do anything complex. It took me several days(or was it weeks) before I had a grasp of how things worked with this particular compiler.
Good luck and I hope you don't have a LCD screen because CRT's can handle the head banging better.
Ronald |
|
|
|