pic programming

Thread Starter

chrissyp

Joined Aug 25, 2008
82
I am a complete newbie at pic programming . I have been given a Picstart plus programmer and some 16F819 chips. can anyone point me in the right direction of any tutorials ,or can I follow the hand book that came with it because this tutorial refers to the 16F628 chip.Are they compatable .Sorry for being so thick but this is my first attempt into the digital world ,analog i'm fine.
 

Markd77

Joined Sep 7, 2009
2,806
There are some differences but the below should get you started. It sets some of the important registers and outputs a "1" on PortA, 2

Rich (BB code):
;**********************************************************************
;   This file is a basic code template for assembly code generation   *
;   on the PIC16F819. 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: P16F819.INC                                      *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:                                                           *
;                                                                     *
;**********************************************************************

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

    errorlevel  -302              ; suppress message 302 from list file

    __CONFIG   _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _DEBUG_OFF & _LVP_ON & _BODEN_OFF & _MCLR_ON & _WDT_OFF & _PWRTE_ON & _INTRC_IO 

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




;***** VARIABLE DEFINITIONS
w_temp        EQU     0x7E        ; variable used for context saving 
status_temp   EQU     0x7F        ; variable used for context saving


bank0      macro      ; Macro bank0
      bcf STATUS, RP0     ; Reset RP0 bit = Bank0
      endm     ; End of macro
             
bank1     macro     ; Macro bank1
      bsf STATUS, RP0     ; Set RP0 bit = Bank1
      endm     ; End of macro


    cblock 0x20
    
    

    endc

    cblock 0x70        ;access all areas

    endc



;**********************************************************************
    ORG     0x000             ; processor reset vector
    goto    init              ; 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



endint
    bcf INTCON, TMR0IF            ;clear timer0 interupt flag
;end ISR
    movf    status_temp,w     ; retrieve copy of STATUS register
    movwf    STATUS            ; restore pre-isr STATUS register contents
    swapf   w_temp,f
    swapf   w_temp,w          ; restore pre-isr W register contents
    retfie                    ; return from interrupt


init

    CLRF PORTA ; Initialize PORTA by
    ; clearing output
    ; data latches
    bank1
    MOVLW 0x06 ; Configure all pins
    MOVWF ADCON1 ; as digital inputs
    MOVLW b'00000011' 
    MOVWF TRISA ; Set RA<1:0> as inputs others out
    CLRWDT
    movlw b'00000100'
    movwf OPTION_REG        ;timer0 prescaler 32
    movlw b'0110000'
    movwf OSCCON            ;4MHz internal clock
    bank0
    clrf INTCON
    movlw b'00000100'
    movwf PORTA




main




    goto main



; initialize eeprom locations

    ORG    0x2100
;    DE    0x00, 0x01, 0x02, 0x03


    END                       ; directive 'end of program'
 

Harrington

Joined Dec 19, 2009
85
Hi

Here is a set of notes and small tutorial + simulator which you can start with Its based around the PIC16C84 series

Yes I know now out of date but never the less a good place to start as you can cross code 16F84A or what ever the replacement is for this is now

The notes are very basic in that they give you some short examples of programs coupled with small few exorcises and obviously a simulator which indicates how the registers work the SFR , status registers, Ports , the Instruction register and program counter , general purpose registers

You can also use the Pins button at the top which will enable you to set pins either high or low

It is a very good place to start off and was originally written by US Navel academy

It does have a few errors

I wouldn't let that concern you too much to start with

It functions and it works quite well for the purpose of introducing people to PIC programming from a novice stage

Its also free !!

Another useful tool which could prove to be very handy for you is the Pic Timer calculator which I've only just found the other day this can be downloaded from this address

http://users.picbasic.org/projects/PicTmrCalc/PicTimerCal.htm

I hope this proves as beneficial to you as it has done to me

See attached Best of luck with this and stick with it doe sent take to long to learn the essentials so that you can move on to better adaptions for the PIC

Remember Algorithms first, flow charts showing your program flow and then code

Always helps in the long run


Mark
 

Attachments

Thread Starter

chrissyp

Joined Aug 25, 2008
82
Hi Mark
thanks for the info and simulator link.I will study them and start some practice exercises .I will be patiant ,iv'e stuck with analog electronics for the last 15 years ,thought it was time to bring myself into the 21st century and learn digital.
Chris :)
 
Top