pic programming

Discussion in 'Programmer's Corner' started by chrissyp, Jul 2, 2010.

  1. chrissyp

    Thread Starter Active Member

    Aug 25, 2008
    82
    10
    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.
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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

    Code ( (Unknown Language)):
    1. ;**********************************************************************
    2. ;   This file is a basic code template for assembly code generation   *
    3. ;   on the PIC16F819. This file contains the basic code               *
    4. ;   building blocks to build upon.                                    *
    5. ;                                                                     *
    6. ;   Refer to the MPASM User's Guide for additional information on     *
    7. ;   features of the assembler (Document DS33014).                     *
    8. ;                                                                     *
    9. ;   Refer to the respective PIC data sheet for additional             *
    10. ;   information on the instruction set.                               *
    11. ;                                                                     *
    12. ;**********************************************************************
    13. ;                                                                     *
    14. ;    Filename:        xxx.asm                                           *
    15. ;    Date:                                                            *
    16. ;    File Version:                                                    *
    17. ;                                                                     *
    18. ;    Author:                                                          *
    19. ;    Company:                                                         *
    20. ;                                                                     *
    21. ;                                                                     *
    22. ;**********************************************************************
    23. ;                                                                     *
    24. ;    Files Required: P16F819.INC                                      *
    25. ;                                                                     *
    26. ;**********************************************************************
    27. ;                                                                     *
    28. ;    Notes:                                                           *
    29. ;                                                                     *
    30. ;**********************************************************************
    31.  
    32.     list      p=16f819           ; list directive to define processor
    33.     #include <p16F819.inc>        ; processor specific variable definitions
    34.  
    35.     errorlevel  -302              ; suppress message 302 from list file
    36.  
    37.     __CONFIG   _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _DEBUG_OFF & _LVP_ON & _BODEN_OFF & _MCLR_ON & _WDT_OFF & _PWRTE_ON & _INTRC_IO
    38.  
    39. ; '__CONFIG' directive is used to embed configuration word within .asm file.
    40. ; The lables following the directive are located in the respective .inc file.
    41. ; See data sheet for additional information on configuration word settings.
    42.  
    43.  
    44.  
    45.  
    46. ;***** VARIABLE DEFINITIONS
    47. w_temp        EQU     0x7E        ; variable used for context saving
    48. status_temp   EQU     0x7F        ; variable used for context saving
    49.  
    50.  
    51. bank0      macro      ; Macro bank0
    52.       bcf STATUS, RP0     ; Reset RP0 bit = Bank0
    53.       endm     ; End of macro
    54.              
    55. bank1     macro     ; Macro bank1
    56.       bsf STATUS, RP0     ; Set RP0 bit = Bank1
    57.       endm     ; End of macro
    58.  
    59.  
    60.     cblock 0x20
    61.    
    62.    
    63.  
    64.     endc
    65.  
    66.     cblock 0x70        ;access all areas
    67.  
    68.     endc
    69.  
    70.  
    71.  
    72. ;**********************************************************************
    73.     ORG     0x000             ; processor reset vector
    74.     goto    init              ; go to beginning of program
    75.    
    76.  
    77.     ORG     0x004             ; interrupt vector location
    78.     movwf   w_temp            ; save off current W register contents
    79.     movf    STATUS,w          ; move status register into W register
    80.     movwf    status_temp       ; save off contents of STATUS register
    81. ;ISR
    82.  
    83.  
    84.  
    85. endint
    86.     bcf INTCON, TMR0IF            ;clear timer0 interupt flag
    87. ;end ISR
    88.     movf    status_temp,w     ; retrieve copy of STATUS register
    89.     movwf    STATUS            ; restore pre-isr STATUS register contents
    90.     swapf   w_temp,f
    91.     swapf   w_temp,w          ; restore pre-isr W register contents
    92.     retfie                    ; return from interrupt
    93.  
    94.  
    95. init
    96.  
    97.     CLRF PORTA ; Initialize PORTA by
    98.     ; clearing output
    99.     ; data latches
    100.     bank1
    101.     MOVLW 0x06 ; Configure all pins
    102.     MOVWF ADCON1 ; as digital inputs
    103.     MOVLW b'00000011'
    104.     MOVWF TRISA ; Set RA<1:0> as inputs others out
    105.     CLRWDT
    106.     movlw b'00000100'
    107.     movwf OPTION_REG        ;timer0 prescaler 32
    108.     movlw b'0110000'
    109.     movwf OSCCON            ;4MHz internal clock
    110.     bank0
    111.     clrf INTCON
    112.     movlw b'00000100'
    113.     movwf PORTA
    114.  
    115.  
    116.  
    117.  
    118. main
    119.  
    120.  
    121.  
    122.  
    123.     goto main
    124.  
    125.  
    126.  
    127. ; initialize eeprom locations
    128.  
    129.     ORG    0x2100
    130. ;    DE    0x00, 0x01, 0x02, 0x03
    131.  
    132.  
    133.     END                       ; directive 'end of program'
    134.  
    135.  
     
  3. chrissyp

    Thread Starter Active Member

    Aug 25, 2008
    82
    10
    Thanks I will give that a try over the weekend :)
     
  4. Harrington

    New Member

    Dec 19, 2009
    86
    3
    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
     
  5. chrissyp

    Thread Starter Active Member

    Aug 25, 2008
    82
    10
    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 :)
     
  6. Mickster

    Member

    Jan 10, 2010
    25
    11
    chrissyp likes this.
  7. chrissyp

    Thread Starter Active Member

    Aug 25, 2008
    82
    10
    Thanks Mickster that link looks very usefull
     
Loading...