Maker Pro
Maker Pro

getting started on C programming on PIC16F628A, PIC16F690, OR PIC18F2620

S

ssylee

Jan 1, 1970
0
I'm trying to get started with C programming on either one of the PIC
microcontrollers in MPLAB IDE using C18 compiler (or any other C
compiler that Microchip makes), however, I'm having some trouble
drafting a source code that has, for example, LEDs flashing or display
a "Hello World" message through printf() and in such fashion that I
can see it on a host computer. Does anyone know any good resources in
those tasks that could help me get started?

Stanley
 
J

Jan Panteltje

Jan 1, 1970
0
I'm trying to get started with C programming on either one of the PIC
microcontrollers in MPLAB IDE using C18 compiler (or any other C
compiler that Microchip makes), however, I'm having some trouble
drafting a source code that has, for example, LEDs flashing or display
a "Hello World" message through printf() and in such fashion that I
can see it on a host computer. Does anyone know any good resources in
those tasks that could help me get started?

Stanley

Yes, write in ASM :)
 
A

Anthony Fremont

Jan 1, 1970
0
ssylee said:
I'm trying to get started with C programming on either one of the PIC
microcontrollers in MPLAB IDE using C18 compiler (or any other C
compiler that Microchip makes), however, I'm having some trouble
drafting a source code that has, for example, LEDs flashing or display
a "Hello World" message through printf() and in such fashion that I
can see it on a host computer. Does anyone know any good resources in
those tasks that could help me get started?

Microchip's C compiler only works on 18F type PICs, not the 16F line.
Perhaps you should start with assembler.
 
T

Tom2000

Jan 1, 1970
0
I'm trying to get started with C programming on either one of the PIC
microcontrollers in MPLAB IDE using C18 compiler (or any other C
compiler that Microchip makes), however, I'm having some trouble
drafting a source code that has, for example, LEDs flashing or display
a "Hello World" message through printf() and in such fashion that I
can see it on a host computer. Does anyone know any good resources in
those tasks that could help me get started?

Stanley

Hello, Stanley,

For the C18 compiler, start with the C18 Getting Started manual.
Then, download and study "Essential C." Then hit the C18 User's
Guide. Finally, study the data sheet for your processor and any
Microship supplemental information, such as the 18F Configuration
Settings Addendum.

Essential C link:

http://cslibrary.stanford.edu/101/

Below is a LED "Hello World" routine for your 2620.

Hope this helps.

Good luck!

Tom


#include <p18f2620.h>

#pragma config WDT = OFF, OSC = INTIO67 // WDT off, int RC osc,
// RA6 & RA7 as I/O
// See 18F Config Addendum,
// p. 116

void delay(int dly)
{
while(--dly > 0)
dly = dly;
}

void main()
{
OSCCON = 0x72; // Int osc at 8 MHz
// See p. 30 of 18F2620 data sheet

ADCON1 = 0x0f; // All ports digital
// See 18F2620 data sheet, p. 94
ADCON2 = 0x05; // Set AN10-AN12 on PORTB as digital I/O
// See p. 224 of 18F2620 data sheet

TRISB = 0; // All PORTB lines as outputs

while(1)
{
PORTB = 0x55; // Flash 8 LEDs on PORTB in checkerboard pattern
delay(6500); // at approx 5 Hz
PORTB = 0xAA;
delay(6500);
}
}
 
D

David L. Jones

Jan 1, 1970
0
I'm trying to get started with C programming on either one of the PIC
microcontrollers in MPLAB IDE using C18 compiler (or any other C
compiler that Microchip makes), however, I'm having some trouble
drafting a source code that has, for example, LEDs flashing or display
a "Hello World" message through printf() and in such fashion that I
can see it on a host computer. Does anyone know any good resources in
those tasks that could help me get started?

Stanley

Try the HiTech PIC-C compiler, the free version supports the 16F627A:
http://www.hitech.com.au/products/compilers/PICClite.php
Follow the example programs supplied.

Dave.
 
S

ssylee

Jan 1, 1970
0
Hello, Stanley,

For the C18 compiler, start with the C18 Getting Started manual.
Then, download and study "Essential C." Then hit the C18 User's
Guide. Finally, study the data sheet for your processor and any
Microship supplemental information, such as the 18F Configuration
Settings Addendum.

Essential C link:

http://cslibrary.stanford.edu/101/

Below is a LED "Hello World" routine for your 2620.

Hope this helps.

Good luck!

Tom

#include <p18f2620.h>

#pragma config WDT = OFF, OSC = INTIO67 // WDT off, int RC osc,
// RA6 & RA7 as I/O
// See 18F Config Addendum,
// p. 116

void delay(int dly)
{
while(--dly > 0)
dly = dly;

}

void main()
{
OSCCON = 0x72; // Int osc at 8 MHz
// See p. 30 of 18F2620 data sheet

ADCON1 = 0x0f; // All ports digital
// See 18F2620 data sheet, p. 94
ADCON2 = 0x05; // Set AN10-AN12 on PORTB as digital I/O
// See p. 224 of 18F2620 data sheet

TRISB = 0; // All PORTB lines as outputs

while(1)
{
PORTB = 0x55; // Flash 8 LEDs on PORTB in checkerboard pattern
delay(6500); // at approx 5 Hz
PORTB = 0xAA;
delay(6500);
}

}

Hi Tom,

I have ended up modifying your code slightly in the header file to be
included (http://www.pastebin.ca/691457) when I tried to compile the
code using sdcc. Apparently SDCC tried to link it with 18F458, which
is wrong, as shown in http://www.pastebin.ca/691459. I have installed
the latest snapshot of gputils on its sourceforge site. I have
downloaded the latest snapshot of SDCC and overwritten "include" and
"lib" folder contents with those in the snapshot in /usr/shared/sdcc/.
Does anyone have any ideas on how to deal with the fact that the
compiler is linking with the wrong MCU?

Stanley
 
T

Tom2000

Jan 1, 1970
0
Hi Tom,

I have ended up modifying your code slightly in the header file to be
included (http://www.pastebin.ca/691457) when I tried to compile the
code using sdcc. Apparently SDCC tried to link it with 18F458, which
is wrong, as shown in http://www.pastebin.ca/691459. I have installed
the latest snapshot of gputils on its sourceforge site. I have
downloaded the latest snapshot of SDCC and overwritten "include" and
"lib" folder contents with those in the snapshot in /usr/shared/sdcc/.
Does anyone have any ideas on how to deal with the fact that the
compiler is linking with the wrong MCU?

Stanley

That's not a surprise. Each compiler, it seems, has its own
particular syntax when dealing with the low level PIC stuff. (For
instance, I normally use PCH, which uses radically different syntax
for PIC-specific stuff. As an example, PCH uses #fuses instead of
C18's #pragma config, and uses different syntax within the statement.
It looks like SDCC has its own syntax for this, and also for the
low-level register stuff. Check your SDCC reference manual and the
18f2620 header file included with your compiler.)

You'll have to either compile my example in MCC18 or learn SDCC's
specific syntax if you want to convert the routine to SDCC.

If SDCC is the compiler you're going to be using, that's the one you
shoud spend your time learning.

Linking to the wrong processor is a different story. My guess (with
nothing to go on) is that it's an IDE issue, having to do with the way
you set up your project.

I don't use SDCC, so I'm afraid that I can't provide any specific
information for you.

Good luck!

Tom
 
Top