buy hot The Fixer cool video Year One download Kasabian album nice Terminator Salvation hit cool track Jordin Sparks USA Whatever Works video download Check My Brain melodies nice video Finding Nemo nice Pop - Various Artists hit cheap DIVX Year One

digital-diy.com

Swordfish Tutorial - PICKit 2 and UART Print E-mail
( 0 Votes )
  
Saturday, 04 April 2009 08:58

Communication between you  PIC micro and PC could not be easier then with your PICKit 2. Forget the hassles of wiring up your DB9 connectors and worrying about MAX232's or DS275's. don't even worry about connecting an   LCD to get real time data from your program... This is the fast, effective and simple solution for real time debugging and user interfacing on your projects.

 

PIC20to20PICKit20220to20PC1


Ok, so I hear what you are saying - the PICKit 2 will program almost every PIC known to man kind from 12Fs/16F's/18F's/dsPIC's/24F PIC's, but how do you use it for UART/USART communication with your PC? Well start off by opening the PICKit 2 programming software, and from the Tools menu, select UART Tool...

 

PICKit20220Select20UART20Tool1


The PICKit UART tool will open, and the first thing you should do is set the baud that your using...

 

PICKit20220Select20Baud20Speed1

 

Your now set to go! One other thing before I cover a simple UART program, the "Echo On" option box enable/disables the transmitted data to be appended to the UART Tool screen, eg, if you typed "Hello World" and then clicked "Send", if enabled it would display in the UART Tool screen.

 

PICKit20220Select20Echo20off1


Let's have a look at a simple program to transmit data from your PIC to your PC;

 

Device = 18F4550
Clock = 8
Config FOSC = INTOSCIO_EC
 
// import usart module...
Include "usart.bas"
 
// setup the internal OSC for 8Mhz
OSCCON = %01110110
 
// read in characters and echo to screen...
USART.SetBaudrate(br9600)
While true
   USART.WriteByte(USART.ReadByte)
Wend

 

I am using an 18F4550 as it is my PIC of choice at the moment, and also utilising the built in 8Mhz oscillator to minimise external components. You can use any PIC micro that Swordfish supports, there are plenty of other examples with setting up other PIC's on the site.


From there, I include the USART.bas library, as it contains all of the routines to handle Hardware UART on PIC's. OSCCON = %01110110 is part of setting up the 18F4550's internal oscillator, the next important part is USART.SetBaudrate(br9600), as it tells the compiler what speed your UART will be operating at, in this case its 9600 baud.


Essentially the main program is a UART Echo routine - that is, whatever is received is then transmitted. The program will wait for ever if need be until USART.ReadByte returns something, so that USART.WriteByte can then send something.


Connecting your PIC to the PICKit 2 couldn't be easier, it is even shown on the PICKit 2 UART tool, but here it is again;

 

img3621


You do not need to connect Pin 5 of the PICKit 2 if your just using the UART tool for displaying data from the PIC, leaving you with only three wires to connect. Locating the USART pins on a PIC micro can be found in the datasheet, in either the USART section or the Pinout diagram. The USART pins are usually identified by RX and TX as shown below;

 

PICKit20220PIC20Micro20Pinout20UART1


This is extremely handy for thousands of uses, in particular, I use this method extensively as a real time display of what is happening in my program, eg, place a line of code that sends crucial program status information via UART so I can tell exactly what my program is doing, handy.

Simulation

( 3 Votes )

Comments (4)
  • Nirav J, Doshi  - What about PICKIT 3?

    Is there anything out there for PICKIT 3?

  • Nirav J, Doshi  - How about PICKIT3

    Is there anything out there for PICKIT 3? Please do a video or post links for the software for PICKIT 3.
    Thanx

  • uuu  - pic16f690 uar

    I am going to send two data from ADC to USART(async mode) to serial port of PC. Please give me a sample asm code, any baud rate will do. Thank.

  • Jon Chandler

    If this wasn't a class project that had to be done on a PIC16F690 using assembly, it would be a trivial task using a PIC18F series and Swordfish Basic.

    There are several examples in the Swordfish section. The free Swordfish SE version is more than up to this task.

Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
Security
Please input the anti-spam code that you can read in the image.
Last Updated ( Saturday, 18 April 2009 07:36 )
 

Whos Online

  • andyo
  • Jon Chandler
  • MrDEB

Forum Activity