Announcement

Collapse
No announcement yet.

pic16f84a

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • pic16f84a

    I am new to the pic16f84a. I use mplab as my debugger and am not sure of all the errors. If anyone has anything on them I would appreciate it if you could post a link. Thankyou. The problem I am having is when I insert the shift register command and compile I get error messages that say the overwriting the previous address. If anyone can help me with what I am doing wrong it would make my day.


    LIST P=16F84a ;tells which processor is used
    INCLUDE "p16f84a.inc" ;defines various registers etc. Look it over.

    RA4 EQU H'0004'
    RP0 EQU H'0005'
    STATUS EQU H'0003'
    PORTA EQU H'0005'
    PORTB EQU H'0006'
    TRISA EQU H'0085'
    TRISB EQU H'0086'
    CLRF PORTA ;Initialize PORTA by clearing output data latches
    BSF STATUS, RP0 ;Select Bank 1
    MOVLW 0x0F ;Value used to initialize data direction
    MOVWF TRISA ;Set RA<3:0> as inputs, R4 as output, TRISA<7:5> are ;always read as '0'
    ORG H'0000'
    BSF STATUS, RP0



    Clean: Deleting intermediary and output files.
    Clean: Done.
    Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F84A "final.asm" /l"final.lst" /e"final.err"
    Message[302] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 14 : Register in operand not in bank 0. Ensure that bank bits are correct.
    Error[118] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 16 : Overwriting previous address contents (0000)
    Error[118] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 16 : Overwriting previous address contents (0000)
    Error[129] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 20 : Expected (END)
    Halting build on first failure as requested.
    BUILD FAILED: Thu Sep 08 16:17:50 2005


    Ultimately what I am wanting to do is make a counter that automatically incrimates when a clock pulse is sent to it. We are controlling the clock pulse maunally. After we push a button, the counter will automtically incrimate. Thanks lots.

  • #2
    The "ORG H'0000'" should only be used at the very start of the code.
    You will have to jump before the program reaches ORG H'0004' (reserved for interrupts).

    like this:
    TITLE 'PI-3v2'
    PROCESSOR 16F877A ; Platform = 16F877A
    list p=16f877A ; list directive to define processor
    #include <p16f877A.inc> ; processor specific variable definitions
    __CONFIG _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF & _DEBUG_OFF & _CP_OFF & _CPD_OFF

    ;***** VARIABLE DEFINITIONS
    w_temp EQU 0x70 ; variable used for context saving
    status_temp EQU 0x71 ; variable used for context saving
    ;etc
    ;etc
    ;************************************************* ********
    ORG 0x000 ; processor reset vector
    clrf PCLATH ; ensure page bits are cleared
    clrf STATUS ;reset STATUS on powerup
    clrf FSR ;reset FSR on powerup
    goto Start ; Jump to program start

    ORG 0x004 ; processor reset vector (reserved address)
    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
    bsf PULSE ; make sure pulse is off
    bcf INTCON,GIE ; Disable all Interrupts
    bcf INT_DONE
    call INTERRUPT ; what to do...
    BCF PAGE_ ;Select page 0 (...0x7FF)
    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
    bcf INTCON,INTF ; reset interrupt flag
    bcf INTCON,RBIF ; reset interrupt flag
    bsf INTCON,GIE ; Enable Interrupts
    retfie ; return from interrupt
    ;************************************************* ********

    Start
    ;************************************************* ********; Initialize ports & modules
    ;************************************************* ********
    here is the actual start of the program code

    there is a counter in PIC16F84 (Timer0) but as you are controlling it manually the buttons bounce will increase the timer more than you like so write a new code for counting.
    when using buttons... PORTB is preferable as it has internal pull-ups (when not connected to anything it is read as a '1' and when button is pressed its connected to GND and read as '0').
    Remember to implement a delay for buttons to bounce (usually 3-10ms).

    hope this will help
    /Peter Morf

    Comment


    • #3
      Ok, I copied that interrupt information, and now I am having errors that looks like it says I need to define them. I looked in the p16f84a.inc file and I didnt see anything in there for them.

      LIST P=16F84a ;tells which processor is used
      INCLUDE "p16f84a.inc" ;defines various registers etc. Look it over.

      RA4 EQU H'0004'
      RP0 EQU H'0005'
      STATUS EQU H'0003'
      PORTA EQU H'0005'
      PORTB EQU H'0006'
      TRISA EQU H'0085'
      TRISB EQU H'0086'
      W_TEMP EQU
      ORG 0x000 ; processor reset vector
      CLRF PCLATH ; ensure page bits are cleared
      CLRF STATUS ; reset STATUS on powerup
      CLRF FSR ; reset FSR on powerup
      GOTO Start ; Jump to program start
      CLRF PORTA ; Initialize PORTA by clearing output data latches
      BSF STATUS, RP0 ; Select Bank 1
      MOVLW 0x0F ; Value used to initialize data direction
      MOVWF TRISA ; Set RA<3:0> as inputs, R4 as output, TRISA<7:5> are always read as '0'
      ORG 0x004 ; processor reset vector (reserved address)
      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
      BSF PULSE ; make sure pulse is off
      BCF INTCON,GIE ; Disable all Interrupts
      BCF INT_DONE
      CALL INTERRUPT ; what to do...
      BCF PAGE_ ; Select page 0 (...0x7FF)
      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
      BCF INTCON,INTF ; reset interrupt flag
      BCF INTCON,RBIF ; reset interrupt flag
      BSF INTCON,GIE ; Enable Interrupts
      RETFIE ; return from interrupt
      ORG H'0000'
      BSF STATUS, RP0



      Clean: Deleting intermediary and output files.
      Clean: Done.
      Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F84A "final.asm" /l"final.lst" /e"final.err"
      Error[128] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 11 : Missing argument(s)
      Error[113] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 16 : Symbol not previously defined (Start)
      Message[302] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 20 : Register in operand not in bank 0. Ensure that bank bits are correct.
      Error[113] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 22 : Symbol not previously defined (W_TEMP)
      Error[118] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 22 : Overwriting previous address contents (0004)
      Error[118] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 22 : Overwriting previous address contents (0004)
      Error[118] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 23 : Overwriting previous address contents (0005)
      Error[118] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 23 : Overwriting previous address contents (0005)
      Error[113] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 24 : Symbol not previously defined (STATUS_TEMP)
      Error[118] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 24 : Overwriting previous address contents (0006)
      Error[118] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 24 : Overwriting previous address contents (0006)
      Error[113] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 25 : Symbol not previously defined (PULSE)
      Error[128] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 25 : Missing argument(s)
      Error[118] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 25 : Overwriting previous address contents (0007)
      Error[118] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 25 : Overwriting previous address contents (0007)
      Error[113] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 27 : Symbol not previously defined (INT_DONE)
      Error[128] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 27 : Missing argument(s)
      Error[113] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 28 : Symbol not previously defined (INTERRUPT)
      Error[113] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 29 : Symbol not previously defined (PAGE_)
      Error[128] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 29 : Missing argument(s)
      Error[113] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 30 : Symbol not previously defined (STATUS_TEMP)
      Error[113] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 32 : Symbol not previously defined (W_TEMP)
      Error[113] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 33 : Symbol not previously defined (W_TEMP)
      Error[118] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 40 : Overwriting previous address contents (0000)
      Error[118] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 40 : Overwriting previous address contents (0000)
      Error[129] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\FINAL.ASM 44 : Expected (END)
      Halting build on first failure as requested.
      BUILD FAILED: Thu Sep 08 19:05:35 2005


      So confused!!

      Comment


      • #4
        thechad,

        It looks like you have taken some parts of Peter's example code that were not required, and these are causing the errors.

        I suggest you look at the asm template file that Microchip provides for the 16F84A. It can be found in your MPLAB install directory under the following path;

        MPASM Suite\Template\Code\f84atemp.asm

        Simply add your own code where it says 'remaining code goes here'.

        Good luck.

        Mark

        Comment


        • #5
          I am still confused though. All I have to do is copy what is here. That doesn't seem right. There is still EQU labels that have to be defined and what not. Or is that where the 'remaining code goes here' comes into play? Also Im not sure why the interrupts are needed. I used them with another chip and never really understood the use of them. But if you are saying I need them for this cause I will do that.

          Comment


          • #6
            Hi thechad,

            Your EQU statements would go into the section of the template that reads VARIABLE DEFINITIONS (or anywhere above your code really).

            No, you probably do not need to use an interrupt to do what you require (although it may make things easier). The interrupt handler in the template is simply there to show you how you would implement one, should you need to. In fact, the comments at the top of the template read;

            ;If interrupts are not used all code presented between the ORG
            ;0x004 directive and the label main can be removed. In addition
            ;the variable assignments for 'w_temp' and 'status_temp' can
            ;be removed.

            Mark

            Comment


            • #7
              OK--I compiled and worked out all the errors. Thanks so much up to this point. I was told since I was wanting to count, I would have to use the shift right command up to where I wanted to count to. I was planning on using the INCF command. Would either work? Also when I was getting the address overwrite errors, does that mean I have to use two registers and use the ADDLW and store to the RA4 output register I am planning on using? Thanks for putting up with the questions.

              Comment


              • #8
                Hi thechad,

                Whether you use a shift instruction or an increment really depends on what you intend to do with the count and how high you need to count. If you are going to output the count to an I/O port, for example to a line of LEDs, then a shift instruction may be the way to go. Remember, if you do use the shift instruction, you will need to 'seed' the count to some initial value (like 1), as 0 bit shifted in either direction is still 0.

                I do not think the address overwrite errors you were seeing were related to your register usage. They were likely caused by your ORG statements, or more specifically, by the number of asm instructions between the ORG statements.

                Mark

                Comment


                • #9
                  Ok I think I got it now. Another issue is getting the code to increment after we send a clock pulse to it. I looked in the manual and didn't see anything. I more than likely overlooked it. If anyone knows the answer I'd love to hear from you. I think I have to use the interrupt, but not sure. Also not sure how to use interrupts.



                  list p=16F84A ; list directive to define processor
                  #include <p16F84A.inc> ; processor specific variable definitions
                  __CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC
                  RA4 EQU H'0004'
                  RP0 EQU H'0005'
                  STATUS EQU H'0003'
                  PORTA EQU H'0005'
                  PORTB EQU H'0006'
                  TRISA EQU H'0085'
                  TRISB EQU H'0086'
                  W_TEMP EQU H'000C'
                  STATUS_TEMP EQU H'000D'
                  TOCS EQU H'0005'

                  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

                  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

                  MAIN MOVWF RA4
                  RLF RA4
                  RLF RA4
                  RLF RA4
                  RLF RA4

                  END


                  Clean: Deleting intermediary and output files.
                  Clean: Done.
                  Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F84A "pic.asm" /l"pic.lst" /e"pic.err"
                  Message[305] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\PIC.ASM 33 : Using default destination of 1 (file).
                  Message[305] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\PIC.ASM 34 : Using default destination of 1 (file).
                  Message[305] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\PIC.ASM 35 : Using default destination of 1 (file).
                  Message[305] C:\DOCUMENTS AND SETTINGS\CHAD\MY DOCUMENTS\PIC.ASM 36 : Using default destination of 1 (file).
                  Loaded C:\Documents and Settings\Chad\My Documents\pic.COD.
                  BUILD SUCCEEDED: Sat Sep 10 13:29:31 2005


                  Im also not sure what this message 305 I am getting. I made sure there were no errors and the build was successful.

                  Comment


                  • #10
                    Me again. I am making progress on this thing and think I found a way to make things go smoother for me. I do have one glitch I cant seem to overcome. I am using if...then statements and dont know what to do for the =. MPLAB doesnt recognize it and when I type in equals, it asks for me to define it. If I am doing this all wrong, please let me know. Thank you.

                    Comment


                    • #11
                      Chad, try http://www.picbasic.org Goto the forum there and post to a guy called Lester (surname). The people there know more about the PIC then anyone else I've come across. Not that the answers above aren't valid, they are, but the help you will get there will supliment what you get here.

                      Good luck.

                      Comment

                      Working...
                      X