Pwm with Pic 16f84

Only available on StudyMode
  • Pages : 6 (426 words )
  • Download(s) : 888
  • Published : July 30, 2010
Open Document
Text Preview
#include

CBLOCK0X0C
BAND
;P_ON
CONT
P_OFF
W_AUX
S_AUX
TEMP1
TEMP2
ENDC

ORG0X00
GOTOMAIN

;-------------------INTERRUPÇÃO-----------
ORG0X04

MOVWFW_AUX
SWAPFSTATUS,W
MOVWFS_AUX
MOVLW0XFF
XORWFPORTA,1;INVERTE A SAIDA

CALLBANDEIRA
CALLINVERTE
BCFINTCON,2
SWAPFS_AUX,W
MOVWFSTATUS
SWAPFW_AUX,F
SWAPFW_AUX,W
RETFIE

;-----------------MAIN----------------------
MAIN
BSFSTATUS,RP0
BCFTRISA,0;SAÍDA PWM
BCFTRISB,5
BCFTRISB,4
BSFTRISB,6;CONF. RB6 COMO BOTOEIRA 1
BSFTRISB,7;CONF. RB7 COMO BOTOEIRA 2
MOVLW0X05;HABILITA PULL-UP,CONF.PRE-ESCALA P/TMR0
MOVWFOPTION_REG;
BCFSTATUS,RP0
BSFPORTA,0
MOVLW0X00
MOVWFBAND
MOVLW0XE8
MOVWFCONT

;-----------------ROTINA PRINCIPAL-------------
MOVFCONT,0
MOVWFTMR0
MOVLWB'10100000'
MOVWFINTCON
BTFSCPORTB,6;BT1 PRESSIONADA?
GOTO$+3;NÃO,
CALLBT1_SIM;SIM,
GOTO$-3
CALLBT1_NAO
GOTO$-5

;-----------------BT1_NAO---------------
BT1_NAO
BTFSCPORTB,7;BT2 PRESSIONADA?
RETURN;NAO,MANTEM CONT
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY

MOVLW0XD6
XORWFCONT,0
BTFSCSTATUS,2
GOTO$+5
BCFPORTB,5
DECFCONT,1;SIM,VÁ PARA DIREITA
BCFPORTB,4
GOTO$+3
BSFPORTB,4
RETURN
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
RETURN

;----------------BT1_SIM--------------------
BT1_SIM
BTFSCPORTB,7;BT2 PRESSIONADA?
GOTO$+6;NAO,VÁ PARA ESQUERDA
BCFPORTB,4
BCFPORTB,5
MOVLW0XE7;SIM,FAÇA CONT=12
MOVWFCONT
RETURN

CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY

MOVLW0XFB;FIM PARA ESQUERDA
XORWFCONT,0;SE AUMENTAR MAIS A ESQ VAI
BTFSCSTATUS,2
GOTO$+5
BCFPORTB,4
INCFCONT,1
BCFPORTB,5
GOTO$+3
BSFPORTB,5
RETURN
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
CALLDELAY
RETURN

;------------------INVERTE-----------------
INVERTE
MOVLW0X01
XORWFBAND,0
BTFSSSTATUS,2
GOTO$+9

MOVFCONT,0
MOVWFP_OFF
COMFP_OFF,1
INCFP_OFF,1
MOVLW0XFF
ADDWFP_OFF,0
MOVWFTMR0
RETURN

MOVFCONT,0
MOVWFTMR0
RETURN

;---------------------BANDEIRA---------
BANDEIRA
MOVLW0X00
XORWFBAND,0
BTFSSSTATUS,2
GOTO$+4
MOVLW0X01
MOVWFBAND
RETURN
MOVLW0X00
MOVWFBAND
RETURN
;-----------------DELAY--------------
DELAY
MOVLW0X00
MOVWFTEMP1
MOVWFTEMP2
DECFTEMP2,1
BTFSCSTATUS,2
GOTO$-2
DECFTEMP1,1
BTFSSSTATUS,2
GOTO$-5
RETURN

END
tracking img