Jump to content
43oh

NES Controller


Recommended Posts

The program reads an NES Controller. The Data pin is connected to P1.0, the latch pin is connected to P1.1 and the Clock Pin is connected to P1.2. I'm using the controller adapter from parallaxhttp://www.parallax.com/Store/Accessories/HumanInterfaceDevices/tabid/822/CategoryID/90/List/0/SortField/0/Level/a/ProductID/613/Default.aspx to hook up the controllers. After it is done reading the controller it jumps to the subroutine "Finished".

The inputs are stored in Register 12 which goes:

A B Select Start UP DOWN LEFT RIGHT

1 is pressed, 0 is unpressed.

#include "msp430.h"                     ; #define controlled include file

       NAME    main                    ; module name

       PUBLIC  main                    ; make the main label vissible
                                       ; outside this module
       ORG     0FFFEh
       DC16    init                    ; set reset vector to 'init' label

       RSEG    CSTACK                  ; pre-declaration of segment
       RSEG    CODE                    ; place program in 'CODE' segment

init:   MOV     #SFE(CSTACK), SP        ; set up stack
                                       ;42 If Button Press
main:   CLR.B &P1DIR                    ;41 If No Button Press
       BIS.B #7Fh, &P1DIR                             ; main program
       ADD.B #7Fh, &P1DIR
       CLR.B &P1OUT
       BIS.B #02h, &P1OUT ;Latch Up
       CLR R4
       CLR R13 ;Button State
       CLR R12 ;All values stored
       CLR R5 ;Counter
       BIS.B &P1IN, R13 ;Gets data1 status ;02 is button pressed 03 is not
       BIS.B #03h, R4 ;Math to get button status
       SUB.B R13, R4
       CLR.B &P1OUT
       CMP.B #01h, R4 ;Compare values
       JNE NextButton
       ADD.B #01h, R12
NextButton: ;67 althogether (A pressed) 15 or 16
       INC.B R5 ;Counter
       CMP #08h, R5 ;Checks How many times loop has run
       JEQ Finished ;Insert To whereever you want to go after inputs read
       CLR R13 ;Reset
       CLR R4
       RLA.B R12 ;Rotate for new value
       ADD.B #04h, &P1OUT ;Clock High
       BIS.B &P1IN, R13 ;Gets INput
       CLR.B &P1OUT;Clock Low
       CMP.B #04h, R13
       JNE NextButton
       ADD.B #01h, R12
       JMP NextButton
       END 

When I tested it I connected four LEDS on pins P1.4 to P1.7 and added the code. Since I only added four led's it only outputs either the multi directional button presses or the normal(A B Start Select) button. IF you try this code make sure you erase the END command on the first section of code i posted.

Finished:
       CMP #10h, R12
       JLO Displaay
       BIS.B R12, &P1OUT
       JMP main
Displaay:
       RLA.B R12
       RLA.B R12
       RLA.B R12
       RLA.B R12
       BIS.B R12, &P1OUT
       JMP main
       END

EDIT: Optimized the code(Removed 1 instruction). EDIT 2: Removed another instruction

Link to post
Share on other sites

thanks Lizard787,

 

the << >> will do shifts but it would be neat if i can do rotate (w/o drop off the last bit on the other side). of course it can be add back to achieve rotate, but it means more instructions, in assembler it's a native instruction and looks like it does no take more than one cycle.

Link to post
Share on other sites
  • 4 weeks later...

At first I was trying with the snes (on my project) then I tried the nes when it was not working. I checked it last night and I have a knock off nes controller. It looks the same but does not have Nintendo written on it. I opened it up an it has an epoxy blob and the parts and pcb look kinda recent.

Link to post
Share on other sites
@jmlb

 

Are you trying it with a NES controller or an SNES controller. I dkn if they are different, but I would venture to say they are...........

 

I would also like to say, this is pure genius. I have the NES controller apart on the bench right now............

 

Only difference is that SNES controllers are logically, two nes controllers. That is to say, they spit out 16 bits of serial data per control, while NES controllers spit out 8 bits. Inside, the snes is just two of the same nes chips, chained together like you would a decade counter.

Link to post
Share on other sites

@jmlb

 

Yea...........

I bought the discovery board also, but STmicro has horrible information for noobs like me. TI, in general, seems to be more geared towards education of their products and, I think that Microchip could be a close second.

 

I finally progressed far enough with school to get into a programming class, so soon I should be able to impliment some cool ideas that I have been toying around. Right now I can only design the hardware, like I have been doing since the earily 90's.

 

I really do like this nes controller port, and I am sorry that it does not work with your system, but I think that I will try to port this through the tusb4130 so I can use an original nes controller on my emulator. Then I can relive my childhood all orer again. I am using an original nes controller, and I have a destroyed nes to use for parts to get the connector from. When I was younger I fried the system board while trying to clean the cart connector. I shorted some wires together and "poof" it let the smoke out.

 

Live and learn.............

Link to post
Share on other sites
I bought the discovery board also, but STmicro has horrible information for noobs like me.

 

I found the STM32 kinda hard to use so I decided to document my learning process. I wrote a blog about it if you are interested. It guides you threw setting up a project and make an echo of a serial port.

 

as for this snippet, I have not tried it. I was asking because I am working on a similar project. I will test your code next time I get the chance. I was curious if you came across a similar problem.

Link to post
Share on other sites

Only difference is that SNES controllers are logically, two nes controllers. That is to say, they spit out 16 bits of serial data per control, while NES controllers spit out 8 bits. Inside, the snes is just two of the same nes chips, chained together like you would a decade counter.

 

 

They are pretty much 2 parallel load shit registers. but really my official snes controller is just a epoxy blob so I can't tell what voltage they can take. I had the Idea of switching the chip with a lower voltage compatible one but I was disappointed to see it was just a blob lol

Link to post
Share on other sites

Only difference is that SNES controllers are logically, two nes controllers. That is to say, they spit out 16 bits of serial data per control, while NES controllers spit out 8 bits. Inside, the snes is just two of the same nes chips, chained together like you would a decade counter.

 

 

They are pretty much 2 parallel load shit registers. but really my official snes controller is just a epoxy blob so I can't tell what voltage they can take. I had the Idea of switching the chip with a lower voltage compatible one but I was disappointed to see it was just a blob lol

SNES and NES, and pretty much everything of that era was 5v. Try driving it at 3.5v or 3.6v (5v*0.7) and see if it works. If not, the function/chip is so basic you could just get a off the shelf shift register, or make one from a msp430.

 

Pinout of the chip, and of the controller.

http://kyorune.com/modding/article.php?id=14

//Apparently, the NES IC is a 4021 CMOS 8-bit Shift register, and the SNES uses a 16-bit Shift Register (2 4021's cascaded together), with 12 enabled.//

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...