tmr0_int bcf INTCON, T0IF ; clear flag
delay1s decfsz tmr0_cnt1, f ; decrement interrupts count
goto delay33ms ;
movlw 245 ; reload count
movwf tmr0_cnt1 ; reset tmr0_cnt1 for 501.76msecs
decfsz tmr0_cnt2, f ; decrement interrupts count
goto delay33ms ;
movlw 2 ; reload count
movwf tmr0_cnt2 ; reset tmr0_cnt for 1003.52msecs
bsf t1000ms ; set '1 second' flag for main program
clrf T2CON ; stop/clear timer2
movlw 1<<GIE|1<<T0IE ;
movwf INTCON ; enable global & TMR0 interrupts
;******************************************************************
; *
; Filename: Sim Door Bell.asm *
; Author: Mike McLaren, K8LH *
; (C)2012: Micro Application Consultants *
; Date: 30-Sep-12 *
; *
; 16F690 (8-MHz INTOSC) Door Bell Demo' *
; *
; *
; MPLab: 8.84 (tabs=8) *
; MPAsm: 5.44 *
; *
;******************************************************************
#include <p16f690.inc>
radix dec
list st=off
errorlevel -302,-224
;--< config fuses >------------------------------------------------
__config _FCMEN_OFF& _IESO_OFF& _MCLRE_OFF& _WDT_OFF& _INTOSCIO
; _FCMEN_OFF ; -- fail safe clock monitor enable off
; _IESO_OFF ; -- int/ext switch over enable off
; _BOR_ON ; default, brown out reset on
; _CPD_OFF ; default, data eeprom protection off
; _CP_OFF ; default, program code protection off
; _MCLR_OFF ; -- use MCLR pin as digital input
; _PWRTE_OFF ; default, power up timer off
; _WDT_OFF ; -- watch dog timer off
; _INTOSCIO ; -- internal osc, OSC1 and OSC2 I/O
;--< variables >---------------------------------------------------
cblock 0x20
swold ; switch state latch
delayhi ; DelayCy() subsystem variable
countlo ;
counthi ;
endc
;--< constants >---------------------------------------------------
#define piezo 0 ; bit index for piezo spkr on RA0 pin
#define button 7 ; bit index for button on RB7 pin
;==================================================================
; K8LH DelayCy() subsystem macro generates four instructions =
;==================================================================
radix dec
clock equ 8 ; 4, 8, 12, 16, 20 (MHz), etc.
usecs equ clock/4 ; cycles/microsecond multiplier
msecs equ clock/4*1000 ; cycles/millisecond multiplier
DelayCy macro delay ; 11..327690 cycle range
movlw high((delay-11)/5)+1
movwf delayhi
movlw low ((delay-11)/5)
call uDelay-((delay-11)%5)
endm
;==================================================================
; K8LH Tone(frequency,duration) Macro =
;==================================================================
radix dec
tone macro freq,duration
local loop
movlw (duration/(500000/freq))%256
movwf countlo ;
movlw (duration/(500000/freq))/256
movwf counthi ;
loop movlw 1<<piezo ;
xorwf PORTA,F ; toggle piezo spkr pin
DelayCy(500000/freq*usecs-11)
movf countlo,F ;
skpnz ;
decf counthi,F ;
decf countlo,F ;
movf countlo,W ;
iorwf counthi,W ;
skpz ;
goto loop ;
endm
;******************************************************************
; reset vector *
;******************************************************************
org 0x000
v_reset
clrf STATUS ; force bank 0 and IRP = 0 |B0
goto init ; |B0
;******************************************************************
; interrupt vector *
;******************************************************************
org 0x004
v_interrupt
;******************************************************************
; main init *
;******************************************************************
init
bsf STATUS,RP1 ; bank 2 |B2
clrf ANSEL ; turn off ADC for digital I/O |B2
clrf ANSELH ; |B2
;
; configure INTOSC for 8-MHz
;
bcf STATUS,RP1 ; bank 0 |B0
bsf STATUS,RP0 ; bank 1 |B1
movlw b'01110000' ; setup INTOSC for 8-MHz |B1
movwf OSCCON ; |B1
stable btfss OSCCON,HTS ; osc stable? yes, skip, else |B1
goto stable ; loop (wait until stable) |B1
;
; configure I/O ports
;
bcf OPTION_REG,7 ; enable pull-ups |B1
clrf TRISA ; port A all outputs |B1
movlw 1<<button ; bit index for switch on RB7 |B1
movwf TRISB ; all others outputs |B1
clrf TRISC ; port C all outputs |B1
bcf STATUS,RP0 ; bank 0 |B0
clrf PORTA ; clear port A output latches |B0
clrf PORTB ; clear port B output latches |B0
clrf PORTC ; clear port C output latches |B0
;
bsf STATUS,RP1 ; bank 2 |B2
bsf WPUB,WPUB7 ; enable RB7 (button) pull-up |B2
bcf STATUS,RP1 ; bank 0 |B0
;
; initialize program variables
;
clrf swold ; clear switch state latch |B0
;******************************************************************
; main loop *
;******************************************************************
loop
DelayCy(16*msecs) ; 16-msec 'debounce' intervals |B0
;
; K8LH parallel switch state logic (using "new press" filter)
;
; wreg ___---___---___---___ inverted active lo sample
; swold ____---___---___---__ switch state latch
; wreg ___-__-__-__-__-__-__ changes, press or release
; wreg ___-_____-_____-_____ filter out 'release' bits
;
comf PORTB,W ; sample active lo switches |B0
andlw b'10000000' ; on the RB7 pin only |B0
xorwf swold,W ; changes, press or release |B0
xorwf swold,F ; update switch state latch |B0
andwf swold,W ; filter out 'release' bits |B0
skpnz ; a new press? yes, skip, else |B0
goto loop ; branch (wait for input) |B0
;
; generate a 1-second 661-Hz tone (toggle the piezo speaker at
; 756-usec intervals 1322 times)
;
tone 661,1000000 ; 661-Hz tone for 1000000 usecs |B0
;
; generate a 496-Hz tone for 1 second (toggle the piezo speaker
; at 1008-usec intervals 992 times)
;
tone 496,1000000 ; 496-Hz tone for 1000000 usecs |B0
goto loop ; |B0
;******************************************************************
; K8LH DelayCy() 16-bit uDelay (11..327690 cycle) subroutine *
;******************************************************************
nop ; entry for (delay-11)%5 == 4 |B0
nop ; entry for (delay-11)%5 == 3 |B0
nop ; entry for (delay-11)%5 == 2 |B0
nop ; entry for (delay-11)%5 == 1 |B0
uDelay addlw -1 ; subtract 5 cycle loop time |B0
skpc ; borrow? no, skip, else |B0
decfsz delayhi,F ; done? yes, skip, else |B0
goto uDelay ; do another loop |B0
return ; |B0
;******************************************************************
end
I know from teaching that almost every student have some kind of strange reluctance against using debugger/simulator tools in programming. I do not know why. At the lab then a program is not working as expected they just ask for help. And our young apprentice Eric is no exception at all. It is always more easy to help. If you are given some basic information. Say something like this. I have placed a breakpoint in the ISR. But it looks like this breakpoint is not reachedI still think you should use Mplab Simulator. The time it takes to learn it will save you lots of time. If you watch these and apply it you will probably be further ahead on the project by the end of the day than if you don't.
http://www.youtube.com/watch?v=pnkUOL0mmyA
http://www.youtube.com/watch?feature=endscreen&NR=1&v=T3OQsgAqdZs
You could probably have saved half an hour just now by putting a breakpoint in the interrupt, and seeing that it didn't happen.
So if the next one is due in 14 days, you're probably going to wait for 13 days before starting it, right (grin)?Thanks All and on to the next one!
thanks!Congrats' Eric. Happy to hear you did good...
Hahahahaa... you know me well...So if the next one is due in 14 days, you're probably going to wait for 13 days before starting it, right (grin)?
Regards, Mike...
by Jake Hertz
by Duane Benson
by Jake Hertz
by Duane Benson