ripkars
Junior Member level 1
porta portb portc
Hi all,
I'm encountering glitching/artifact effects on the output latches associated to PORTA, PORTB and PORTC registers of a PIC 16F870.
The code which writes to those ports is:
On RA0 there is a switch that selects the start input (0V / +5V),
On RA2 there's a led
The problem is: I turn on the circuit and set the switch to +5V and it starts blinking (as it should) but at the same time it turns on, without an apparent reason, also led on RA3 or RA1 (which insetad stays turned on fixed, it does not blink).
Similar problems happened putting other leds on PORTB and PORTC (and obviously changing the circuit/software.
I add that:
1) the circuit is built over a breadboard
2) the leds are linked in the following manner: PIN---ANODE....CATODE---RESISTOR(1Kohm<R<3Kohm)---GND
3) the oscillator is a RC one(10kohm/100pf)
Thanks to everyone who will partecipate to this discussion,
Riccardo
(P.S.: please excuse my bad english...)
Hi all,
I'm encountering glitching/artifact effects on the output latches associated to PORTA, PORTB and PORTC registers of a PIC 16F870.
The code which writes to those ports is:
Code:
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
MOVWF T_LAMP1
MOVF LAMP2,0
MOVWF T_LAMP2
MOVLW B'00000000' ;initialize address register
MOVWF TBYTE
CLRW
;Main cycle
RESTART
BSF PORTA,2 ;turn on RA2 (Led GREEN)
CALL GENERIC_DELAY
BCF PORTA,2 ;turn off RA2
BTFSS PORTA,0 ;if RA0 is UP -> begin
GOTO RESTART
BCF PORTA,2
;GOTO (OTHER_CODE_NOT_POSTED_BUT_FOR_SURE_NOT_IMPORTANT)
;Loop Blinking Led
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
On RA0 there is a switch that selects the start input (0V / +5V),
On RA2 there's a led
The problem is: I turn on the circuit and set the switch to +5V and it starts blinking (as it should) but at the same time it turns on, without an apparent reason, also led on RA3 or RA1 (which insetad stays turned on fixed, it does not blink).
Similar problems happened putting other leds on PORTB and PORTC (and obviously changing the circuit/software.
I add that:
1) the circuit is built over a breadboard
2) the leds are linked in the following manner: PIN---ANODE....CATODE---RESISTOR(1Kohm<R<3Kohm)---GND
3) the oscillator is a RC one(10kohm/100pf)
Thanks to everyone who will partecipate to this discussion,
Riccardo
(P.S.: please excuse my bad english...)