Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Lighting an LED and help with datasheet (PIC18F45K20)

Status
Not open for further replies.

Mike.B

New Member
Hello everyone !

I have just bought a PICKIT3 and I have to admit I am getting confused !
The datasheet is really heavy and I don't really know how to start.
My PIC is a PIC18F45K20 and here is the datasheet : **broken link removed**

I would like to light an LED.
I can see I have 7 LED but I don't know how to switch on.
I have looked for a schematic where the LED were but I didn't find.

Can you help me to light an LED and understand the datasheet ?

Thanks
 
Hi,

Yes the Microchip datasheets are not very friendly for the beginner or even the advanced user at times.

If you see the Sticky post at the top of this forum it has links to various Starter tutorials which begin with the proverbial flashing led, though most of them refer to the 16F series you should be able to apply the code to that 18F chip with a little modification.

You also need to mention what programming language you are using so we can perhaps give you some starter code.
 
Assuming it's a Starter Kit from MicroChip (Pickit and a demo board), then it comes complete with example programs to use the demo board provided. So start with those, and modify them to suit your needs.
 
Hi all !

Thanks for your replies, I appreciated ! :)

Care to tell us which board you have....
My bad...:banghead:
I have bought a PICkit 3 Debug Express (DV164131)
This kit includes the 44-pin demo board with a PIC18F45K20 microcontroller and a USB cable.
It is the first product on this list : https://www.microchipdirect.com/productsearch.aspx?Keywords=DV164131
Here is a video :
I use MPLAB 8.92 and CSS.

Yes the Microchip datasheets are not very friendly for the beginner or even the advanced user at times.
Yes, that's exactly my feeling. I Hope I could manage to understand.
Alright, I am going to check the Sticky Post. :)

then it comes complete with example programs
I didn't find example programs unfortunately.
In the beginning, I could see blinking LED (actually, there was already a program embedded in the PIC).
I couldn't see where the code was and I decided to erase the memory and program my own code.

Thanks for your hep !
 
There is a lack of CSS programmers here on ETO... However! There is a free version of XC8 that you can do an awful lot with...

I use XC8, mplabc18 and Hi-tech tool suites.... I also have acquired the MikroC tool suite... So I can help you with your programs but not specific CSS issues..
 
Blinking an LED in C for any microcontroller is simple. Assuming those LED's are on PORTD and say you wanna blink the LED on RD0 -

Code:
#include <xc.h>

/*
  * CONFIG1H @ 0x300001
  *
  * Internal oscillator with I/O function on RA6 & RA7
  */

#pragma config FOSC = INTIO67

/*
  * CONFIG2L @ 0x300002
  *
  * Brown Out Reset disabled
  * Power Up Timer enabled
  */

#pragma config BOREN = OFF, PWRT = ON        

/*
  * CONFIG2H @ 0x300003
  *
  * Watchdog Timer disabled
  */

#pragma config WDTEN = OFF

/*
  * CONFIG4L @ 0x300006
  *
  * Low Voltage Programming disabled
  * Reset on stack over/underflow disabled
  */

#pragma config LVP = OFF, STVREN = OFF

#define _XTAL_FREQ 16000000

void main(void)
{
    OSCCON = 0b01110000;                       //16MHz Fosc
    PORTD = 0x00;                                      //clear PORTD latch
    TRISD = TRISD & 0b11111110;             //RD0 output drivers enabled
  
  while(1)
  {
        PORTD = PORTD ^ 0b00000001;             //toggle LED

          /*
           * 1/2 second flash rate
           */

         for(char i = 0; i < 10; i++)
         {
               __delay_ms(49);
         }
  }
}
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top