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.

[Help] Starting to use PICs

Status
Not open for further replies.
A

amando96

Guest
Hi, been in the world of micro controllers for little over a year, been programming only arduinos so far, but I want to start using PICs
I bought myself a PIC 16F628, I followed this tutorial to build a programmer, I have a serial port on my old XP computer.
I intend to download **broken link removed**.

Now, Are all these compatible with each other? can that PIC be programmed with that programmer, and can that programmer be used by that software?

Also, is this wiring perfectly correct just to test if it's working with code?
**broken link removed**

Also, any other things to take into consideration before attempting to burn the code?

Thanks a lot.
 
I've no experience with that PIC programmer, but I would recommend that you consider buying the PICKIT 2 (or 3) programmer (or clone - there are several versions around, some in kit form, others already made up). They are really not that expensive and they will let you program all sorts of PIC devices as your experience grows. Also it lets you debug the program through the MPLAB software as well as program the device.

Also, this will let you think about the PIC itself and you programming, not your programmer, when things go wrong (as they always do - its the "fun" part of the learning curve)!

Susan
 
The article mentioned above is very difficult to follow.
Here is a circuit diagram of a simple PIC programmer using just 12 parts:
**broken link removed**
Or you can make a USB programmer for less than $25.00
 
Neither of the serial port programmers shown in this thread will work with MPLAB. I am with Susan on this one. For $35 you can buy a picKit2 from MicrochipDirect. It also acts as an In Circuit Debugger (for testing) and a simple logic analyzer.

Collin you know that programmers using the serial port to generate VPP are a crap shoot. If you are going to suggest one how about a design with an external VPP supply. It may take a bit of effort to scrounge a 12V wall wart or other supply but it would be worth not having to mess with methods used to get 12V where not exists.
 
The picaxe software has a PIC programmer, it doesn't program only picaxes apparently, i'll try to use that too.

The other option is Winpic.

I really can't afford a pickit right now.
 
I have programmed hundreds of PIC chips with a simple programmer and not had any trouble.
I also have a USB programmer as mentioned above. You can build the simple programmer and burn an 18F2550 for the USB programmer. Even the PICkit2 constantly can't find the chip and fails to program. I don't know where the fault lies with the PICkit2.
I think my USB programmer is about 50% better than the PICkit2 and I am using it constantly now. The PICkit2 is far better than the serial-port programmer in performance and feedback. It recognises the chip for a start.
I think Microchip charge $15.00 shipping for the programmer.
 
Last edited:
I might be just delirious, but would it possible to program them with this It would be quite cool...

A USB programmer would be simpler, wouldn't need two machines to be on simultaneously.
 
Collin you need to look past your own personal experience and think about the problems other people have.

I agree that the picKit2 is not perfect but it works. None of the solutions you suggest can do ICD. As people move past using other peoples hex files and into more complex programs ICD is a real plus.
 
I successfully burned this .HEX file with the latest version of WinPic and the led is blinking :D
9745-great success.jpg

So now I'm downloading MPlab, With MPlab for what I understand will let me write my own code, and compile it to .HEX? I want to write my own code, Don't just want to use other people's codes...
 
Last edited by a moderator:
Hi, successfully burned some more codes onto the PIC, this time I only changed which pins blinked, Now I have pin RA1 blinking.

;************************************************************
; Processor: PIC16F628 at 4 MHz using internal RC oscillator
; Function: Flash a LED connected to RA2
; Hardware: Testboard K4
; Filename: 628LED.asm
; Author: Lars Petersen, oz1bxm@pobox.com
; Website: 16F628 LED flash program
; Credit: Tony Nixon's LED flasher
;************************************************************

LIST P=16F628, R=DEC ; Use the PIC16F628 and decimal system

#include "P16F628.INC" ; Include header file

__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON

CBLOCK 0x20 ; Declare variable addresses starting at 0x20
Loop1,Loop2
ENDC
;
; -----------
; INITIALIZE
; -----------
;
ORG 0x000 ; Program starts at 0x000

CLRF PORTA ; Initialize port A
CLRF PORTB ; Initialize port B

BSF STATUS,RP0 ; RAM bank 1

CLRF TRISA ; All pins port A output
CLRF TRISB ; All pins port B output

BCF STATUS,RP0 ; RAM bank 0
;
; ------------------------
; FUNCTION OF PORT A PINS
; ------------------------
;
MOVLW 7
MOVWF CMCON ; Comparators off, all pins digital I/O
;
; ----------
; MAIN LOOP
; ----------
;
Main BSF PORTA,1 ; Turn on LED connected to RA1
CALL delay
BCF PORTA,1 ; Turn off LED connected to RA1
CALL delay
GOTO Main
;
; ---------------
; DELAY 250 MSEC
; ---------------
;
delay MOVLW 250
MOVWF Loop1
Outer MOVLW 200
MOVWF Loop2
Inner NOP
NOP
DECFSZ Loop2,F
GOTO Inner ; Inner loop = 5 usec.
DECFSZ Loop1,F
GOTO Outer
RETURN

END

Now what I'm not understanding is, how do I calculate the frequency/delay of the blinking LED?

I found this calculator, but after calculating I get this What exactly do I have to replace with that code to be able to alter the delay?
 
Last edited by a moderator:
Code:
; --------------- 
; DELAY 250 MSEC 
; --------------- 
; 
delay
      MOVLW 250 
      MOVWF Loop1 
Outer
      MOVLW 200 
      MOVWF Loop2 
Inner
      NOP 
      NOP 
      DECFSZ Loop2,F 
      GOTO Inner ; Inner loop = 5 usec. 
      DECFSZ Loop1,F 
      GOTO Outer 
      RETURN
Basically, the delay loop above loads W with 250 and then transfers it to 'Loop1' register.
Next, it loads W with 200 and then transfers that to 'Loop2' register.
At the label 'Inner', 'Loop2' register is decremented by 1 and stored back in 'Loop2'. DECFSZ means 'DECrement File, Skip if Zero.
This operation takes 5 uSeconds and is started again by 'GOTO Inner' at which point 'Loop2' register now contains 199.
200 loops of 'Inner' will take 200 X 5 uSeconds = 1 mSecond.
Once the 'Inner' loop register 'Loop2' reaches zero (after 1 mSecond), 'GOTO Inner' is skipped.
The routine then decrements register 'Loop1' by 1 and stores it back in 'Loop1'. 'Loop1' register now contains 249. (249 mSeconds to go...)
Next, the delay loop then gets directed to the 'Outer' loop again, by 'GOTO Outer'.
The 'Outer' loop register (Loop2) was previously at zero, but is now reloaded with 200 to start the whole process again.

So......now you know the inner loop takes 5 uSecs and 200 X 5 = 1 mSecond, you can quickly tailor the outer loop to provide from 1 mSec to 255 mSecs just by editing the 'MOVLW 250'

If you need to provide a longer delay than 250 mSecs, you can simply call the delay routine more than once.

Say you need a 400 mSec delay, you would change the initial 'MOVLW 250' in the delay loop, to 'MOVLW 200' and call the routine twice:

Code:
Main
      BSF PORTA,1 ; Turn on LED connected to RA1
      CALL delay
      CALL delay  
      BCF PORTA,1 ; Turn off LED connected to RA1
      CALL delay
      CALL delay  
      GOTO Main

Frequency/delays....
The original example you posted above (post #10) flashes the LED at 2Hz. (twice per second)
That is because the LED is switched on, kept on for 250 mSec, switched off and kept off for 250 mSec = 500 mSec = 0.5 Seconds = 2 Hz.
If you call the original delay loop twice as in my example above, the LED will flash more slowly at 1Hz.
That is because the LED is switched on, kept on for 250 mSec, kept on for another 250 mSec, switched off and kept off for 250 mSec, kept off for another 250 mSec = 1000 mSec = 1 Second = 1 Hz.

HTH.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top