ciao a tutti
sto cercando di creare un dimmer a due canali comandabile sia da pulsante che da 485
per farlo sto usando un pic16f873a e il picbasic
ho praticamente finito ma ho un piccolo problema... riesco a fare le rampe di salita e discesa correttamente usando portb.0 per per lo "zero crossing" e il tmr0 e tmr1 per il conteggio per l'accensione e funzionano. appena però comunico con la la luce sfarfalla. come se non agganciasse un interrupt correttamente. ovviamente ho fatto tutta la gestione degli interrupt in assembler ma non cambia nulla
vi allego il sorgente così magari mi aiutate...
'Variables for saving state in interrupt handler wsave VAR BYTE $70 system ' Saves W ssave VAR BYTE bank0 system ' Saves STATUS psave VAR BYTE bank0 system ' Saves PCLATH fsave VAR BYTE bank0 system ' Saves FSR
PROTBUFFER_SIZE CON 30
PROTREAD0 VAR BYTE[30] PROTOUT0 VAR BYTE[30] PROTOUTLEN var word PROTINDEX VAR BYTE bank0 PROTINDEX_OUT VAR BYTE bank0 BUFFRECEIVE VAR BYTE bank0
errflag VAR BYTE bank0 ' Error flag
'' Define interrupt handler 'DEFINE INTHAND myint
GoTo EndInterrupt ' Skip around interrupt handler
' Assembly language INTERRUPT handler MY_INT_HANDLER: Asm myint
; Save the FSR value for later
movf FSR, W ; Move FSR to W movwf fsave ; Save FSR
btfss pir1,5 GoTo TESTLAMP
comm ; Find in which bank the compiler put buffer, and set IRP IF (_PROTREAD0 > 0FFh) ; Find the bank where buffer is located bsf STATUS,IRP ; If bank 2 or 3 set IRP Else bcf STATUS,IRP ; If bank 0 or 1 clear IRP EndIF
; Check for hardware overrun error btfsc RCSTA,OERR ; Check for usart overrun GoTo usart_err ; jump to assembly error routine ; Test for buffer overrun clrf _BUFFRECEIVE; clrf _PROTTIMEOUT; incf _PROTINDEX, W ; Increment index_in to W subwf _PROTBUFFER_SIZE-1, W ; Subtract indexes to test for buffer overrun btfsc STATUS,Z ; check for zero (index_in = index_out) GoTo buffer_err ; jump to error routine if zero
; Increment the index_in pointer and reset it if it's outside the ring buffer incf _PROTINDEX, F ; Increment index_in to index_in movf _PROTINDEX, W ; Move new index_in to W sublw _PROTBUFFER_SIZE-1 ; Subtract index_in from buffer_size-1
; Set FSR with the location of the next empty location in buffer movlw Low _PROTREAD0 ; Get the location of buffer[0] addwf _PROTINDEX, W ; Add index_in to point to next empty slot movwf FSR ; Store pointer in FSR
; Read and store the character from the USART movf RCREG, W ; Read the received character movwf INDF ; Put the received character in FSR location
bcf pir1,5 bsf _BUFFRECEIVE,1
movf fsave, W ; retrieve FSR value movwf FSR ; Restore it to FSR
goto finished
TESTLAMP btfss intcon,1 GoTo TESTLAMP0
bcf pir1,0 bsf intcon,5 bsf intcon,6 bcf Intcon,1 bcf Intcon,2
movf _DIMM0VAL,W movwf TMR0
movf _DIMM1VALL,W movwf TMR1L movf _DIMM1VALH,W movwf TMR1H
bcf _DIMM0 bcf _DIMM1
goto finished
TESTLAMP0
btfss intcon,2 GoTo TESTLAMP1
bcf Intcon,2 btfss _DIMM_ENABLED,0 GoTo finished
bsf _DIMM0 goto finished TESTLAMP1
bcf pir1,0 btfss _DIMM_ENABLED,1 GoTo finished
bsf _DIMM1 goto finished
; Restore FSR, PCLATH, STATUS and W registers finished
;btfsc pir1,5 ;GoTo comm
btfsc intcon,1 GoTo TESTLAMP
btfsc intcon,2 GoTo TESTLAMP0
btfsc pir1,0 GoTo TESTLAMP1
;bsf intcon,7 retfie ; Return from the interrupt ; Error routines buffer_err ; Jump here on buffer error bsf _errflag,1 ; Set the buffer flag usart_err ; Jump here on USART error bsf _errflag,0 ; Set the USART flag movf RCREG, W ; Trash the received character GoTo finished ; Restore state and return to program
EndAsm
vi ringrazio e se avete dubbi chiedete pure. grazie ciao Marco