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.

  • 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.

pic programming help

Status
Not open for further replies.

williB

New Member
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
 

williB

New Member
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..
 

williB

New Member
i just stored the array as a shortint. it worked !
so i assume that each one or zero is stored as a byte..?
 

Nigel Goodwin

Super Moderator
Most Helpful Member
williB said:
i just stored the array as a shortint. it worked !
so i assume that each one or zero is stored as a byte..?

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.
 

williB

New Member
Nigel Goodwin said:
williB said:
i just stored the array as a shortint. it worked !
so i assume that each one or zero is stored as a byte..?

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.
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..
 

Nigel Goodwin

Super Moderator
Most Helpful Member
williB said:
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..

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:
  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;
 

williB

New Member
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 ??
 

Nigel Goodwin

Super Moderator
Most Helpful Member
williB said:
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..

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.

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 .?

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.
 

williB

New Member
i got it going ..this is what i came up with...
Code:
        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
 

williB

New Member
This revised Code is rock solid :D


Code:
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
 

Nigel Goodwin

Super Moderator
Most Helpful Member
techknow said:
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:

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!
 

williB

New Member
Re: help

techknow said:
i need write an asm code for reading and writing to pic16f628 internal EEPROM so help me!! how it can be don
please explain..
how far along in the pic programming process are you?
 

williB

New Member
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!!
 

Attachments

  • c1.png
    c1.png
    22.8 KB · Views: 3,512
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top