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 gatesphere, markey1979, jsolarski and 1 other 4 Quote 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.