Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] [moved] Problem with programming PIC Microcontrollers!

Status
Not open for further replies.

Tranx

Newbie level 3
Joined
Sep 2, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
24
I am new to Micro-controller programming.I have some lessons on PICs which i follow,but they are all designed for programming using a simple JDM programmer.Lesson codes are in assembly language. Here's a code for PIC16F84A ...
Code:
*****Set up the Constants*****
STATUS equ 03h
TRISA equ 85h
PORTA equ 05h
CounterL equ 0Dh
CounterH equ 0Eh
;*****Set up the port*****
bsf STATUS,5
bcf TRISA,0
bcf STATUS,5
;*****Turn the LED on*****
Start bsf PORTA,0
;*****Delay loop1*****
Loop1 decfsz CounterL,1
goto Loop1
decfsz CounterH,1
goto Loop1
;*****Turn the LED OFF*****
bcf PORTA,0
;*****Delay loop2*****
Loop2 decfsz CounterL,1
goto Loop2
decfsz CounterH,1
goto Loop2
goto Start
end
It's just supposed to blink an led. I've set configuration bits in MPLAB IDE as oscillator to be XT as i'm using a 4 MHz crystal and successfully built the HEX file.
1. The first problem is the LED doesn't blink in regular intervals all the time. It randomly changes the blinking interval.

2. Here's a another problem. I got two uC s . PIC16F84A and PIC16F877A. The picpgm software identifies the pic16f84a but not the other one. In winpic800 it says "Unknown device " for the PIC16F877A but it also identifies the PIC16F84A.

If you guys can help me out with the problems, i would be very grateful.
Thanks!
 

The JDM programmer is notoriously unreliable. In itself it isn't too bad but it relies greatly on the capability of the port driving it, you might get completely different results using a different computer. It's far better to use something like a Pickit2 or Pickit3, even their clones will be more reliable than JDM designs.

If you are using MPLAB, please use the tools it provides. At the moment your code is difficult to follow and contains lines which are not necessary. This is your code re-written using the 16F84A template and MPLAB macros. It compiles without errors in MPLAB version 8.92

Code:
;**********************************************************************
;   This file is a basic code template for assembly code generation   *
;   on the PIC16F84A. This file contains the basic code               *
;   building blocks to build upon.                                    *  
;                                                                     *
;   Refer to the MPASM User's Guide for additional information on     *
;   features of the assembler (Document DS33014).                     *
;                                                                     *
;   Refer to the respective PIC data sheet for additional             *
;   information on the instruction set.                               *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Filename:	    xxx.asm                                           *
;    Date:                                                            *
;    File Version:                                                    *
;                                                                     *
;    Author:                                                          *
;    Company:                                                         *
;                                                                     * 
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files Required: P16F84A.INC                                      *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:                                                           *
;                                                                     *
;**********************************************************************


	list      p=16F84A            ; list directive to define processor
	#include <p16F84A.inc>        ; processor specific variable definitions

	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

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




;***** VARIABLE DEFINITIONS
w_temp        EQU     0x0C        ; variable used for context saving 
status_temp   EQU     0x0D        ; variable used for context saving

;*****Set up the Constants*****
	cblock 0x0D
CounterL 
CounterH
	endc

;********************************************************************** 
    ORG     0x000             ; processor reset vector
    goto    main              ; go to beginning of program

    ORG     0x004             ; interrupt vector location
    movwf   w_temp            ; save off current W register contents
    movf	STATUS,w          ; move status register into W register
    movwf	status_temp       ; save off contents of STATUS register

; isr code can go here or be located as a call subroutine elsewhere

    movf    status_temp,w     ; retrieve copy of STATUS register
    movwf	STATUS            ; restore pre-isr STATUS register contents    
    swapf   w_temp,
    swapf   w_temp,w          ; restore pre-isr W register contents
    retfie                    ; return from interrupt
;********************************************************************** 

main
;*****Set up the port*****
    banksel TRISA
    bcf TRISA,0

;*****Turn the LED on*****
Start
    bsf PORTA,0

;*****Delay loop1*****
Loop1
    decfsz CounterL,f
    goto Loop1
    decfsz CounterH,f
    goto Loop1
		
;*****Turn the LED OFF*****
	bcf PORTA,0
		
;*****Delay loop2*****
Loop2
    decfsz CounterL,f
    goto Loop2
    decfsz CounterH,f
    goto Loop2
    goto Start
		
    end

Brian.
 

Thanks Brian,
I know JDM programmers are obsolete now. I should try to build a pk2 clone.
Yeah, the code was written for some old version of the MPLAB.

Thanks again for the reply and for your time.
 

You might find it cheaper to buy a Pickit2 or 3 instead of building your own. The designs of the 'real' ones are available on Microchip's web site but many of the clones are not fully compatible and often do not have the programmable VPP facility or on-board RAM.

Brian.
 

Yeah, i read that too. Building a clone costs the amount as same as the price of the original. So i think its wise to buy an original one rather than hassling to build a clone.
Yeah, most of the clones doesn't have the ability regulate voltage as well as the vpp toggle.

Thanks Brian
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top