Presentation is loading. Please wait.

Presentation is loading. Please wait.

Applications examples. A binary count : stepped manually and reset with push buttons. Define ports Reset portd Reset =0? INCF portd no Step =0? yes.

Similar presentations


Presentation on theme: "Applications examples. A binary count : stepped manually and reset with push buttons. Define ports Reset portd Reset =0? INCF portd no Step =0? yes."— Presentation transcript:

1 Applications examples

2 A binary count : stepped manually and reset with push buttons. Define ports Reset portd Reset =0? INCF portd no Step =0? yes

3 BTFSC PORTB,2 GOTO START CLRW MOVWFTRISD MOVLW0X06 MOVWFTRISB RESET :CLRF PORTD INCF portd GOTO START START:BTFSS PORTB,1 GOTO RESET Define ports Reset portd RB1 =0? INCF portd no RB2 =0? yes Code for stepped manually binary count

4 Simple home security system Switches are active high; The system works only when ARMED If AWAY is set :all sources of alarms are checked If AWAY is reset: only alarms door & window are checked When the alarm is set on, the system waits for some one to disarm the system

5 Define ports Reset alarm Armed? no Away? no zone1? no zone2? no window? no door? no y y set alarm Armed? y n yes Code for home security

6 START BCF PORTC,0 AGAIN BTFSS PORTB, ARMED; system is armed GOTO AGAIN; BTFSS PORTB, AWAY; no people at home GOTO HOME; people are at home BTFSC PORTD, ZONE1; if no alarm from zone1 GOTO ALARM BTFSC PORTD, ZONE2; if no alarm from zone2 GOTO ALARM HOME BTFSC PORTD, WINDOW; if no alarm from window GOTO ALARM BTFSC PORTD, FRONTDOOR; if no alarm from door GOTO ALARM GOTO AGAIN; if no alarm from any where ALARM BSF PORTC,1 DISABLE_ALARM BTFSC PORTB, ARMED GOTO DISABLE_ALARM GOTO START END Define ports Reset alarm Armed? no Away? no zone1? no zone2? no windo w? no door? no y y set alarm Armed? y n

7 The seven segment display : the "step" botton increments the count on the seven segment display ( 0-F) ;the "reset" resets the count Display digit 0 Is “reset “ =1? Is “step “ =1? Initialize ports Increment the Display Y N

8 count on the seven segment display ( 0-F) -2 Display digit 0 Is “reset “ =1? Is “step “ =1? Initialize ports Increment the Display Y N CLRW MOVWF TRISC BSFTRISD,0 BSFTRISD,1 WAIT MOVLW 0x3F; MOVWFPORTC GOTO main Main BTFSC PORTD, 1 GOTO WAIT Loop1:BTFSS PORTD, 0; GOTO loop1; INCFCNT,1; MovfCNT,0; ANDLW0X0F; CALLshow Table: ADDWFPCL RETLWB'00111111' RETLWB'00000110' RETLWB'01011011' RETLWB'01001111' RETLWB'01100110‘ RETLWB'01101101' RETLWB'01111101' RETLWB'00000111' RETLWB'01111111' RETLWB'01101111' RETLWB'01110111' RETLWB'01111100' RETLWB'00111001' RETLWB'01011110' RETLWB'01111001' RETLWB'01110001' Show: CALLtable MOVWFPORTC RETURN

9 Keypads 1.an array of push buttons connected in rows and columns. 2.each can be tested for closure inputs outputs 1 11 0

10 Keypad connection inputs outputs Initially set high

11 The main program will do the following: 1.set RD4-RD7 high 2.Call scan 3.Call show 4.Loop. main MOVLW 0xFF MOVWF PORTD CALL scan CALL show GOTO main END Write a program that display’s the pressed key on the 7-segment

12 Scan Key=0:cy=1 RD0=0? RD1=0? RD2=0? y RD4=0 INCR KEY RET RD3=1 CY=0? RL PORTD Re-start scanning new row row INCF Key BTFSS PORTD,0 GOTO found INCF Key BTFSS PORTD,1 GOTO found INCF Key BTFSS PORTD,2 GOTO found GOTO next scan CLRF Key BSF 3,0 BCF PORTD,4 newrow GOTO row next BSF PORTD,3 RLF PORTD BTFSC 3,0 GOTO newrow GOTO scan found RETURN next Found y y y

13 Keypad program: the show subroutine show CALL table MOVWF PORTC RETURN table MOVF Key,W ADDWF PCL NOP RETLW B'00001100' RETLW B'10110110' RETLW B'10011110' RETLW B'11001100' RETLW B'11011010' RETLW B'11111010' RETLW B'00001110' RETLW B'11111110' RETLW B'11001110' RETLW B'10010010' RETLW B'01111110' RETLW B'11101100' Code for 1

14 Keypad program row INCF Key BTFSS PORTD,0 GOTO found INCF Key BTFSS PORTD,1 GOTO found INCF Key BTFSS PORTD,2 GOTO found GOTO next table MOVF Key,W ADDWF PCL NOP RETLW B'00001100' RETLW B'10110110' RETLW B'10011110' RETLW B'11001100' RETLW B'11011010' RETLW B'11111010' RETLW B'00001110' RETLW B'11111110' RETLW B'11001110' RETLW B'10010010' RETLW B'01111110' RETLW B'11101100' scan CLRF Key BSF 3,0 BCF PORTD,4 newrow GOTO row next BSF PORTD,3 RLF PORTD BTFSC 3,0 GOTO newrow GOTO scan found RETURN main MOVLW 0FF MOVWF PORTD CALL scan CALL show GOTO main END show CALL table MOVWF PORTC RETURN

15 TRAFFIC LIGHTS Turn on green on light1: red on light 2 Wait 15 sec on the display Turn on green and yellow on light1: red on light 2 Wait 5 sec on the display Turn on green on light2: red on light1 Wait 15 sec on the display Turn on green and yellow on light2: red on light 1 Wait 5 sec on the display


Download ppt "Applications examples. A binary count : stepped manually and reset with push buttons. Define ports Reset portd Reset =0? INCF portd no Step =0? yes."

Similar presentations


Ads by Google