Help implementing SNES Controller + PIC1F887


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Welcome to the forum.

    Is that the whole code posted? I do not see how this will work
    Code:
     SHIFTIN PORTC.2, PORTC.0, LSBPRE,[theoutput \16]             ' Shift in socket 1 data 
      LCDOUT $FE, 1, BIN16 dasresult             ' Display values
    I do not see "dasresult " as a VAR or how you are going from "theoutput" to "dasresult".
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Sep 2010
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Oops, thats a mistake from when I was cleaning it up to post, the revised code is below XD

    Code:
    Include "modedefs.bas"
    	
    	OSCCON = %01110000 ' INTRC = 8MHz
    
    	DEFINE OSC 8
    
    
            DEFINE LCD_DREG PORTB       ' Set LCD Data port
            DEFINE LCD_DBIT 0           ' Set starting Data bit (0 or 4) if 4-bit bus i.e, PortD.4-PORTD.7
            DEFINE LCD_RSREG PORTD      ' Set LCD Register Select port
            DEFINE LCD_RSBIT 2          ' Set LCD Register Select bit i.e, PORTC.5
            DEFINE LCD_EREG PORTD       ' Set LCD Enable port
            DEFINE LCD_EBIT 4           ' Set LCD Enable bit i.e, PORTE.4
            DEFINE LCD_BITS 8           ' Set LCD bus size ot 4 bit Upper Nibble (4 or 8 bits)
            DEFINE LCD_LINES 4          ' Set number of lines on LCD to 4 Lines
            DEFINE LCD_COMMANDUS 2000   ' Set command delay time in us
            DEFINE LCD_DATAUS 50        ' dSet data delay time in us
    	DEFINE LCD_RWREG PORTD
    	DEFINE LCD_RWBIT 3
    
    
    
     
    theoutput	var	Word
    
    ANSEL = 0
     
    PAUSE 1000                                        ' Wait a second 
    
    OUTPUT PORTC.1         ' configure input/output pins
    OUTPUT PORTC.0
    INPUT PORTC.2
    
     
    LOW PORTC.1                                             ' Initialize LATCH 
    LOW PORTC.0                                             ' Initialize CLK 
     
    Loop:                                                ' Main loop 
     
      PULSOUT PORTC.1, 10                                   ' Latch the data 
    
      SHIFTIN PORTC.2, PORTC.0, MSBPRE,[theoutput \16]             ' Shift in socket 1 data 
    	
      LCDOUT $FE, 1, BIN16 theoutput             ' Display values 
    
    
    
    pause 50
     
    GOTO Loop
    END                                              ' Repeat main loop
    The only issue that remains is that my timing is not precise enough and I'm losing a lot of the button press bits. I think the only solution is purchasing a crystal as the internal oscillator is not accurate enough.
    Last edited by Daguava; - 7th September 2010 at 23:23.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I have not used one of those controllers..
    The internal OSC should be accurate enough, the speed might be the issue.
    You are pushing buttons while data is being sent to the display or looping for the next call???

    Would be nice to push the data from the controller instead of calling for it. Is there some way to have a signal going to a PORTB interrupt?
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Sep 2010
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Oh wow, I feel so stupid, but I've just solved my own problem. Undervolting the shift-register inside of the controller by a half volt was enough to cause it to freak out giving me incomplete output, my code now works as expected and everything is working great.

    Thanks for the help, and, if you wouldn't mind, could you elaborate a bit on what you meant by the PortB interrupt, I've done very little with interrupts and don't quite get what you mean.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Glad it is working.

    PORTB has an interrupt on change. When the state of PORTB.0 changes an interrupt can be triggered.

    An example would be counting parts on a conveyor. The MCU can be off doing something else like sending data to a display while a sensor/switch is activated as a part passes by. Then when the MCU is finished with the display the part count can be increases.
    That is using PBP interrupts. If you go with ASM or Darrel Taylor's instant interrupts then the trigger is instantly. But you still need a certain amount of time for everything to happen.

    Either way, you do not need to loop back and check the state of the pin, it happens for you in the background.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts