Nah! doesn't sound Harsh at all...all y'all are RIGHT!!! I must learn the 'simulation' ASAP...just that Im in a panic mode right now...OK, sorry if this sounds a bit harsh, I'll still help you but I won't be doing any simulating after this.
I've found one bug, you are changing tmr0_cnt2 in the delay33ms section so nothing is happening.
I've made a video of me simulating it and finding the bug, I suggest you should watch it as soon as you have time (link when I've uploaded it). It shows how easy it is, and if you are going to be making a robot you need to learn the simulator first, it's too complicated to work on without the simulator and you would never finish it in time.
;******************************************************************
; *
; 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
swnew ; switch "new press" flags
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
;******************************************************************
; 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
;
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
;
; 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 ___---___---___---___ active hi switch sample
; swold ____---___---___---__ switch state latch
; wreg ___-__-__-__-__-__-__ changes, press or release
; wreg ___-_____-_____-_____ filter out 'release' bits
;
movf PORTB,W ; sample active high 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)
;
movlw 1000000/756%256 ; |B0
movwf countlo ; |B0
movlw 1000000/756/256 ; |B0
movwf counthi ; |B0
tone661
movlw 1<<piezo ; bit mask for piezo spkr (RA0) |B0
xorwf PORTA,F ; toggle piezo spkr output |B0
DelayCy(756*usecs-11) ; precise 756 usec loop time |B0
movf countlo,W ; |B0
skpnz ; |B0
decf counthi,F ; |B0
decf countlo,F ; |B0
movf countlo,W ; check for 1-second elapsed |B0
iorwf counthi,W ; has tone been on for 1 second? |B0
skpz ; yes, skip, else |B0
goto tone661 ; branch |B0
;
; generate a 496-Hz tone for 1 second (toggle the piezo speaker
; at 1008-usec intervals 992 times)
;
movlw 1000000/1008%256 ; # intervals for 1 second |B0
movwf countlo ; |B0
movlw 1000000/1008/256 ; |B0
movwf counthi ; |B0
tone496
movlw 1<<piezo ; bit mask for piezo spkr (RA0) |B0
xorwf PORTA,F ; toggle piezo spkr output |B0
DelayCy(1008*usecs-11) ; precise 1008 usec loop time |B0
movf countlo,W ; |B0
skpnz ; |B0
decf counthi,F ; |B0
decf countlo,F ; |B0
movf countlo,W ; check for 1-second elapsed |B0
iorwf counthi,W ; has tone been on for 1 second? |B0
skpz ; yes, skip, else |B0
goto tone496 ; branch |B0
goto loop ; 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
Are you using a pull-up or pull-down resistor for the button?You are right...panic mode all the time!
I just tried your code but there is no response! I assume the push botton is the problem...I also realize I did not ground the push button when trying with previous code!
Okay, so with a pull-up resistor, it means you're looking for the pin to go low. When the pin goes low, it means the switch is pressed. I haven't read the code all the way through, because to be perfectly honest, I don't really understand itI think it 'pullup' it the same configuration I use all the time!
one end of resistor goes to + and the other end goes to pushbutton pin & RB7
the other pin of pushbutton goes to gnd!
this configuration works on my other circuit.... *getting stressed##
I think I got to take a break with this and study my exam...will get back to it in 2 hours...but will keep on checking posts..
it unbeleivable how I am wasting time on a little project like this!
loop
DelayCy(16*msecs) ; 16-msec 'debounce' intervals |B0
;
; K8LH parallel switch state logic (using "new press" filter)
;
; wreg ___---___---___---___ active hi switch sample
; swold ____---___---___---__ switch state latch
; wreg ___-__-__-__-__-__-__ changes, press or release
; wreg ___-_____-_____-_____ filter out 'release' bits
;
movf PORTB,W ; sample active hi 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
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
LOL...Okay, so with a pull-up resistor, it means you're looking for the pin to go low. When the pin goes low, it means the switch is pressed. I haven't read the code all the way through, because to be perfectly honest, I don't really understand it
So my question is, in the code, did you tell the interrupt to "trip" when the pin reads a 1, or when it reads a 0?
yep! the resistor is external!I didn't see you turn on the internal pull-up resistors in your code so you must be using an external pull-up resistor???