Stránka 1 z 1

PIC-Problem s nastavenim portov.

Napsal: 14 pro 2015, 11:24
od dudo02
Zdravim,

Snazim sa naprogramovat casovac,ktory bude ovladat bodovu zvaracku.
Pracujem v MPLABe.
Procesor PIC16F628A.

Mam problem s nastavenim portov A ako vstupnych a to konkretne A0, A1, A2, A3.Planujem na nich napojit pull-upp rezistory.
Program ako je napisany v code funguje korektne pokial sa nepokusim spominane porty v programe pouzit.

V datasheete sa uvadza:



2: On Reset, the TRISA register is set to all
inputs. The digital inputs (RA<3:0>) are
disabled and the comparator inputs are
forced to ground to reduce current
consumption.


Cize pravdepodobnym dovodom preco program blbne je to ze su porty vypnute,popr. to ze su povolene komparatory.
Na a neviem vycitat z datasheetu ako porty zapnut, popr.deaktivovat komparatory, alebo co vlastne robit

Kód: Vybrat vše

; Projekt: Bodovacka
 LIST   p=16F628A          ;type of processor
#INCLUDE   <P16F628A.INC>   ; definitoins

; configguration bits settings
 __CONFIG _PWRTE_ON & _WDT_OFF & _MCLRE_OFF & _BODEN_OFF & _LVP_OFF & _INTRC_OSC_NOCLKOUT

 

; definitions
#DEFINE   OPT    PORTA,2  ;optocoupler
#DEFINE   LED    PORTA,3  ;led
#DEFINE FOOT   PORTA,6  ;foot switch
#DEFINE SW1    PORTB,7  ;SW1-SW11 rotary switch
#DEFINE SW2    PORTB,6
#DEFINE SW3    PORTB,5
#DEFINE SW4    PORTB,4
#DEFINE SW5    PORTB,3
#DEFINE SW6    PORTB,2
#DEFINE SW7    PORTB,1
#DEFINE SW8    PORTB,0
#DEFINE SW9    PORTA,7 
#DEFINE SW10   PORTA,5
#DEFINE SW11   PORTA,4


 CBLOCK 0X20
 D1
 D2
 ENDC


;program
 RESET ORG 0x0000      ; start program on adress 0000h

;inicializacia portov
 BSF STATUS,RP0 
 BCF OPTION_REG, 7   ; enable internal pullups   
 MOVLW b'11110011'   ; RA1,RA2=OUT, rest=IN
 MOVWF TRISA   
 MOVLW b'11111111'   ; RB0-7= all IN
 MOVWF TRISB
 BCF   STATUS,RP0

 GOTO START
    
   
;podprogram DELAY 50ms
DELAY   MOVLW   0x0F
        MOVWF   D1
       MOVLW   0x28
        MOVWF   D2

DELAY_0 DECFSZ   D1, F
       goto   $+2
       decfsz   D2, F
       goto   DELAY_0
;2 cycles
       GOTO   $+1
       RETURN   ; return when if d1=0


;Podprogramy DELAYs
DELAY_50   BSF  OPT
         CALL DELAY
         BCF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BSF  OPT
         CALL DELAY
         CALL DELAY
         BCF  OPT
         RETURN

DELAY_100  BSF  OPT
         CALL DELAY
         BCF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BSF  OPT
         CALL DELAY
         CALL DELAY
         BCF  LED
         RETURN

DELAY_150  BSF  OPT
         CALL DELAY
         BCF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BSF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BCF  OPT
         RETURN

DELAY_200  BSF  OPT
         CALL DELAY
         BCF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BSF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BCF  OPT
         RETURN

DELAY_250  BSF  OPT
         CALL DELAY
         BCF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BSF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BCF  OPT
         RETURN

DELAY_300  BSF  OPT
         CALL DELAY
         BCF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BSF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BCF  OPT
         RETURN

DELAY_350  BSF  OPT
         CALL DELAY
         BCF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BSF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BCF  OPT
         RETURN

DELAY_400  BSF  OPT
         CALL DELAY
         BCF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BSF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BCF  OPT
         RETURN

DELAY_450  BSF  OPT
         CALL DELAY
         BCF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BSF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BCF  OPT
         RETURN

DELAY_500  BSF  OPT
         CALL DELAY
         BCF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BSF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BCF  OPT
         RETURN

NON_STOP   BSF  OPT
         CALL DELAY
         BCF  OPT
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         CALL DELAY
         BSF   OPT
         BTFSS FOOT
         GOTO  $-1
         BCF   OPT
         RETURN
   
;main program
START   BSF     LED
        CALL    DELAY
       BCF     LED
       CALL    DELAY
       CALL    DELAY
       CALL    DELAY
       CALL    DELAY
       CALL    DELAY
       CALL    DELAY
       CALL    DELAY
       CALL    DELAY
       BCF     LED
      BTFSC   FOOT
       GOTO    START

       BTFSS   SW1         
       CALL    DELAY_50

       BTFSS   SW2
       CALL    DELAY_100

       BTFSS   SW3
       CALL    DELAY_150

       BTFSS   SW4
       CALL    DELAY_200

       BTFSS   SW5
       CALL    DELAY_250

       BTFSS   SW6
       CALL    DELAY_300

       BTFSS   SW7
       CALL    DELAY_350

       BTFSS   SW8         
       CALL    DELAY_400

       BTFSS   SW9              
        CALL    DELAY_450
      
        BTFSS   SW10
        CALL    DELAY_500


        BTFSS   SW11
        CALL    NON_STOP


       BTFSS   FOOT
       GOTO    $-1
       GOTO    START      
      
        END
   

Napsal: 14 pro 2015, 11:44
od mikollar
Mas to priamo v katalogu

Kód: Vybrat vše

CLRF PORTA ;Initialize PORTA by
;setting
;output data latches
MOVLW 0x07 ;Turn comparators off and
MOVWF CMCON ;enable pins for I/O
;functions
BCF STATUS, RP1
BSF STATUS, RP0 ;Select Bank1
MOVLW 0x1F ;Value used to initialize
;data direction
MOVWF TRISA ;Set RA<4:0> as inputs
;TRISA<5> always
;read as ‘1’.
;TRISA<7:6>
;depend on oscillator
;mode

Napsal: 14 pro 2015, 21:20
od dudo02
Vdaka, programovat zacinam a nebol som si isty. Funguje to,tak ako ma.

Napsal: 16 pro 2015, 20:20
od petrfilipi
Je to v datasheetu na straně 54 - viz obrázek. Musíš nastavit bity 0,1,2 registru CMCON na 1, abys měl PortA jako digitální.

PF