1. 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.
    Dismiss Notice

Programming all PIC chips with PICkit 2

Discussion in 'Microcontrollers' started by richacm, Jun 5, 2008.

  1. karenhornby

    karenhornby New Member

    Joined:
    Feb 3, 2008
    Messages:
    101
    Likes:
    2
    Thanks your a star :) I've been trying to find that info out for ages now reading all sorts but nothing actually says it can power the pic directly with nothing else needed!
    BTW hope you didn't mind me modding your original pic, but I did leave your name on it so people knew where it came from
     
    Last edited: Jun 19, 2008
  2. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    The power supply came from HVW Technologies. I have three of them. Excellent product.

    The heat sink came from the junk pile. No idea what I ripped apart to get it, but I had stacks of old printers, so probably that's what it came off. It's not really necessary for that power supply. I just wanted it to run cool, so... :p
     
    • Like Like x 1
  3. BaCaRdi

    BaCaRdi Member

    Joined:
    Apr 7, 2008
    Messages:
    233
    Likes:
    2
    Location:
    Hoboken / NYC
    Hey I like that breadboard Power supply! I think I will get one, or two.

    I find I make sure I have two of everything, since I usually blow-up or use parts for something else. Always helps to have a backup...hehe

    Cheers for the links and info,

    -BaC
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Thunderchild

    Thunderchild New Member

    Joined:
    Jul 3, 2005
    Messages:
    2,294
    Likes:
    9
    Location:
    UK

    the pickit2 starters guide has the pinot of the header in it
     
  6. Thunderchild

    Thunderchild New Member

    Joined:
    Jul 3, 2005
    Messages:
    2,294
    Likes:
    9
    Location:
    UK
    just use a 5 V wall wart from an old phone charger or something and put header/jumper teminals on the end that have 2.54 mm spacing so it plugs straight into the breadboard
     
  7. richacm

    richacm New Member

    Joined:
    May 19, 2008
    Messages:
    148
    Likes:
    0
    Location:
    Hamilton, New Zealand
    Thanks - I just found that the other day when I was sorting out the ICP for my circuit.
     
  8. iyke20024

    iyke20024 New Member

    Joined:
    Aug 7, 2008
    Messages:
    14
    Likes:
    0
    source code for PIC16F887

    Hi, can some experience help me with this very problem i am facing. i am trying to write a source code to generate a 200ms pulse at various interval, let say.. 5s, 50, 100..... using PIC16F887. I used the AD converter becos i wanted to use a rotary switch to control the frequency or speed.

    i have only few days to make this work. i need to used this switch to drive a relay.

    Can someone help me look at this code and the errors in it or better still help me debug or edit it. i have tried wit could not build. at an instance it did build when i started the program with

    org 0x2100. but the Led did not light. i wanted to use the led to monitor the pulse time.

    I tried to debug the code and i always recieve error

    CORE-E0002: Stack under flow error occurred from instruction at 0x000005

    Thank you





    Code (text):
    l   istp=16f887 ; list directive to define processor
        #include    <p16f887.inc>   ; processor specific variable definitions


    ; '__CONFIG' directive is used to embed configuration data within .asm file.
    ; The labels following the directive are located in the respective .inc file.
    ; See respective data sheet for additional information on configuration word.

        __CONFIG    _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
        __CONFIG    _CONFIG2, _WRT_OFF & _BOR21V

    ; variable decleration

         cblock 0x00
    Delay1           ; Assign an address to label Delay1
    Delay2
    Display          ; define a variable to hold the diplay
    timer1      
    incf_count

    Endc
            org      0x0021     ;  Start  program  at  address  
    count   equ      0x20       ;  Counter  variable        
            nop                 ;  required for debugger

     ;  Initialize  PORT  D  to  be  all  outputs and PORT A all inputs.

    Start
            BANKSEL PORTD
            CLRF    PORTD
            BANKSEL TRISD        
            movwf   TRISA          ;  Make PortA all input
            clrf    TRISD          ;  Set PORTD for output        
            clrf    PORTD          ;  write 0s to PORTD
            clrf    count          ;  Initialize  count  to  0.

    ;  Setup  timer  1

            bcf     T1CON,TMR1ON        ;  Turn  Timer  1  off.
            bsf     T1CON,T1CKPS1       ;  Set  prescaler  for  divide bsf T1CON,T1CKPS0 by  8.                        
            bcf     T1CON,T1OSCEN       ;  Disable  the  RC  oscillator.
            bcf     T1CON,TMR1CS        ;  Use  the  Fosc/4  source.
            clrf    TMR1L               ;  Start  timer  at  0000h
            clrf    TMR1H               ;  clear the pre-scalar counter
            bsf     T1CON,TMR1ON        ;  Start  the  time

    Time1   btfss   PIR1,TMR1IF              ;  Did  timer  overflow?
           
    ;  Timer  overflowed,  increment  counter  and  display

            bcf    PIR1,0     ;  Clear  the  flag
            incf   count,F    ;  Bump  the  counter
            movf   count,W    ;  Get  the  count
            movwf  PORTD      ;  Send  to  Port  D.
            bcf    T1CON,0    ;  Turn  the  timer  off.
            movlw  80h        ;  Start  timer  at  80h
            movwf  TMR1H
            clrf   TMR1L
            bsf    T1CON,0    ;  Turn  the  timer  on.
     
            movlw     0xFF
            movlw     0x00           ; Left Justified, Vdd-Vss referenced
            movwf     ADCON1
            BANKSEL   TRISA        
            movlw     0xFF           ; we want all Port A pins Analog
            movwf     ANSEL
            bcf       STATUS,RP0     ; back to Register Bank 0    
            movlw     0x41
            movwf     ADCON0         ; configure A2D for Fosc/8, Channel 0 (RA0), and turn on the A2D module

            nop                      ; wait 5uS for A2D amp to settle and capacitor to charge.
            nop                      ; wait 1uS
            nop                      ; wait 1uS
            nop                      ; wait 1uS
            nop                      ; wait 1uS
            bsf       ADCON0,GO_DONE ; start conversion
            btfss     ADCON0,GO_DONE ; this bit will change to zero when the conversion is complete
            goto      $-1

            movf      ADRESH, W      ; Copy the display to the LEDs
            movwf     PORTD

            goto      timer1          

            End               ; directive 'end of program'
     
  9. mvs sarma

    mvs sarma Well-Known Member

    Joined:
    Oct 29, 2006
    Messages:
    3,512
    Likes:
    76
    Location:
    Hyderabad, India.
    @iyke20024,
    Please try the following code. I have now seen on MPLAB simulator, that the bit 0 of PORTD changes accordingly. Also a zip file containing the .asm is attached for ready use to finalise to your needs.


    Code (text):
     
            list p=16f887  ; list directive to define processor
            #include  <p16f887.inc>  ; processor specific variable definitions
     
     
    ; '__CONFIG' directive is used to embed configuration data within .asm file.
    ; The labels following the directive are located in the respective .inc file.
    ; See respective data sheet for additional information on configuration word.
     
        __CONFIG    _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
        __CONFIG    _CONFIG2, _WRT_OFF & _BOR21V
     
        errorlevel -302
    ; variable decleration
     
         cblock 0x00
    Delay1           ; Assign an address to label Delay1
    Delay2
    Display          ; define a variable to hold the diplay
    timer1      
    incf_count
     
            Endc
            org      0x0021    ;  Start  program  at  address    
    count   equ      0x20        ;  Counter  variable        
            nop          ;  required for debugger
     
     ;  Initialize  PORT  D  to  be  all  outputs and PORT A all inputs.
     
    Start
            BANKSEL PORTD
            CLRF    PORTD
            BANKSEL TRISD        
            MOVLW   0X00
            MOVWF   TRISD          ;  Set PORTD for output        
            BANKSEL PORTA
            MOVLW   0XFF
            movwf   TRISA           ;  Make PortA all input
            MOVLW   0X00
    ;                clrf    PORTD          ;  write 0s to PORTD
            clrf    count          ;  Initialize  count  to  0.  
     
    ;  Setup  timer  1  
     
             bcf    T1CON,TMR1ON        ;  Turn  Timer  1  off.  
             bsf    T1CON,T1CKPS1       ;  Set  prescaler  for  divide bsf T1CON,T1CKPS0 by  8.                          
            bcf     T1CON,T1OSCEN       ;  Disable  the  RC  oscillator.  
            bcf     T1CON,TMR1CS        ;  Use  the  Fosc/4  source.  
            clrf    TMR1L               ;  Start  timer  at  0000h  
            clrf    TMR1H               ;  clear the pre-scalar counter
            bsf     T1CON,TMR1ON        ;  Start  the  time
     
    Time1   btfss   PIR1,TMR1IF              ;  Did  timer  overflow?  
             
    ;  Timer  overflowed,  increment  counter  and  display  
     
            bcf    PIR1,0     ;  Clear  the  flag  
            incf   count,F    ;  Bump  the  counter  
            movf   count,W    ;  Get  the  count  
            movwf  PORTD      ;  Send  to  Port  D.  
            bcf    T1CON,0    ;  Turn  the  timer  off.  
            movlw  80h        ;  Start  timer  at  80h  
            movwf  TMR1H
            clrf   TMR1L
            bsf    T1CON,0    ;  Turn  the  timer  on.  
       
            movlw     0xFF
            movlw     0x00           ; Left Justified, Vdd-Vss referenced
            movwf     ADCON1
            BANKSEL   TRISA        
            movlw     0xFF           ; we want all Port A pins Analog
            movwf     ANSEL
            bcf       STATUS,RP0     ; back to Register Bank 0    
            movlw     0x41
            movwf     ADCON0         ; configure A2D for Fosc/8, Channel 0 (RA0), and turn on the A2D module
     
            nop                      ; wait 5uS for A2D amp to settle and capacitor to charge.
            nop                      ; wait 1uS
            nop                      ; wait 1uS
            nop                      ; wait 1uS  
            nop                      ; wait 1uS
            bsf       ADCON0,GO_DONE ; start conversion
            btfss     ADCON0,GO_DONE ; this bit will change to zero when the conversion is complete
            goto      $-1
     
            movf      ADRESH, W      ; Copy the display to the LEDs
           BANKSEL  PORTD
            movwf     PORTD
     
            goto      timer1          
     
            End               ; directive 'end of program'
     
     
     

    Attached Files:

    Last edited: Aug 7, 2008
  10. iyke20024

    iyke20024 New Member

    Joined:
    Aug 7, 2008
    Messages:
    14
    Likes:
    0
    Hi serma,

    The problem was because i used a linker file.

    check the code below. It built, but did not output to PORTD. the led did not blink.

    See, i am not too Good with this stuff, but i am learning everyday.

    you can look at the code and try to debug it and see if there is something wrong.

    Does the precedence mater. i.e setting up the timer first before converting from analogue to digital?

    Code (text):
        list    p=16f887    ; list directive to define processor
            #include <p16f887.inc>  ; processor specific variable definitions
                 

    ; '__CONFIG' directive is used to embed configuration data within .asm file.  
    ; The labels following the directive are located in the respective .inc file.  
    ; See respective data sheet for additional information on configuration word.  

            __config _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
            __config _CONFIG2, _WRT_OFF & _BOR21V

                 
    ; variable decleration
            udata
    Delay1      res 1       ; Assign an address to label Delay1
    Delay2      res 1
    Display     res 1       ; define a variable to hold the diplay
    timer1      res 1
    incf_count  res 1

    count       equ 0x20        ;  Counter  variable

    Reset       code    0x0000      ;  Start  program  at  address      
            goto    main

    IRQ     code    0x0004
            retfie

            code
                        ;  Initialize  PORT  D  to  be  all  outputs and PORT A all inputs.

    main
           
            BANKSEL TRISD      
            clrf    TRISD       ;  Set PORTD for output
            BANKSEL PORTD
            clrf    PORTD       ;  write 0s to PORTD
            clrf    count       ;  Initialize  count  to  0.

    ;  Setup  timer  1  

            bcf T1CON,TMR1ON    ;  Turn  Timer  1  off.
            bsf T1CON,T1CKPS1   ;  Set  prescaler  for  divide bsf T1CON,T1CKPS0 by  8.                        
            bcf T1CON,T1OSCEN   ;  Disable  the  RC  oscillator.
            bcf T1CON,TMR1CS    ;  Use  the  Fosc/4  source.
            clrf    TMR1L       ;  Start  timer  at  0000h
            clrf    TMR1H       ;  clear the pre-scalar counter
            bsf T1CON,TMR1ON    ;  Start  the  time

    Timer1      btfss   PIR1,TMR1IF ;  Did  timer  overflow?
                 
    ;  Timer  overflowed,  increment  counter  and  display  

            bcf PIR1,0      ;  Clear  the  flag
            incf    count,F     ;  Bump  the  counter
            movf    count,W     ;  Get  the  count
            movwf   PORTD       ;  Send  to  Port  D.
            bcf T1CON,0     ;  Turn  the  timer  off.
            movlw   80h     ;  Start  timer  at  80h
            movwf   TMR1H
            clrf    TMR1L
            bsf T1CON,0     ;  Turn  the  timer  on.
                 
            movlw   0xFF       
            movwf   ADCON1
            BANKSEL TRISA
            movlw   B'11111111'     ; Left Justified, Vdd-Vss referenced
            movwf   TRISA       ;  Make PortA all input
            movlw   0xFF        ; we want all Port A pins Analog
            movwf   ANSEL
            bcf     STATUS,RP0  ; back to Register Bank 0    
            movlw   0x41
            movwf   ADCON0      ; configure A2D for Fosc/8, Channel 0 (RA0), and turn on the A2D module

            nop         ; wait 5uS for A2D amp to settle and capacitor to charge.
            nop         ; wait 1uS
            nop         ; wait 1uS
            nop         ; wait 1uS
            nop         ; wait 1uS

            bsf     ADCON0,GO_DONE  ; start conversion
            btfss   ADCON0,GO_DONE  ; this bit will change to zero when the conversion is complete
            goto    $-1

            movf    ADRESH,W    ; Copy the display to the LEDs

            movwf   PORTD

            goto    timer1          

            end         ; directive 'end of program'
     
  11. bananasiong

    bananasiong New Member

    Joined:
    Mar 7, 2006
    Messages:
    1,893
    Likes:
    7
    Location:
    Malaysia
    Hi,
    Code (text):

        bsf T1CON,0     ;  [COLOR="Red"]bank 0, correct[/COLOR]
                 
        movlw   0xFF       
        movwf   ADCON1  ;  [COLOR="Red"]supposed to be in bank 1[/COLOR]
        BANKSEL TRISA
        movlw   B'11111111'     ; Left Justified, Vdd-Vss referenced
        movwf   TRISA       ;  Make PortA all input
        movlw   0xFF        ; we want all Port A pins Analog
        movwf   ANSEL ;  [COLOR="Red"]this is in bank 3[/COLOR]
     

    And, shouldn't this to be:
    Code (text):

        btfs[COLOR="Red"]c[/COLOR]  ADCON0,GO_DONE  ; this bit will change to zero when the conversion is complete
        goto    $-1
    you're reading the result register before the conversion ends.
     
  12. fritzrevenge

    fritzrevenge New Member

    Joined:
    May 1, 2012
    Messages:
    1
    Likes:
    0
    does it really needs pull-down resistor? every time I program a PIC18F2550 without using pulldown resistor it works fine. XD
     

Share This Page