1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

pic programming help

Discussion in 'Microcontrollers' started by williB, Aug 30, 2004.

  1. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    hmmm i have the array stored as integer.
    the book says that an integer in the range of -32,768 to 32767 is stored as a signed word..so yeah i guess . lemmy try that ,see what happens
     
  2. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    i didnt get to your last answer yet :oops:
    but i was working/playing around with the clock input to a running F628A
    At around 25 Hz input the output stops working , why is that?
    i figure it is maybe the watchdog timer or something is taking over..?
    i am blinking LED's BTW..
     
  3. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    i just stored the array as a shortint. it worked !
    so i assume that each one or zero is stored as a byte..?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,234
    Likes:
    641
    Location:
    Derbyshire, UK

    It depends entirely on how and where you store it - if you're storing each individual BIT in it's own variable, that seems very clumsy and wasteful. As the value is a 14 bit WORD, it makes sense to store them as such, in an unsigned 16 bit WORD variable - ignoring the top two bits, although they come into play if you start using 18F series 16 bit PIC's.
     
  6. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    i'm not sure how it is stored..?
    this is my statement..under type

    PicoutType = array[0..1024,1..14] of shortint;

    i think , but not sure , that each bit is stored as a shortint..
     
  7. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,234
    Likes:
    641
    Location:
    Derbyshire, UK
    How about like this:

    PicoutType = array[0..1023] of word;

    This allocates a 16 bit unsigned word for each 14 bit PIC 'word', and space for 1024 of them (not 1025 like you declared!).

    Incidently, WinPicProg allocates the program buffer like this:
    Code (text):

      BufType = Record
        Prog   : Array[0..MaxProgSize - 1] Of Word;
        Data   : Array[0..MaxDataSize - 1] Of Word;
        ID     : Array[0..7] Of Word;
        Fuses  : Word;
        Config : Array[1..7] Of Word;
      End;
     
     
  8. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    Thanks for that Nigel
    i have another question i checked your site ,but didnt see anything on hardware interrupts..


    ok using PIC 16F628A

    i plan on using RB0 / int pin and i am not sure how to do it..
    i just need an outline of what to do..
    My interrupt will be normally high , going low when the interrupt occors.
    1)i know you have to clear the Intedg ,bit 6 in option reg..
    2)as for the INTCON reg ..?
    i think all i have to do for this is set bit 4 INTE and clear bit 1 INTF after i service the interrupt..
    3)i think i also have to save W and STATUS and return them when done..but i am not sure why STATUS must be saved .?

    have i missed anything ??
     
  9. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,234
    Likes:
    641
    Location:
    Derbyshire, UK
    MicroChip have a number of application notes about using 'interrupt on change on PortB' - I would advise looking at those.

    An interrupt occurs on EVERY change - going high, or going low, so your interrupt routine needs to test if it'r the one you want - again, the application note explains this, and gives examples.

    You need to save EVERYTHING! which might be changed in the interrupt routine, the STATUS register is EXTREMELY important - many PIC instruction affect the STATUS register.

    If you check my seven segment LED display tutorial, this uses a timer interrupt routine, and gives an example of saving and restoring the registers.

    I would advise trying not to use subroutines called from an interrupt routine (or at least being very aware and careful), because the PIC only has a very limited stack size - if the main routine is three levels down subroutines, then an interrupt is called, which goes down another two levels, you're looking at overflowing the stack. This sort of problem is likely to occur only occasionally, under a particular unlucky set of circumstances, so could be very hard to find - best to avoid the situation ever occuring.
     
  10. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    i got it going ..this is what i came up with...
    Code (text):
            org     0x00                    
            goto    BEGIN

            org     0x04                 ;set start of ISR
            movwf   wtemp                ; save W & status
            swapf   STATUS,W
            movwf   statustemp


            movlw   0x0E                  ;blink upper three of lower half ON
            movwf   PORTB
            nop
            nop
            nop

            movlw   0x00                 ; Blink OFF
            movwf   PORTB

            movlw   0x0E                  ;blink upper three of lower half ON
            movwf   PORTB
            nop
            nop
            nop

            movlw   0x00                 ; Blink OFF
            movwf   PORTB

            swapf   statustemp,W         ; Restore W & status
            movwf   STATUS
            movf    wtemp,w
            bcf     INTCON,1             ; clear bit 1 INTF
            retfie



    BEGIN   clrf    PORTA
            clrf    PORTB
            bsf     INTCON,4             ; Enable RB0 interrupt
         
            movlw   0x07                 ; turn off comparators
            movwf   CMCON

            bsf     INTCON,7          ; Bit7 GIE global int enable
            bsf     INTCON,6          ; PEIE Bit set Peripheral enable
            bsf     INTCON,4          ; INTE Bit RB0 External Interrupt bit

            bsf     STATUS ,RP0       ;Bank 1
                                      ;set TRISB bit0 to 1
            movlw   b'00000001'          ;set PORTB Bits<7..1>as output
            movwf   TRISB                 ; PORTB Bit0 as Input
            bcf     OPTION_REG,6         ;Clear PEIE (RBO interrupt)

            bcf     STATUS ,RP0          ; Bank 0
    START
            nop
            nop
                                         ; wait for interrupt
            nop
            goto    START


     end
     
  11. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    This revised Code is rock solid :D


    Code (text):

    wtemp      EQU     0x20
    statustemp EQU     0x21


            org     0x00                    
            goto    BEGIN

            org     0x04                 ;set start of ISR
            movwf   wtemp                ; save W & status
            swapf   STATUS,W
            movwf   statustemp
            clrf    STATUS                  ; Force bank 0
            clrf    PORTA
            clrf    PORTB
         ; my blink routine starts here
            movlw   0x0E                  ;blink upper three of lower half ON
            movwf   PORTB
            nop
            nop
            nop
            movf    PORTB,w
            movlw   0x00                 ; Blink OFF
            movwf   PORTB
         ; my Blink routine stops here  

            swapf   statustemp,w         ; Restore W & status
            movwf   STATUS
            movf    wtemp,w
            bcf     INTCON,INTF             ; clear bit 1 INTF
            retfie



    BEGIN
            bsf     STATUS,RP0          ; Bank 1
            movlw   0x1F
            movwf   TRISA
            movlw   b'00000001'          ;set PORTB Bits<7..1>as output
            movwf   TRISB                 ; PORTB Bit0 as Input

            bcf     STATUS,RP0           ; Bank 0
            clrf    PORTA
            clrf    PORTB
            clrf    INTCON

         
            movlw   0x07                 ; turn off comparators
            movwf   CMCON

            bcf     OPTION_REG,INTEDG     ; Interrupt edge select bit
            bsf     INTCON,GIE          ; Bit7 GIE global int enable
            bsf     INTCON,INTE             ; bit 4 Enable RB0 interrupt
    START
                                         ; wait for interrupt
          goto    START



     end
     
     
  12. techknow

    techknow New Member

    Joined:
    Oct 22, 2004
    Messages:
    70
    Likes:
    0
    help

    i need write an asm code for reading and writing to pic16f628 internal EEPROM so help me!! how it can be don
     
  13. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,234
    Likes:
    641
    Location:
    Derbyshire, UK
    Re: help

    Consult my tutorials, one of the remote control ones does just that!.
     
  14. techknow

    techknow New Member

    Joined:
    Oct 22, 2004
    Messages:
    70
    Likes:
    0
    not enough so dont tr it again
     
  15. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,234
    Likes:
    641
    Location:
    Derbyshire, UK
    Sorry? - the tutorial in question reads and writes to the EEPROM, what are you wanting to do then?.
     
  16. techknow

    techknow New Member

    Joined:
    Oct 22, 2004
    Messages:
    70
    Likes:
    0
    sorry for disturbing u guys :(
    actualy i need is a asm code for w/r to a pic internal eeprom....not an complicated tiutorial.... :eek:
     
  17. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,234
    Likes:
    641
    Location:
    Derbyshire, UK
    Have you heard of 'cut and paste'? - simply take the piece out you want - or read the datasheet which tells you how to do it in the first place!
     
  18. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    Re: help

    please explain..
    how far along in the pic programming process are you?
     
  19. techknow

    techknow New Member

    Joined:
    Oct 22, 2004
    Messages:
    70
    Likes:
    0
    i got it and thaks for the u guys.. but i got it from somother forum...willib i do lots f stuff and but never used eeproms in life heehe
     
  20. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    I've updated my ISA bus Pic programmer schematic..
    thanks, to all who helped me get this Eagle layout software, working...
    i still have to tie up some loose ends on this schematic , but this is basically it..
    notice i've labeled it PC control..thats what you can do with it..
    My latest use is to read a microchip MCP3004 Serial A/D converter with it..
    i just simulated the signals of the SPI interface.
    the signal labled RB6 i used for the clock.
    Din & Dout connect signal labeld RB7
    and i connected the signal labeld MCLR to the chip select line.
    The only adjustment i had to make was to drop the voltage on MCLR to 5 V .
    Like i said earlier i still have to check the schematic against the board.
    I left the B inputs to the LS245 open , depending on how many data sources you want to use.Right now i have all but D0 grounded (so the data From the 3004 comes in as either a one or a zero.
    also the DIR on the LS 245 isnt connected in the schematic that should go from B to A.
    luv this Layout program!!
     

    Attached Files:

    • c1.png
      c1.png
      File size:
      22.8 KB
      Views:
      3,490
  21. Jay.slovak

    Jay.slovak Active Member

    Joined:
    Jan 11, 2005
    Messages:
    1,726
    Likes:
    5
    I just wanted to bring up this interesting ISA programmer :lol:
     

Share This Page