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

Junebug PORTB header mod

Discussion in 'Microcontrollers' started by futz, Dec 12, 2007.

  1. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    futz hope you dont mind i modded your code to replace my busted RA1 pin to the RB0 pin works 100% :D :
    Code (text):

        list    p=18F1320
        include <p18F1320.inc>
        CONFIG  OSC=INTIO2,WDT=OFF,MCLRE=ON,LVP=OFF

        cblock  0x00
            d1,d2,d3,count,count2,dataout,temp,dec1,dec2
        endc

        org 0x0000
    init    bsf OSCCON,IRCF2    ;set to 8MHz clock
        bsf OSCCON,IRCF1
        bsf OSCCON,IRCF0
        clrf    TRISA
        clrf    TRISB
        clrf    LATA
        clrf    LATB
        setf    ADCON1      ;make PORTA all digital
        clrf    count
        call    dl_40ms     ;allow lcd to settle before init
        call    lcdinit     ;initialize lcd
        goto    main

    table1  db  "Junebug LCD Demo",0x00

    main    movlw   HIGH table1 ;display table1
        movwf   TBLPTRH
        movlw   LOW table1
        movwf   TBLPTRL
    mnloop  tblrd   *+
        movf    TABLAT,W
        xorlw   0x00        ;zero?
        btfsc   STATUS,Z
        goto    next        ;yes, done
        movwf   dataout     ;no, go again
        call    lcdchar
        call    dl_50us     ;wait 50us
        goto    mnloop
    next    call    lcd_line2
        call    dl_50us

    nbs movlw   d'100'      ;count down from 100 on second line
        movwf   count2
    nubs    decfsz  count2
        goto    numbs
        goto    dood
    numbs   movf    count2,W
        call    fix
        movf    dec1,W
        movwf   dataout
        call    lcdchar
        call    dl_50us    
        movf    dec2,w
        movwf   dataout
        call    lcdchar
        call    Delay
        call    lcd_line2
        goto    nubs
    dood    goto    nbs

    ;*************************************************************
    ; fix - subroutine takes byte passed in W - splits it into two
    ; ascii bytes in dec1 and dec2, representing decimal digits.
    fix:    movwf   dec2        ;put number in dec2
        clrf    count       ;count = 0
        movlw   0x0a        ;W = 10
    tens:   subwf   dec2,F      ;subtract 10 from number
        btfsc   STATUS,C    ;result <10?
        goto    again       ;no, go again
        movf    count,W     ;yes, put count in W
        addlw   0x30        ;add $30 to make it an ASCII number
        movwf   dec1        ;and store it in dec1
        movf    dec2,W      ;get remainder (2nd digit)
        addlw   0x0a        ;put the last subtract back
        addlw   0x30        ;add $30 to make it ASCII
        movwf   dec2        ;store it back in dec2
        return          ;and return
    again:  incf    count,F     ;increment count
        goto    tens        ;go again

    lcd_line1
        movlw   0x80
        movwf   dataout
        call    lcdcmd
        call    dl_50us
        return

    lcd_line2
        movlw   0xc0
        movwf   dataout
        call    lcdcmd
        call    dl_50us
        return

    lcdinit movlw   0x06        ;send 03 nybble
        movwf   PORTA
        BSF PORTB, 0
        call    e_togg
        call    dl_05ms     ;wait 5ms

        movlw   0x06        ;send 3 second time
        movwf   PORTA
        BSF PORTB, 0
        call    e_togg
        call    dl_160us    ;wait 160us

        movlw   0x06        ;send 3 third time
        movwf   PORTA
        BSF PORTB, 0
        call    e_togg
        call    dl_160us    ;wait 160us

        movlw   0x04        ;enable 4-bit mode
        movwf   PORTA
        BCF PORTB, 0
        call    e_togg
        call    dl_50us     ;wait 50us
           
        movlw   0x28        ;set 4-bit mode and 2-lines
        movwf   dataout
        call    lcdcmd
        call    dl_50us     ;wait 50us

        movlw   0x10        ;cursor move & shift left
        movwf   dataout
        call    lcdcmd
        call    dl_50us     ;wait 50us

        movlw   0x06        ;entry mode = increment
        movwf   dataout
        call    lcdcmd
        call    dl_50us     ;wait 50us

        movlw   0x0d        ;display on, cursor on, blink on
        movwf   dataout
        call    lcdcmd
        call    dl_50us     ;wait 50us

        movlw   0x01        ;clear display
        movwf   dataout
        call    lcdcmd
        call    dl_05ms     ;wait 5ms
        return

    lcdcmd  swapf   dataout,W   ;swap nybbles and transfer to w
        andlw   0x0f        ;mask out high nybble
        movwf   temp        ;rotate left one bit for A1-A4
        rlncf   temp,F
        movff   temp,LATA   ;stuff result in PORTA [b]
        BTFSC   temp, 1     ;RA1 to RB0 Fix
        bra $+6
        BCF LATB, 0
        bra $+4     ;end of fix[/b]
        BSF LATB, 0
        bcf LATB,1      ;set RS low
        call    e_togg      ;latch the data
        movf    dataout,W   ;get byte in w again
        andlw   0x0f        ;and mask out high nybble
        movwf   temp
        rlncf   temp,F
        movff   temp,PORTA  ;Stuff [b]
        BTFSC   temp, 1     ;RA1 to RB0 Fix
        bra $+6
        BCF LATB, 0
        bra $+4     ;end of fix[/b]
        BSF LATB, 0
        bcf LATB,1      ;set RS low
        call    e_togg      ;latch the data
        goto    bleh        ;3 cycles - 600ns delay
    bleh    nop
        nop
        return

    lcdchar swapf   dataout,W   ;swap nybbles and transfer to w
        andlw   0x0f        ;mask out high nybble
        movwf   temp        ;rotate left one bit for A1-A4
        rlncf   temp,F
        movff   temp,LATA   ;stuff result in PORTA [b]
        BTFSC   temp, 1     ;RA1 to RB0 Fix
        bra $+6
        BCF LATB, 0
        bra $+4     ;end of fix[/b]
        BSF LATB, 0
        bsf LATB,1      ;set RS high
        call    e_togg      ;latch the data
        movf    dataout,w   ;get byte in w again
        andlw   0x0f        ;and mask out high nybble
        movwf   temp
        rlncf   temp,F
        movff   temp,LATA   ;stuff [b]
        BTFSC   temp, 1     ;RA1 to RB0 Fix
        bra $+6
        BCF LATB, 0
        bra $+4     ;end of fix[/b]
        BSF LATB, 0
        bsf LATB,1      ;set RS high
        bsf LATB,1      ;RS high
        call    e_togg      ;latch the data
        goto    bleh2       ;3 cycles - 600ns delay
    bleh2   nop
        nop
        return

    e_togg  bsf LATB,4      ;toggle E to latch data
        nop         ;delay 450ns minimum
        nop
        nop
        bcf LATB,4
        return

    dl_40ms movlw   0x7e        ;40ms delay
        movwf   d1
        movlw   0x3f
        movwf   d2
    dl40_0  decfsz  d1,F
        goto    $+6
        decfsz  d2,F
        goto    dl40_0
        nop
        return

    dl_05ms movlw   0xce        ;5ms delay
        movwf   d1
        movlw   0x08
        movwf   d2
    dl05_0  decfsz  d1,F
        goto    $+6
        decfsz  d2,F
        goto    dl05_0
        return

    dl_160us            ;160us delay
        movlw   0x69
        movwf   d1
    dl160_0 decfsz  d1,F
        goto    dl160_0
        return

    dl_50us movlw   0x1f        ;50us delay
        movwf   d1
    dl50_0  decfsz  d1,F
        goto    dl50_0
        return

    Delay   movlw   0x0c        ;.75 second delay
        movwf   d1
        movlw   0x46
        movwf   d2
        movlw   0x04
        movwf   d3
    Delay_0 decfsz  d1,F
        goto    $+6
        decfsz  d2,F
        goto    $+6
        decfsz  d3,F
        goto    Delay_0
        return

        end  
     
     
  2. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Hey futz since your always helping you know about look-up tables?

    How would i implement one here?

    Code (text):

        MOVFW   OFFSET  ; Where to start in table
        CALL    TABLE   ; Call the table
        ORG     0xnn00  ; Not sure what this is for here
    TABLE   ADDWF PCL   ; add W to the Table Pointer Current Location(address)
        RETLW   0xnn    ; RETURN with Literal in W
     
     
  3. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    That's the old fashioned pre18F way to do tables. Just use my code as an example to learn how to use the TBLRD instruction and the TABLAT and TBLPTR registers. They're very simple to use. The data sheet has good info too.

    Basically, you load the TBLPTR table pointer register with the address of your table. Then you use TBLRD to read the table, autoincrementing or not or whatever you need. Then just read TABLAT to get the result of the table read.
     
    Last edited: Apr 10, 2008
  4. dave

    Dave New Member

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


     
  5. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US

    [embed]http://www.youtube.com/v/B7770NZoOTs[/embed]

    Nice shots:
    [​IMG]
    [​IMG]
    [​IMG]
     
    Last edited: Apr 10, 2008
  6. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Thanks for the info futz works great!
     
  7. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    I just ran across this pic of the adapter boards I use. Cheap and easy.
    They allow me to use 2x5's for most everything.
    On the Junebug I use a female pinheader in place of the molex next to the USB which allows me to use it there too.

    [​IMG]

    This one indicates the status of each line.
    It does not detect a floating line.
    A so so debug tool but great for teaching.

    [​IMG]
     
  8. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    I put this breadboard connector together. I pulled the pins out of the 2x5, cut the long pin connector into two sets of 5. Squeezed together in a vice.
     

    Attached Files:

  9. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    actually those headers fit 100% on my board... just like to seperate them more. i make a ICD wire today let me take a picture.
     
  10. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Here it is:
    Ugly but useful

    [​IMG]

    Off topic my Power Circuit... (and test LED)

    [​IMG]
    [​IMG]
    [​IMG]
     
  11. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    There is nothing wrong with ugly if it works for you. The key is to find out what works for you.

    When I make things for school, which is most of the time, I need several. PCBs saves me time.

    While I am on the subject. I like using Eagle (could be any program with schematic capture) to work on projects. If I happen to move on to another project for a while. the schematics for the board can be pulled up when I get back to it. I lack the discipline to make and update schematics for hand wired boards as I make changes to them. Each file in an Eagle project has a description field. I use these to note changes made from rev to rev, if the board was built, assembly notes, and corrections.

    I also have a small collection of etched but unpopulated boards. If I need to populate one of these it is easy to match the board rev number to an eagle schematic and board file.
     
  12. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    Do you know I was actually working on a small 5V / 3.3V adapter (for Junebug with clamp diodes) that looks very much like the one you posted.
     
  13. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    thanks 3v0 make me feel better :D

    Cool bill.... would love to see what you have done so far.. any updates?
     
  14. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Bill explain something to me...

    you say we cant program 3v chips because junebug sends 5v right.... why not just drop the 5v to 3 or so with some resistors and a capacitor ?

    DO you need to do anything else beside drop the voltage?
     
  15. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    I've got the 3.3V stuff working, the target PIC needs its own power supply and a pair of clamp diodes on PGD & PGC.

    Not too tough actually.
     
  16. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    cool.. would love a schem of it
     
  17. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    dude who ever gave me a bad rep sux and thats that.. i would understand if it was for a good reason but come on..

    [​IMG]
     
    • Like Like x 2
  18. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    I think the mods are fine, that's the fun of a kit. If I could squeeze another connector on the PCB that would be cool.

    PS thanks for the "great product" part but personally I'm thrilled people are extending my "baby" and I don't think the mods are "useless" I wish I had thought of them first :)
     
  19. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    Nice photos AdamSoft & Futz, wish my photo skillz were as good.
     
  20. Krumlink

    Krumlink New Member

    Joined:
    Aug 10, 2007
    Messages:
    2,080
    Likes:
    20
    Location:
    Michigan, USA
    Everybody is apparently credited by the number of reputation points they have. This is one of the things that are really starting to bug me.
     
  21. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    lol futz has the real skills on photo taking. I love his photos seem so clean.

    Bill i hope you dont mind. I might copy your design on the junebug and make my own (kind of) of course it will not be for sale as its your design and i would never do that. Just want to have a little more luxury.

    Will add:
    Port B header
    Variable Power Supply (isolated circuit) for use with powering device projects.

    PortB header will be 2x5 header with power output

    RA6 and RA7 and RA0 will have a DIL Switch to control weather have LEDs on it or a External Clock with a extra I/O pin available on PortA Header

    Con 3 will be re-a-ranged to be a PortA header... with power output

    Hows that sound?
     

Share This Page