Re: getting started on C programming on PIC16F628A, PIC16F690, OR PIC18F2620
- From: ssylee <stanigator@xxxxxxxxx>
- Date: Tue, 11 Sep 2007 06:42:17 -0000
On Sep 10, 2:07 am, Tom2000 <ab...@xxxxxxxxxxxxx> wrote:
On Sun, 09 Sep 2007 03:15:09 -0000, ssylee <sta***...@xxxxxxxxx>
wrote:
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 *** 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 ***
ADCON1 = 0x0f; // All ports digital
// See 18F2620 data ***, p. 94
ADCON2 = 0x05; // Set AN10-AN12 on PORTB as digital I/O
// See p. 224 of 18F2620 data ***
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
.
- Follow-Ups:
- References:
- Prev by Date: Auto polarity changer
- Next by Date: Re: Recommended USB oscilloscopes?
- Previous by thread: Re: getting started on C programming on PIC16F628A, PIC16F690, OR PIC18F2620
- Next by thread: Re: getting started on C programming on PIC16F628A, PIC16F690, OR PIC18F2620
- Index(es):