Assembly JOYSTICK+UART+ADC

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.3 kB
2
Indexable
Never
    LIST P=PIC18F4321 H=INHX32 ;CHRISTIAN HASKO
    #INCLUDE <P18F4321.INC>
    
    CONFIG OSC = HSPLL
    CONFIG PBADEN = DIG
    CONFIG WDT = OFF
    
    ORG 0X0000
    GOTO MAIN
    ORG 0X0008
    RETFIE FAST
    ORG 0X0018
    RETFIE FAST
    
    LEIDO EQU 0X00
    
    CONFIG_PORTS
    
	SETF ADCON1,0 ;PUERTO A DIGITAL
	CLRF TRISD,0
	CLRF LATD,0
	
	CLRF LEIDO,0
	
	BSF TRISC,6,0
	BSF TRISC,7,0
    
    RETURN
    
    CONFIG_ADC
    
	MOVLW B'00001101'
	MOVWF ADCON1,0
	
	MOVLW B'0000110'
	MOVWF ADCON2,0
	
	BSF ADCON0,ADON,0
	
	;ADCON0 SE CONFIGURA TODO EL RATO PARA EL CANAL QUE QUERAMOS OBTENER!
    
    RETURN
    
    CONFIG_UART
    
	;9600 BPS A 40MHZ
	
	;FORMULAS:
	;   64 --> DIVISOR: 64.10   --> 9615.38
	;   16 --> DIVISOR: 259.41  --> 9615.38
	;   4  --> DIVISOR: 1040.66 --> 9596.92 !! BRG16 = 1, BRGH = 1
	
	MOVLW B'00100100'
	MOVWF TXSTA,0
	
	MOVLW B'10010000'
	MOVWF RCSTA,0
	
	MOVLW B'00001000'
	MOVWF BAUDCON,0
	
	MOVLW HIGH(.1041)
	MOVWF SPBRGH,0
	
	MOVLW LOW(.1041)
	MOVWF SPBRG,0
    
    RETURN
    
    MAIN
    
	CALL CONFIG_PORTS
	CALL CONFIG_UART
	CALL CONFIG_ADC
    
    LOOP
    
	MOVLW B'00000111'
	MOVWF ADCON0,0
	
    ESPERAX
    
	BTFSC ADCON0,1,0
	GOTO ESPERAX
	MOVFF ADRESH,LEIDO
	
    ESPERATX
    
	BTFSS PIR1, TXIF,0
	GOTO ESPERATX
	MOVFF LEIDO,W
	MOVFF W, TXREG
	
	;MOVLW .92
	;CPFSLT LATC,0
	;GOTO PUTZEROX ;POR ENCIMA DE 102 -> CENTRO
	
	;MOVLW .66
	;CPFSLT LATC,0
	;GOTO FIRST_LEFT;POR ENCIMA DE 76 -> FIRST
	
	;MOVLW .41
	;CPFSLT LATC,0
	;GOTO SECOND_LEFT;POR ENCIMA DE 51 -> SECOND
	
	MOVLW .1
	CPFSLT LEIDO,0
	GOTO THIRD_LEFT
	
	GOTO FULL_LEFT;POR DEBAJO DE 25 -> FULL
	
	
    PUTZEROX
    
	BSF LATD,3,0
	BCF LATD,0,0
	BCF LATD,1,0
	BCF LATD,2,0
	BCF LATD,4,0
	BCF LATD,5,0
	BCF LATD,6,0
	GOTO LOOP
	
    FIRST_LEFT
    
	BSF LATD,2,0
	BCF LATD,0,0
	BCF LATD,1,0
	BCF LATD,3,0
	BCF LATD,4,0
	BCF LATD,5,0
	BCF LATD,6,0
	GOTO LOOP
	
    SECOND_LEFT
    
	BSF LATD,0,0
	BCF LATD,3,0
	BCF LATD,1,0
	BCF LATD,2,0
	BCF LATD,4,0
	BCF LATD,5,0
	BCF LATD,6,0
	GOTO LOOP
	
    THIRD_LEFT
    
	BSF LATD,6,0
	BCF LATD,0,0
	BCF LATD,1,0
	BCF LATD,2,0
	BCF LATD,4,0
	BCF LATD,5,0
	BCF LATD,3,0
	GOTO LOOP
	
    FULL_LEFT
    
	BSF LATD,5,0
	BCF LATD,0,0
	BCF LATD,1,0
	BCF LATD,2,0
	BCF LATD,4,0
	BCF LATD,3,0
	BCF LATD,6,0
	GOTO LOOP
	
	
    GOTO LOOP
    END