Lizard787 4 Posted December 22, 2010 Share Posted December 22, 2010 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 markey1979, bluehash, gatesphere and 1 other 4 Quote Link to post Share on other sites
bluehash 1,581 Posted December 22, 2010 Share Posted December 22, 2010 Nice - Assembly code, Havent seen that for quite a while. Thanks for your submission. Quote Link to post Share on other sites
simpleavr 399 Posted December 23, 2010 Share Posted December 23, 2010 RLA.B R12 just curious, is there a way to do rotate on a 8bit or 16bit unsigned int in 'C'? i always needs that and don't know how to. anyone? Quote Link to post Share on other sites
Lizard787 4 Posted December 23, 2010 Author Share Posted December 23, 2010 I don't know C, but you could try << or >>. That might work. Quote Link to post Share on other sites
simpleavr 399 Posted December 23, 2010 Share Posted December 23, 2010 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. Quote Link to post Share on other sites
JMLB 24 Posted January 20, 2011 Share Posted January 20, 2011 I tired to interface my NES controller with the Launch pad. I thought It was a voltage issue, I should try the code see if it works. I could have wrote bad code (not likely just kidding). you didn't come into any voltage problems did you? Quote Link to post Share on other sites
Lizard787 4 Posted January 24, 2011 Author Share Posted January 24, 2011 No I didn't have any problems with voltage. According to the Datasheet for the 4021 IC it can run as low as 3 volts. I used the VCC and GND pins for powering the NES Controller. Quote Link to post Share on other sites
JMLB 24 Posted January 25, 2011 Share Posted January 25, 2011 I see. Mine was just a epoxy blob and so was my snes controller. I might not have a knock off. I bought it from ebay not too long ago. Quote Link to post Share on other sites
markey1979 4 Posted January 26, 2011 Share Posted January 26, 2011 @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............ Quote Link to post Share on other sites
JMLB 24 Posted January 26, 2011 Share Posted January 26, 2011 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. Quote Link to post Share on other sites
cde 334 Posted January 26, 2011 Share Posted January 26, 2011 @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. Quote Link to post Share on other sites
markey1979 4 Posted January 26, 2011 Share Posted January 26, 2011 @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............. Quote Link to post Share on other sites
JMLB 24 Posted January 27, 2011 Share Posted January 27, 2011 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. Quote Link to post Share on other sites
JMLB 24 Posted January 27, 2011 Share Posted January 27, 2011 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 Quote Link to post Share on other sites
cde 334 Posted January 27, 2011 Share Posted January 27, 2011 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.// Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.