Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Accendere LED con interrupt

Tipologie, strumenti di sviluppo, hardware e progetti

Moderatore: Foto UtentePaolino

0
voti

[21] Re: Accendere LED con interrupt

Messaggioda Foto Utenterudj » 15 feb 2014, 14:21

certo, stasera ti mando tutto
Avatar utente
Foto Utenterudj
25 5
New entry
New entry
 
Messaggi: 80
Iscritto il: 2 gen 2014, 17:31

0
voti

[22] Re: Accendere LED con interrupt

Messaggioda Foto Utenterudj » 16 feb 2014, 0:13

ecco qua, codice e foto:

Codice: Seleziona tutto
PROCESSOR 16F84
RADIX DEC
INCLUDE "P16F84.INC"
ERRORLEVEL -302
__CONFIG 0x3FF1

LED0 EQU 0
LED1 EQU 1
LED2 EQU 2
LED3 EQU 3
SWITCH EQU 0

CBLOCK 0x0c ;dichiarazione variabili
Count:2
ENDC

ORG 0x00
goto start

ORG 0x04 ;interrupt handler
btfsc INTCON,RBIF
goto tastoPremuto

start
bsf STATUS,RP0
movlw B'00000000' ;imposto gli I/O
movwf TRISA
movlw B'00100001'
movwf TRISB

bcf STATUS,RP0  ;spengo i led
clrf PORTA
movlw B'00000000'
movwf PORTA

movlw B'10011000' ;interrupt enable
movwf INTCON

bsf OPTION_REG,INTEDG

mainloop ;attesa dell'interrupt

call Delay
bsf Count,0
goto mainloop

tastoPremuto
call Delay
bcf STATUS,RP0
movf PORTB
btfss PORTA,LED0 ;controlla se i led sono accesi
goto accendi ;se sono spenti li accende...

btfsc PORTA,0
goto spegni ;...altrimenti li spegne



accendi
bsf PORTA,LED0
bsf PORTA,LED1
bsf PORTA,LED2
bsf PORTA,LED3
movlw B'10011000' ;ripristino interrupt
movwf INTCON
retfie

spegni
movlw B'00000000'
movwf PORTA
movlw B'10001000' ;ripristino interrupt
movwf INTCON
retfie

Delay ; delay software
clrf Count
clrf Count+1
DelayLoop
decfsz Count,1
goto DelayLoop
decfsz Count+1,1
goto DelayLoop
return

END
Allegati
piccircuit.jpg
Avatar utente
Foto Utenterudj
25 5
New entry
New entry
 
Messaggi: 80
Iscritto il: 2 gen 2014, 17:31

Precedente

Torna a Realizzazioni, interfacciamento e nozioni generali.

Chi c’è in linea

Visitano il forum: Nessuno e 3 ospiti