;******************************************************************************
; *
; Filename: 16F88Test.asm *
; Date: 13 May 2011 *
; File Version: 1.0 *
; *
; Author: Chris Fourie *
; *
;******************************************************************************
; *
; Notes: _25mS *
; movlw .1 *
; movwf counter0 *
; nop *
; decfsz counter1,f *
; goto $-2 *
; decfsz counter0,f *
; goto $-4 *
; retlw 00 *
; *
; Actually works @ 140mS *
; At least motor turns... *
; *
;******************************************************************************
;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------
LIST p=16F88 ; list directive to define processor
#INCLUDE <P16F88.INC> ; processor specific variable definitions
;------------------------------------------------------------------------------
; CONFIGURATION WORD SETUP
;------------------------------------------------------------------------------
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_OFF & _WDT_OFF & _INTRC_IO
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
;------------------------------------------------------------------------------
; VARIABLE DEFINITIONS
;------------------------------------------------------------------------------
CBLOCK 0x20 ; Sample GPR variable registers allocated contiguously
counter0 ; Counter used for delays
counter1 ; Ditto
delaycnt ; Counter used for setting delays
ENDC
W_TEMP EQU 0x7D ; w register for context saving (ACCESS)
STATUS_TEMP EQU 0x7E ; status used for context saving (ACCESS)
PCLATH_TEMP EQU 0x7F ; variable used for context saving
;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;------------------------------------------------------------------------------
DATAEE ORG 0x2100
DE "MCHP" ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3
;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------
RESET ORG 0x0000 ; processor reset vector
PAGESEL START
GOTO START ; go to beginning of program
;------------------------------------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------
ISR ORG 0x0004 ; interrupt vector location
; Context saving for ISR
MOVWF W_TEMP ; save off current W register contents
MOVF STATUS,W ; move status register into W register
MOVWF STATUS_TEMP ; save off contents of STATUS register
MOVF PCLATH,W ; move pclath register into W register
MOVWF PCLATH_TEMP ; save off contents of PCLATH register
;--------
;User ISR
Count_int
btfsc INTCON, RBIE ;Check for interrupt on RB0
goto count_routine
;--------
Interrupt_exit ;Restore context before returning from interrupt
MOVF PCLATH_TEMP,W ; retrieve copy of PCLATH register
MOVWF PCLATH ; restore pre-isr PCLATH register contents
MOVF STATUS_TEMP,W ; retrieve copy of STATUS register
MOVWF STATUS ; restore pre-isr STATUS register contents
SWAPF W_TEMP,F
SWAPF W_TEMP,W ; restore pre-isr W register contents
RETFIE ; return from interrupt
;-----------------
;Interrupt routine
;-----------------
count_routine
clrf delaycnt
btfsc PORTA,4 ;waits for button press
goto $-1 ;else it loops
count_loop
incf delaycnt, f ;increments the counter
incf PORTA, f ;increments PORTA to show count on LEDs
call Temp ;...2500 operations? aint that too long?
btfss PORTA,4 ;Waits for release
goto $-1
call Temp ;milliseconds...
btfss PORTA,4 ;Tests for release again...
goto count_loop
goto Interrupt_exit
;------------------------------------------------------------------------------
; EQUATES
;------------------------------------------------------------------------------
;I'm using halfsteps, to smooth the turning, otherwise it stutters
TURNA equ b'00000010'
TURNAB equ b'00000110'
TURNB equ b'00000100'
TURNBC equ b'00001100'
TURNC equ b'00001000'
TURNCD equ b'00011000'
TURND equ b'00010000'
TURNDA equ b'00010010'
;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------
START
;Turn interrupts on:
bsf INTCON,INT0IE ;Enables RB0 as interrupt
bsf INTCON,GIE ;Enables interrupt globally
; A
banksel TRISA
movlw b'00010000' ;2,3,4,5 > outputs
movwf TRISA
banksel PORTA
clrf PORTA ;Clears Port A
movlw b'00000101' ;Turns on the lights... RA5 willie werkie(heeltyd aan)
movwf PORTA
; B
banksel TRISB
movlw b'11100001' ;Set bits 0,1,2,3 as outputs
movwf TRISB
banksel PORTB
clrf PORTB ;Clears Port B
loop
movlw TURNA
movwf PORTB
call _10
movlw TURNAB
movwf PORTB
call _10
movlw TURNB
movwf PORTB
call _10
movlw TURNBC
movwf PORTB
call _10
movlw TURNC
movwf PORTB
call _10
movlw TURNCD
movwf PORTB
call _10
movlw TURND
movwf PORTB
call _10
movlw TURNDA
movwf PORTB
call _10
goto loop
;--------------
; Delay routine
;--------------
_1 ;9000 cycles
movlw 0x06
movwf counter0
movlw 0x08
goto Delay_1
_2 ;6000 cycles
movlw 0xAE
movwf counter0
movlw 0x05
goto Delay_1
_3 ;4000 cycles
movlw 0x1E
movwf counter0
movlw 0x04
goto Delay_1
_4 ;2500 cycles
movlw 0xF2
movwf counter0
movlw 0x02
goto Delay_1
_5 ;1600 cycles
movlw 0x3E
movwf counter0
movlw 0x02
goto Delay_1
_6 ;800 cycles
movlw 0x9E
movwf counter0
movlw 0x01
goto Delay_1
_7 ;400 cycles
movlw 0x83
goto Delay_2
_8 ;200 cycles
movlw 0x41
goto Delay_3
_9 ;100 cycles
movlw 0x1F
goto Delay_2
_10 ;20 cycles
retlw 0x00
goto Delay_3
Delay_1
movwf counter1
decfsz counter0, f
goto $+2
decfsz counter1, f
goto $-3
goto $+1
nop
retlw 0x00
Delay_2
movwf counter0
decfsz counter0, f
goto $-1
goto $+1
retlw 0x00
Delay_3
movwf counter0
decfsz counter0, f
goto $-1
retlw 0x00
;temporary routine...
Temp
;993 cycles
movlw 0xC6
movwf counter0
movlw 0x01
movwf counter1
Temp_0
decfsz counter0, f
goto $+2
decfsz counter1, f
goto Temp_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
END