; This is the test one for the PIC Nintendo joystick ; ; ; Written by:Steven Easley ; Email: seasley@robotdungeon.com ; Webpage: www.robotdungeon.com ; ; ; LIST p=16F84a INCLUDE "p16f84a.inc" __CONFIG _PWRTE_ON & _HS_OSC & _WDT_OFF & _CP_OFF errorlevel -302 ; The defines #DEFINE clock PORTA,0 ;Red wire from controller #DEFINE dat PORTA,1 ;Yellow wire from controller #DEFINE perser PORTA,2 ;Orange wire from controller ;Define the outputs that goto the CMOS switches #DEFINE right PORTB,0 #DEFINE left PORTB,1 #DEFINE up PORTB,2 #DEFINE down PORTB,3 #DEFINE but_A PORTB,4 #DEFINE but_B PORTB,5 #DEFINE select PORTB,6 #DEFINE start PORTB,7 cblock 0x14 current counter Endc ;Define ram locations org 0 goto init ;Setup stuff init bsf STATUS, RP0 movlw b'00000010' movwf TRISA clrf TRISB bcf STATUS, RP0 clrf PORTB clrf PORTA ;This is the main program main ;Nobuttons prossed default is b'00000101' call readdat call scan_dat goto main scan_dat chk_right ;check right btfss current,0 goto right_pressed bsf right goto chk_left right_pressed bcf right chk_left ;check left btfss current,1 goto left_pressed bcf left goto chk_down left_pressed bsf left chk_down ;check down btfss current,2 goto down_pressed bsf down goto chk_up down_pressed bcf down chk_up ;check up btfss current,3 goto up_pressed bcf up goto chk_start up_pressed bsf up chk_start ;check start btfss current,4 goto start_pressed bcf start goto chk_select start_pressed bsf start chk_select ;check select btfss current,5 goto select_pressed bcf select goto chk_but_B select_pressed bsf select chk_but_B ;check but_B btfss current,6 goto but_B_pressed bcf but_B goto chk_but_A but_B_pressed bsf but_B chk_but_A ;check but_A btfss current,7 goto but_A_pressed bcf but_A goto end_scan but_A_pressed bsf but_A end_scan return readdat bcf clock bcf perser bsf perser bsf clock bcf clock bcf perser movlw d'8' movwf counter movlw d'0' getbits bcf STATUS, C btfsc dat bsf STATUS, C rlf current, w movwf current bsf clock bcf clock decfsz counter,f goto getbits return end