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

programming a byte on one pin

Discussion in 'Microcontrollers' started by MrDEB, Nov 4, 2012.

  1. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    I realize that it is not that difficult. Been investigating all the aspects of this shift register. Found out I need to clear the register between sub-rountines as I get left over LED(bits) enabled.
    Will try again on firing the rows as I attempted that with unsuccessful results. I re-configured the High Side driver inputs so all 7 inputs are on the same portB (was worried about using the B.6 / PGC pin.
    Tried using PORTB.bITS(x) = 1 then do a for next loop but I have an issue with the OUTPUT enabled. Using PORTB.1=1 dosen't seem to want to coporate. But using HIGH(row0) works just fine.
    Going to try and add just the row data between the colum data BUT I have 5 colum data and 7 row data. Will get back at it. Was thinking an array like I have in the LOAD sub routine.
     
  2. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    By joe I got it working.
    I inserted a counter that increments Rows(x)
    seems to work pretty good.
    need to cnfigure out where I messed up my row connections. not in right order after I moved pin connections around so ALL of the rows are on PORTB
     
  3. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    I got over the hurdle of enabling the rows in sequence along side the colums. Working on making the graphic scroll across the display.
    Still contemplating having separate connections to the TLC5916's (each have its own LE and OE connections to the PIC) Hopefully this will eliminate leftover bits and color mixing.
    Last night I was experimenting with the delay time and found I could get the matrix to display two seperate arrows at the same time and no flickering.
    Would be a nice piece odf test equipment to be able to test the LED intensity comparing different delays settings. A simple photo transistor w amp and meter (light meter). I have all the parts leftover from the LIGHT lISTENER project, maybe a side track project??
     
  4. dave

    Dave New Member

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


     
  5. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22

    curious as to WHY the dang PIC takes so long to get going?
    Have the internal ocs enabled at 32 but it takes about 30 seconds AFTER I program the PIC before the LEDs even come on.
    BUT when it does I get a leftover? bit comes on?
    Thinking of inserting a %00000000 but the bit that comes on is towards the end of the CONST array. Going to look into using a STEP instead of all the 12 CONST elements(12 for rows and 12 for colums).
    Going to take a break, been at it getting slow progress.
     
  6. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,798
    Likes:
    134
    Location:
    morristown,tn
    Your not setting the osccon
     
  7. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,798
    Likes:
    134
    Location:
    morristown,tn
    Include "InternalOscillator.bas you need that with the right setting and clock 16 is wrong too I bet set it to
    clock = 8


    Now I don't no but I think nternalOscillator.bas is the one that set's by the clock setting

    But your chip has no 16 mhZ clock 8 is it without setting pll and I'm sure that's not set.

    You should use a crystal till you get this stuff down pat.
     
    Last edited: Nov 22, 2012
  8. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    I have this assembled on a perfboard and didn't really want to add a crystal but I may just do it.
    Will recheck my code for the oscon setting.
    Using the internaloscilliator.bas
     
  9. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,798
    Likes:
    134
    Location:
    morristown,tn
    Mrdeb you missed a part there is no clock = 16 on that chip with out pll and from what your saying the clock is running slow
     
    Last edited: Nov 22, 2012
  10. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    This is what I have that works

    going to rat shack for some 22pf caps to connect a crystal.
    I looked at the internalosc.bas and it supposedly sets the oscon registers etc.
    This scrolls an arrow across the matrix. Hopefully will stumble on to why on power up I get a segment that blinks once then the roiutine proceeds as wanted. Thinking maybe I need to disable the LE inputs as well as the OE inputs. Going to bed.
    Code (text):
    {
    *****************************************************************************
    *  Name    : UNTITLED.BAS                                                   *
    *  Author  : [select VIEW...EDITOR OPTIONS]                                 *
    *  Notice  : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS]              *
    *          : All Rights Reserved                                            *
    *  Date    : 11/12/2012                                                     *
    *  Version : 1.0                                                            *
    *  Notes   : Burts knight rider                                                               *
    *          :                                                                *
    *****************************************************************************
    }
    Device = 18F2420
    Clock = 8
    //Config OSC = INTIO67
    Include "InternalOscillator.bas "
    Include "shift.bas"
    Include "utils.bas"
    Include "convert.bas"
    Include "InternalOscillator.bas "
    Dim SDI As PORTC.4
    Dim CLK As PORTC.5
    Dim LE As PORTC.3
    Dim RED_OE As PORTC.0
    Dim GREEN_OE As PORTC.1
     
    Dim DataPin As SDI  
    Dim ClockPin As CLK
    Dim ResetPin_R As RED_OE
    Dim ResetPin_G As GREEN_OE
    Dim index As Byte
    Dim X As Byte
    {
    Dim row0 As PORTB.0
    Dim row1 As PORTB.6
    Dim row2 As PORTB.1
    Dim row3 As PORTB.2
    Dim row4 As PORTB.3
    Dim row5 As PORTB.4
    Dim row6 As PORTB.5
    Dim led As PORTA.0
    }

    Dim colum_buffer(5) As Byte
    Dim Z As Byte


    Const data(12)As Byte = (%00010001, %00001010 ,%00000100, %00010001, %00001010, %00000100,
    %00010001, %000001010 ,%00000100, %000010001,%00001010, %00000100)
     
    Const Rows(12) As Byte =(%00000001, %000000010 ,%00000100, %000000010, %00000100, %00001000,
     %00000100 ,%000001000 ,%00010000 ,%00001000,%00010000 ,%00100000)
                         
    Sub LOAD()
        For Z = 0 To 4          
    colum_buffer(Z)= data(Z)            
    Next      
    End Sub

    Sub StartScan()
        LE = 0
        ResetPin_G = 1
        Shift.Out(MSB_FIRST, X ,8)  
        LE = 1         //Latch data
        PORTB =Rows(Z)  
        DelayuS(10)
        ResetPin_G = 0  // output disable
        LE = 0
        Z = Z+1
    End Sub

    Shift.SetOutput(DataPin)
    Shift.SetClock(ClockPin)
    ADCON1 = $07
    Output(ResetPin_R)
    Output(ResetPin_G)
    Output (LE)

    // start of main
    While true
      Z = 0  
     For index = 0 To Bound (data)
          DelayMS(100)
          X = (data(index))
      StartScan
      Next
      TRISB = %00000000
     Wend
     End
     
  11. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    Well I knew I should have connected a crystal to begin with but I hope to get it working without a crystal after I am all done.
    Been adjusting my delays trying to get a SMOOTH transition between arrows. I at one point had two arrows frozen on the matrix. This experimenting got me to wondering if there is a formula for computing delays between getting data and length of time to display data.
    Not real concerned at this point as the delays will change after running the PIC without a crystal in my final design.
     
  12. Pigskin Tony

    Pigskin Tony New Member

    Joined:
    Aug 20, 2012
    Messages:
    18
    Likes:
    0
    Huh? Wouldn't a delay of X mS be the same as long as the clock frequency is specified correctly? Doesn't the compiler handle the details?
     
  13. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,798
    Likes:
    134
    Location:
    morristown,tn
    Yep he has his code wrong if you look at the includes you'll
    See what's happening here your including the osccon bad two
    Times that means the compiler includes the last one which
    Takes forever to load and run
    The compiler sets the delay with the clock =xx statement
    So it doesn't matter if you have a 4 or 32 MHz crystal
    The delay is the same
     
  14. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    Ah yes I see the osccon way down in the code. I missed that one.
    Trying to get the arrow to go left. Tried using a STEP-?? but felt a CONST array reversed what the Rows array has.
    Will post a video AFTER I get it straighen out.
     
  15. Pigskin Tony

    Pigskin Tony New Member

    Joined:
    Aug 20, 2012
    Messages:
    18
    Likes:
    0
    Isn't this oscillator configuration needed too? It's commented out.
     
  16. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,798
    Likes:
    134
    Location:
    morristown,tn
    Yep that should be set to config osc = INTIO67
    this is what he should have

    If Mrdeb want's a INtOSC with a clock of 16
    Code (text):
    Device = 18F2420
    Clock = 16
    CONFIG OSC = INTIO67
    Include "InternalOscillator.bas "
    Include "shift.bas"
    Include "utils.bas"
    Include "convert.bas"
    Your setting should be like that.
     
  17. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,118
    Likes:
    90
    Location:
    Seattle, WA
    I shudder to get involved again, but I think MrDEB's oscillator setup is missing some additional required information.

    this has been explained before.
     
  18. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,798
    Likes:
    134
    Location:
    morristown,tn
    No it's not go back where you came from and read up on the
    that andy wrote it set's the dang thing right IF you use it RIGHT that's the problem

    If you set the OSC to use the Internal Oscillator you can't use osccon setting and use modules with Swordfish the setting don't get set till Swordfish run down the list of Modules and good old Mrdeb
    had the dang thing in there two times which skips the first one and used the second one.

    Then after I told him to use a crystal he must of commented out the CONFIG OSC = INTIO67 one more mess.

    And Jon you need to remember you wrote this
    If MrDeb is using andy's InternalOscillator.bas and this at Start of code the chip will work fine
    Code (text):
    Device = 18F2420
    Clock = 16
    CONFIG OSC = INTIO67
    Include "InternalOscillator.bas "
    Include "shift.bas"
    Include "utils.bas"
    Include "convert.bas"
    And one more thing @ MrDeb when you commented out code write down why and what for and you'll save yourself a bunch of time figuring what went wrong.
     
    Last edited: Nov 23, 2012
  19. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,798
    Likes:
    134
    Location:
    morristown,tn
    And Jon this will not even compile
    Code (text):
    Device = 18F2420
    Clock = 32
    Config OSC = INTIO67
    OSCCON = %01111100 // Sets up the internal oscillator
    OSCTUNE.6 = 1  // Enables PLL
    Why OSCCON = %01111100 OSCTUNE.6 = 1 can't be set before your Module are included
    That's why people started putting these setting in a module to set them as a work around for swordfish
    And one More thing I pointed this out a long time ago and then there started a wave of INtOSC.bas to set these setting even pointed this out to GRAM That his LCD sample didn't run for almost 30 minutes because of the way Swordfish handled modules.
     
  20. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    I should start commenting on the comment out sections of code. I have a crystal installed but will try the internal osc again but use the 16 as well as suggested.
    I hopefully will stir clear of any further clock screw-ups. Will try out what Burt suggested before going any further. Oh by the way I have an LED that blinked at what seemed the correct 1 second interval while I had the internal OSC setup.
    Meanwhile the lone ranger is back at the ranch racking his balls------------------playing pool
    I ran into another conflict as well as discovered why I was getting color mixing.
    I wanted to use an interrupt to change from SUB LEFT to SUB RIGHT. But I have all of portB connected to the High Side driver.
    Before I make a bigger mess, I was contemplating just using two other port pins, say PortA.0 and PortA.1. If A.1 goes LOW then SUB RIGHT, if A.1 goes LOW then SUB LEFT.
    In simple terms, can an interupt be implemented on most any other Port pin besides PortB.0,1 or 2?
     
  21. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,798
    Likes:
    134
    Location:
    morristown,tn
    PortB is the only port interrupt on change and that for inputs What makes you think you need that. And there is 4 pins on that chip that have interrupt on change
     

Share This Page