Salve a tutti, Sto riscontrando effetti di glitching sulle uscite associate ai registri PORTA, PORTB e PORTC di un PIC 16F870. Il codice che effettua la scrittura su quelle porte =E8 il seguente:
SCL_UP EQU H'0020' SCL_DN EQU H'0021' SDA_ORG EQU H'0022' TBYTE EQU H'0023' LAMP1 EQU H'0024' LAMP2 EQU H'0025' T_LAMP1 EQU H'0026' T_LAMP2 EQU H'0027' TEMPB EQU H'0028' TEMPC EQU H'0029'
ORG 00H ;PORTA -> LEDS + BUTTON ;PORTB -> DATA (SDA) ;PORTC -> CLOCK (SCK)
BCF STATUS,7 ;disable all interrupts
BSF STATUS,5 ;Switch to Bank 1 MOVLW b'00000111' ;set Porta pins to digital MOVWF ADCON1 ;i/o (instead of analogical) MOVLW b'00000001' ;Set the Port A pins MOVWF TRISA ;to output (except RA0). BSF STATUS,5 ;Switch to Bank 1 again (NOT NECESSARY?) MOVLW b'00000000' ;Set Port B to output MOVWF TRISB ; BSF STATUS,5 ;Switch to Bank 1 again (NOT NECESSARY?) MOVLW b'00000000' ;Set Port C to output MOVWF TRISC ; BCF STATUS,5 ;switch back to Bank 0
MOVLW d'5' MOVWF SCL_UP MOVLW d'5' MOVWF SCL_DN MOVLW d'150' MOVWF LAMP1 MOVLW d'150' MOVWF LAMP2 MOVF LAMP1,0 ;COPIO LAMP1 E LAMP2 IN T_LAMP1 E T_LAMP2 MOVWF T_LAMP1 MOVF LAMP2,0 MOVWF T_LAMP2 MOVLW B'00000000' ;inizializzo il regitro degli indirizzi MOVWF TBYTE CLRW
;Ciclo Principale RESTART BSF PORTA,2 ;accendo RA2 (Led VERDE) CALL GENERIC_DELAY BCF PORTA,2 ;spengo RA2 BTFSS PORTA,0 ;se RA0 =E8 UP -> Cominicia GOTO RESTART BCF PORTA,2 ;GOTO (ALTRO_CODICE_NON_POSTATO_MA_SICURAMENTE_NON_SIGNIFICATIVO)
;Loop Led Lampeggio GENERIC_DELAY CLRW DLY_GEN DECFSZ LAMP1,1 GOTO DLY_GEN DECFSZ LAMP2,1 GOTO DLY_GEN ;RICARICO LAMP1 E LAMP2 MOVF T_LAMP1,0 MOVWF LAMP1 MOVF T_LAMP2,0 MOVWF LAMP2 RETURN
Su RA0 c'=E8 un interruttore che seleziona l'ingresso posto a massa oppure quello a +5V, Su RA2 c'=E8 un led Il problema si verifica in questa forma: do tensione al circuito e il led comincia a lampeggiare (come previsto) ma nello stesso tempo si accende, senza un'apparente criterio, anche il led posto su RA3 o RA1 (che per=F2 non lampeggia). Problemi analoghi mi sono capitati anche spostando i led su PORTB e PORTC (e cambiando opportunamente il circuito). Aggiugo che:
1) il circuito =E8 montato su breadboard 2) i led sono collegati PIN---ANODO....CATODO---RESISTENZA (1Kohm