Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "p16f873a.inc"
- ; CONFIG
- ; __config 0xFFFB
- __CONFIG _FOSC_EXTRC & _WDTE_OFF & _PWRTE_OFF & _BOREN_ON & _LVP_ON & _CPD_OFF & _WRT_OFF & _CP_OFF
- RES_VECT CODE 0x0000 ; processor reset vector
- STATUS equ 03h
- porta equ 05h
- trisa equ 85h
- portb equ 06h
- trisb equ 86h
- FSR equ 04h
- INDF equ 00h
- full equ 7Fh
- aux equ 7Eh
- aux1 equ 7Dh
- i equ 7Ch
- j equ 7Bh
- min equ 7Ah
- tmp equ 79h
- num1 equ 78h
- num2 equ 77h
- GOTO START ; go to beginning of program
- ; TODO ADD INTERRUPTS HERE IF USED
- MAIN_PROG CODE ; let linker place main program
- START
- ;SETUP
- bsf STATUS, 5 ;Entrando no banco 1
- movlw b'01111111'
- movwf trisb ;Seta os pinos RB1 a RB7 como input
- movlw b'11111111'
- movwf trisa ;Seta todos os pinos do banco a como input
- ;Medida de seguranca, recomendando pela
- ;microchip
- bcf STATUS, 5 ;Voltando ao banco 0
- ;Codigo
- MOVLW 20h ;Endereço inicial para array
- MOVWF FSR
- MOVWF full ;Para ele iterar 32 vezes
- MOVF portb,w ;Lê porta b
- MOVWF aux ;e joga o valor em aux
- Filll:
- MOVWF INDF ;Coloca valor na lido na posição de memória sendo indicada pelo FSR
- INCF FSR ;Passa para o endereço da frente
- DECFSZ full ;Decrementa full e verifica se ja foi os 32 elementos
- GOTO LerP ;Vai ler o próximo elemento
- GOTO Sort ;Passa para o método sort se sim
- LerP:
- MOVF portb,w
- MOVWF aux1 ;Guarda novo valor em aux1 para não perder
- ANDWF aux ;Compara valor que foi lido com o valor anterior, se igual: w = 11111111
- MOVWF aux
- INCF aux,0 ;Incrementa aux e joga em w, se igual, w valendo 0 agora
- BTFSC STATUS, 2 ;Verifica bit zero para verificar resultado anterior e pula caso for 0
- GOTO LerP ;Valor lido igual o anterior, tenta ler de novo
- MOVF aux1,w ;Joga o novo valor guardado anteriormente lido de volta a W
- GOTO Filll ;Passa para o próximo elemento
- Sort:
- MOVLW 20h
- MOVWF i
- fori:
- MOVF i,w
- MOVWF min
- MOVWF j
- INCF j
- forj:
- ;num[j]
- MOVF j,w
- MOVWF FSR
- MOVF INDF,w
- MOVWF num1
- ;num[min]
- MOVF min,w
- MOVWF FSR
- MOVF INDF,w
- ;MOVWF num2
- ;if num1[j] < num[min]
- SUBWF num1,w
- BTFSS STATUS,0
- GOTO Eforj
- MOVF j,w
- MOVWF min
- Eforj:
- INCF j
- MOVLW 40h ;30 (62)
- SUBWF j,w
- BTFSS STATUS,0
- GOTO forj
- ;if (i != min)
- MOVF i,w
- ANDWF min,w
- MOVWF aux
- INCF aux,w
- BTFSC STATUS, 2
- GOTO Efori
- ;tmp = num[i]
- MOVF i,w
- MOVWF FSR
- MOVF INDF,w
- MOVWF tmp
- ;num1 = num[min]
- MOVF min,w
- MOVWF FSR
- MOVF INDF,w
- MOVWF num1
- ;num[i] = num[min]
- MOVF i,w
- MOVWF FSR
- MOVF num1,w
- MOVWF INDF
- ;num[min] = aux
- MOVF min,w
- MOVWF FSR
- MOVF tmp,w
- MOVWF INDF
- Efori:
- INCF i
- MOVLW 3Fh ;29 (61)
- SUBWF i,w
- BTFSS STATUS,0
- GOTO fori
- MOVF i
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement