Code:
'****************************************************************
'* Name : pic controlled power supply *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 11/09/2015 *
'* Version : 1.0 *
'* Notes : pic18f452 10mhz x 4 pll = 40 MHZ *
'****************************************************************
';Program Configuration Register 1H
@ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HSPLL_OSC_1H
';Program Configuration Register 2L
@ __CONFIG _CONFIG2L, _BOR_OFF_2L & _BORV_20_2L & _PWRT_ON_2L
';Program Configuration Register 2H
@ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
';Program Configuration Register 3H
@ __CONFIG _CONFIG3H, _CCP2MX_OFF_3H
';Program Configuration Register 4L
@ __CONFIG _CONFIG4L, _STVR_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
';Program Configuration Register 5L
@ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
';Program Configuration Register 5H
@ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
';Program Configuration Register 6L
@ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
';Program Configuration Register 6H
@ __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
';Program Configuration Register 7L
@ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
';Program Configuration Register 7H
@ __CONFIG _CONFIG7H, _EBTRB_OFF_7H
' ***************************************************************************
DEFINE OSC 40 ' XTAL= 10 MHZ CLOCK= 40 MHZ
INCLUDE "MODEDEFS.BAS"
include "dt_ints-14.bas"
include "REENTERPBP.bas"
CNT VAR WORD ' COUNTER TO BE DISPLAYED ON TERMINAL
CNT= 32000
CNTOLD VAR WORD
CNTOLD=32000
counter VAR WORD
counter= 32000
' DEBUG INTERFACE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'' Set Debug pin port ________________________________________
DEFINE DEBUG_REG PORTD
'' Set Debug pin bit _________________________________________ PIC_PIN_30
DEFINE DEBUG_BIT 7
'' Set Debug baud rate _________________________________________
DEFINE DEBUG_BAUD 115200
'' Set Debug mode: 0 = true, 1 = inverted ______________________
DEFINE DEBUG_MODE 1
DEBUG 13,10,13,10, " PROGRAM IS STARTING...", 13, 10, 13, 10
ADCON1=7 ' all digital !
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RBC_INT, _enc_isr, PBP, NO
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
'@ INT_ENABLE RBC_INT ; enable external (INT) interrupts
ev VAR BYTE BANK0
TMP VAR BYTE BANK0
enca VAR portb.4
encb VAR portb.5
TRISA = 255
lata.0=1
tmp = portb ;; read portb to establish pin change status
INTCON=$C8 ; enable RBC_INT and clear rbcif
Main:
PAUSE 1000
gosub get_cnt:
IF counter <> CNTOLD THEN
DEBUG DEC CNT,13,10
CNTOLD=counter ENDIF
GOTO Main
enc_isr:
ev=ev<<2 ;shift last reading into position
ev=ev|((portb&48)>>4) ;read enc pins 4+5 mask off others then combine this reading with last reading
LOOKUP (ev&$f),[0,255, 1, 0, 1, 0, 0, 255, 255, 0, 0, 1, 0, 1, 255, 0],tmp ;lookup the decision matrix
if tmp then ; decide to inc , dec or ignore
if tmp.7 then
cnt=cnt-1
else
cnt=cnt+1
endif
endif
intcon.0=0 ; clean up and exit
@ INT_RETURN
get_cnt: ; cnt is not atomic this is needed to avoid rollover miss reads
intcon.3=0
counter=cnt
intcon.3=1
return
Bookmarks