Correct.  Click on the instructions, pull everything apart, and try again.



Creating a Program-2


Page 29
INDEX

The only way to learn programming is with examples. One of our opposition companies claimed that a teacher was the the best way to learn. But where is the average electronics student going to find a competent teacher, versed in PIC microcontroller programming, on a Sunday afternoon or 10PM at night!
The web covers the world and the emails we receive proves this. By simply going over the work with lots of examples, the  concepts will become clearer and clearer. 
Here is an extension of the example on the previous page.  Study the program and re-create it by dragging the instructions to the program.   

EXPERIMENT 1b
Turning on a LED for 0.5sec - with debounce
This experiment turns on a LED for 0.5 sec when button "A" is pressed. The LED does not turn on when the button is released. In the previous experiment the LED turned on when the button was released because the micro picked up the noise from the switch and activated the program. 
The secret is the very short delay 7x256uS at Main 1. This is just long enough to cover the time when the switch is being released. Release the switch very slowly and you will see the LED illuminate. This proves the delay is covering the noise from the release of the switch. 

                  ;Expt1b.asm
                  ;Project: LED on for 0.5sec with debounce
List P = 16F84
#include <p16F84.inc>
__CONFIG 1Bh    ;_CP_OFF & _PWRTE_ON & _WDT_OFF & _RC_OSC

SetUp








Delay






Main



Main1













Main2
ORG 0
BSF 03,5
CLRF 06
MOVLW 01
MOVWF 05
BCF 03,5
CLRF 1F
CLRF 06
GOTO Main

NOP
DECFSZ 1A,1
GOTO Delay
DECFSZ 1B,1
GOTO Delay
RETURN

BTFSS 05,0
GOTO Main2
BTFSC 1F,0
GOTO Main
NOP
NOP
NOP
NOP
DECFSZ 1A,1
GOTO Main1
BTFSS 05,0
GOTO Main2
BSF 06,0
CALL Delay
CALL Delay
BCF 06,0
BSF 1F,0
GOTO Main
BCF 1F,0
GOTO Main

END
;This is the start of memory for the program.
;Go to Bank 1
;Make all port B output
;Load W with 0000 0001
;Make RA0 input
;Go to Bank 0 - the program memory area.
;Clear the button-press file
;Blank the display


;Create approx 250mS delay






;Test the input line on port A
;Button not pressed
;Button pressed first time?
;Button already pressed




;Create short delay
;Look again
;Is switch still pressed?
;It was only noise
;Turn on LED
;Illuminate for 250mS
;Illuminate for 250mS
;Turn off LED
;Set button-press flag
;Loop Main
;Clear button-press flag
;Loop Main

 

NEXT