16f722 wont run

Discussion in 'Embedded Systems and Microcontrollers' started by Dodgydave, Jul 20, 2013.

  1. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,979
    744
    i am trying to get this 16f722 pic to work but nothing is doing, what am i doing wrong, it just puts leds on all ports..

    Code ( (Unknown Language)):
    1.  
    2. ;******************************************************************************
    3. ;   This file is a basic code template for code generation on the  PIC16F722. *
    4. ;   This file contains the basic code building blocks to build upon.          *
    5. ;                                                                             *
    6. ;   Refer to the MPASM User's Guide for additional information on features of *
    7. ;   the assembler.                                                            *
    8. ;                                                                             *
    9. ;   Refer to the respective 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. ;    Files Required: P16F722.INC                                              *
    24. ;                                                                             *
    25. ;******************************************************************************
    26. ;                                                                             *
    27. ;    Features of the 16F722:                                                  *
    28. ;                                                                             *
    29. ;    Precision Internal Oscillator (16 MHz or 500 kHz operation)              *
    30. ;    On Chip 3.2 V Regulator                                                  *
    31. ;    Pinout compatible to other 28/40 pin PIC16CXXX and 16FXXX micros         *
    32. ;    Brownout reset with selectable trip points                               *
    33. ;    8 bit resolution and 14 channel A/D Converter                            *
    34. ;    Wide operating voltage range (1.8-5.5V)                                  *
    35. ;    A/D converter with selectable 1.024, 2.048, 4.096 voltage reference      *
    36. ;    AUSART, SPI, and IIC                                                     *
    37. ;                                                                             *
    38. ;******************************************************************************
    39. ;                                                                             *
    40. ;    Notes:                                                                   *
    41. ;                                                                             *
    42. ;                                                                             *
    43. ;******************************************************************************
    44. ;                                                                             *
    45. ;    Revision History:                                                        *
    46. ;                                                                             *
    47. ;******************************************************************************
    48.  
    49. ;------------------------------------------------------------------------------
    50. ; PROCESSOR DECLARATION
    51. ;------------------------------------------------------------------------------
    52.  
    53.      LIST      p=16F722             ; list directive to define processor
    54.      #INCLUDE <P16F722.INC>         ; processor specific variable definitions
    55.  
    56. ;------------------------------------------------------------------------------
    57. ;
    58. ; CONFIGURATION WORD SETUP
    59. ;
    60. ; The 'CONFIG' directive is used to embed the configuration word within the
    61. ; .asm file. The lables following the directive are located in the respective
    62. ; .inc file.  See the data sheet for additional information on configuration
    63. ; word settings.
    64. ;
    65. ;------------------------------------------------------------------------------
    66.  
    67.      __CONFIG    _CONFIG1, _DEBUG_OFF & _PLL_EN & _BORV_1_9 & _BOR_OFF & _CP_OFF & _MCLR_DIS & _PWRT_DIS & _WDT_OFF & _INTOSCIO
    68.      __CONFIG    _CONFIG2, _VCAP_DIS
    69.  
    70.  
    71.         errorlevel -302     ; suppress banksel warning messages during assembly
    72.         errorlevel -311     ; suppress HIGH operator warning messages during assembly
    73.         errorlevel -207     ; no messages
    74. ;------------------------------------------------------------------------------
    75. ;
    76. ; VARIABLE DEFINITIONS
    77. ;
    78. ; Available Data Memory divided into Bank 0 through Bank 3.  Each Bank contains
    79. ; Special Function Registers and General Purpose Registers at the locations
    80. ; below:  
    81. ;
    82. ;           SFR           GPR               SHARED GPR's
    83. ; Bank 0    0x00-0x1F     0x20-0x6F         0x70-0x7F    
    84. ; Bank 1    0x80-0x9F     0xA0-0xBF         0xF0-0xFF  
    85. ; Bank 2    0x100-0x11F                     0x170-0x17F
    86. ; Bank 3    0x180-0x19F                     0x1F0-0x1FF
    87.  
    88.  
    89. ;***** VARIABLE DEFINITIONS
    90.  
    91.     CBLOCK 0x20       ; user file mnames
    92.     Temp
    93.     HUNS
    94.     TENS
    95.     UNIITS
    96.     d1
    97.     d2  
    98.     d3
    99.     d4
    100.     RESULTAD
    101.     ENDC
    102.  
    103. W_TEMP         EQU        0x7F  ; w register for context saving (shared)
    104. STATUS_TEMP    EQU        0x7E  ; status used for context saving (shared)
    105. PCLATH_TEMP    EQU        0x7D  ; pc used for context saving (shared)
    106.  
    107. ;------------------------------------------------------------------------------
    108. ; RESET VECTOR
    109. ;------------------------------------------------------------------------------
    110.  
    111. RESET     ORG     0x0000            ; processor reset vector
    112.           GOTO    MAIN          ; go to beginning of program
    113.  
    114. ;------------------------------------------------------------------------------
    115. ; INTERRUPT SERVICE ROUTINE
    116. ;------------------------------------------------------------------------------
    117.  
    118. ISR       ORG     0x0004            ; interrupt vector location
    119.  
    120. ;         Context saving for ISR
    121.           MOVWF   W_TEMP            ; save off current W register contents
    122.           MOVF    STATUS,W          ; move status register into W register
    123.           MOVWF   STATUS_TEMP       ; save off contents of STATUS register
    124.           MOVF    PCLATH,W          ; move pclath register into W register
    125.           MOVWF   PCLATH_TEMP       ; save off contents of PCLATH register
    126.  
    127. ;------------------------------------------------------------------------------
    128. ; USER INTERRUPT SERVICE ROUTINE GOES HERE
    129. ;------------------------------------------------------------------------------
    130.  
    131. ;         Restore context before returning from interrupt
    132.  
    133.           MOVF    PCLATH_TEMP,W     ; retrieve copy of PCLATH register
    134.           MOVWF   PCLATH            ; restore pre-isr PCLATH register contents
    135.           MOVF    STATUS_TEMP,W     ; retrieve copy of STATUS register
    136.           MOVWF   STATUS            ; restore pre-isr STATUS register contents
    137.           SWAPF   W_TEMP,F
    138.           SWAPF   W_TEMP,W          ; restore pre-isr W register contents
    139.           RETFIE                    ; return from interrupt
    140.  
    141. ;------------------------------------------------------------------------------
    142.      MAIN
    143.     ; set up registers ***************************************************  SEE PAGE 48 DATASHEET
    144.    
    145.    
    146.     BANKSEL OSCCON
    147.     MOVLW B'00111100' ; set 16mhz clock internal
    148.     MOVWF OSCCON
    149.     BANKSEL PORTA      ; select register
    150.     CLRF PORTA         ;Init PORTA as digital ( = analouge i/p)
    151.     BANKSEL ANSELA      ; select register
    152.     CLRF ANSELA         ;digital I/O
    153.     BANKSEL TRISA
    154.     movlw .0
    155.     movwf TRISA          ; set all outputs
    156.  
    157.  
    158.     BANKSEL PORTB       ; select register
    159.     CLRF PORTB          ;Init PORTB as digital( 1 = analouge i/p)
    160.     BANKSEL ANSELB      ; digital i/o
    161.     CLRF ANSELB
    162.     BANKSEL TRISB
    163.     movlw .0    
    164.     movwf TRISB        ; set all outputs
    165.  
    166.     BANKSEL PORTC       ; select register
    167.     CLRF PORTC          ; init PORTC
    168.     BANKSEL TRISC
    169.     movlw .0
    170.     movwf TRISC         ; SET ALL OUTPUTS
    171.  
    172.     BANKSEL OSCCON       ; select oscillator
    173.     MOVLW b'00111100'    ; set up osc as 16Mhz clock 2% accuracy high osc mode
    174.     MOVWF OSCCON
    175.     BANKSEL OPTION_REG   ; select option reg
    176.     MOVLW b'00000111'    ; set up rtcc to prescale 256, pullups off
    177.     MOVWF OPTION_REG     ; do it
    178.     clrf PORTA
    179.     clrf PORTB           ; clear all ports
    180.     clrf PORTC  
    181.     goto START           ; start programme
    182. ;**********************************************************
    183. ;------------------------------------------------------------------------------
    184.  
    185.     START
    186.    
    187.     movlw .255
    188.     movwf PORTA  ; put leds on
    189.     movwf PORTB
    190.     movwf PORTC
    191.  
    192.     goto START
    193.  
    194.  
    195.    
    196.  
    197.  
    198.  
    199.           END
    200.  
     
    Last edited by a moderator: Jul 20, 2013
  2. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,524
    2,369
    Give up on the 18F? :)
    I cut my teeth on the 16F but find the 18f quite a bit simpler if using assembly prog. no bank switching to worry about, among other simpler commands.
    I familiarized myself with PIC's after using Motorola many years ago.
    Here http://www.winpicprog.co.uk/pic_tutorial.htm
    Max.
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    What does it do in the simulator? While the simulator is not perfect (somethings like r-m-w don't sim as they work in the real world) the rule is "if it don't sim you can't win."

    You should be able to see what register is not seats you intended... Or you can just directly set registers to try other settings that may be necessary before the port bits work digitally.
     
  4. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,979
    744

    Just got both pics new and would like to get
    get both running, never used these before so i am lost? I normally use the 16f690 and so thought i would migrate to a more output pic, if you have one to recommend like the 16f690 with 24 I/O then please do so.
     
    Last edited: Jul 21, 2013
  5. tubeguy

    Well-Known Member

    Nov 3, 2012
    1,157
    197
    Look's like the code is looping through START with all bits on ports A-C set HI continuously.
     
  6. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,979
    744

    Yes its supposed to light up all led's, but nothing is happening, there must be something else set wrong in the config or what, ITS NOT THE LEDS BEFORE ANYONE JUMPS IN, its in a prototype board so it can run other other pics as well so i know its this pic that's not working.

    I just cant seem to fathom it out,a simple output to the ports put the leds on and NOWT?
     
    Last edited: Jul 21, 2013
  7. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,524
    2,369
    Did you get the PM, it does not show as sent for some reason?
    Max.
     
  8. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,979
    744
    yes thankyou Max,will look at tonite when i get home , your a star ,cheers Dave
     
  9. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,524
    2,369
    I didn't notice the 'save PM sent' box, new to the forum.
    Max.
     
  10. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,979
    744
    Tried it in the simulator and nothing happens , no ports are active???

    Anybody got ideas why it wont work?
     
  11. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    You aren't returning to bank 0 for I/O...
     
    absf likes this.
  12. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,979
    744

    So how do i do that,?
     
  13. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,524
    2,369
    Your P.M. returned.
    With correction per Tshuck inspiration.
    Max.
     
    Dodgydave likes this.
  14. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    Code ( (Unknown Language)):
    1.  
    2.         BANKSEL  PORTA        ;just add this line
    3.     clrf PORTA
    4.     clrf PORTB           ; clear all ports
    5.     clrf PORTC  
    6.     goto START           ; start programme
    7. ;**********************************************************
    8. ;------------------------------------------------------------------------------
    9.  
    10.     START
    11.    
    12.     movlw .255
    13.     movwf PORTA  ; put leds on
    14.     movwf PORTB
    15.     movwf PORTC
    16.  
    17.     goto START
    18.  
    19.  
    20.           END
    Allen
     
    Dodgydave likes this.
  15. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,524
    2,369
    This works also.
    Code ( (Unknown Language)):
    1.  
    2. Start:
    3.     BANKSEL    PORTA    
    4.         movlw .255
    5.         movwf   PORTA
    6.         movwf   PORTB
    7.         movwf   PORTC
    8. Start1:
    9.     goto Start1
    10.  
    11.  
    12.  
    13.         END
    14.  
     
    Last edited: Jul 23, 2013
    Dodgydave likes this.
  16. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,979
    744
    Yep your both correct, i forgot to banksel porta
    one of the perils of migration, new set up codes!,
    Cheers guys its working.
     
    Last edited: Jul 23, 2013
Loading...