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

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

Reply to
ssylee
Loading thread data ...

On a sunny day (Sun, 09 Sep 2007 03:15:09 -0000) it happened ssylee wrote in :

Yes, write in ASM :-)

Reply to
Jan Panteltje

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

Reply to
Anthony Fremont

Yuck.

Code an 8051 in ASM.

Reply to
MooseFET

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:

formatting link

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

Hope this helps.

Good luck!

Tom

#include

#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); } }

Reply to
Tom2000

Try the HiTech PIC-C compiler, the free version supports the 16F627A:

formatting link
Follow the example programs supplied.

Dave.

Reply to
David L. Jones

Hi Tom,

I have ended up modifying your code slightly in the header file to be included

formatting link
when I tried to compile the code using sdcc. Apparently SDCC tried to link it with 18F458, which is wrong, as shown in
formatting link
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

Reply to
ssylee

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

Reply to
Tom2000

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.