+ Reply to Thread
Page 2 of 3
First 1 2 3 Last
Results 16 to 30 of 39

Thread: switch how do you save the key press

  1. #16
    3v0
    3v0 is online now
    3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent
    Join Date
    Jul 2006
    Location
    USA
    Posts
    6,464
    Blog Entries
    11

    Default

    Have you tried Swordfish Basic ! It requires an 18F which are dirt cheap compared to a stamp.

    Microcontrollers | Newark.com This is a list of the through hole parts. The higher pin count parts are SMDs.

    Everyone needs to understand the machine at assembler level but as you said it can be slow.

    Quote Originally Posted by be80be View Post
    I'll try it that way It looks better then what I came up with. If it was a stamp I be done
    but it would of cost me $50.00 for the stamp. I like the $1.10 for the 12f683 I'm going to get this assembly language one bit at a time maybe lol thanks all
    Last edited by 3v0; 7th February 2009 at 12:57 PM.
    Please post questions to the forums. PM's are for personal communication.

    BCHS/3v0's Tutorials
    Junebug USB PIC programmer kit., USB Bit Whacker,
    The 15 Minute Printed Circuit Board! (+drill time)


  2. #17
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    make a simulas card and set your inputs the way you want them

  3. #18
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    I just ordered about 10 PIC18F1220-I/P and 2 PIC18F4450-I/P last night I used mikrobasic but you have to buy it to code any thing big 50 words limit i'm going to try Swordfish Basic
    now.

  4. #19
    russ_hensel Newbie
    Join Date
    Jan 2009
    Location
    South Dartmouth, Ma
    Posts
    42

    Default

    Quote Originally Posted by be80be View Post
    I'll try it that way It looks better then what I came up with. If it was a stamp I be done
    but it would of cost me $50.00 for the stamp. I like the $1.10 for the 12f683 I'm going to get this assembly language one bit at a time maybe lol thanks all
    You do not have to use a stamp to use basic or other higher language. See the SourceBoost series of compilers. Free for up to 2k programs, quite reasonable for unlimited.

    Russ

  5. #20
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    Thanks all just tried this to read the buffer
    Code:
     
           	cblock 0x20
        KeyBuffer:4
        Keys
        Previous
    	sGPIO 
    	d1
    	d2
    	lock
    	lock1
    	lock2
    	lock3
    	lockopen
    	SaveKeyPress 
    	endc
    		org   	0x0000      	; org sets the origin, 0x0000
            goto    Start   		; go to beginning of program 
    		org	  	0x0004			;interrupt vector
    		goto 	Start
    
    Start		
    
    		movlw   07h            		; Set GPIO <2:0) to
                    movwf   CMCON0          	; digital I/O
    		clrf   	ANSEL           	        ; digital I/O
    		movlw   b'1110101'
                    movwf   OSCCON          	;8MHz internal oscillator
    		movlw	b'001111'
    		banksel	TRISIO
    		movwf	TRISIO
    		banksel	GPIO
    		clrf	GPIO	  
    		
    
    
    		clrf	Previous
    		movlw	KeyBuffer
    		movwf	FSR
    KeyLoop		
    		call	Delay10mS	;debounce delay
    		movfw	Keys		;keep copy of previous keys
    		movwf	Previous
    		movfw	GPIO		;get key state
    		xorlw	0xff		;1 = key pressed
    		movwf	Keys		;save for later
    		xorwf	Previous,W	;find keys that have changed
    		andwf	Keys,W		;and are currently pressed
    		btfsc	STATUS,Z	
    		goto	KeyLoop
    		movwf	INDF		;store the key
    		incf	FSR,f		;move pointer forward
    		movfw	FSR		    ;see if we have 4 keys yet
    		xorlw	KeyBuffer+4
    		btfss	STATUS,Z
    		goto	KeyLoop
      if Keys==0xB            ;If config==0xB is true,
            banksel GPIO      ;set to bank 0 GPIO
            bsf     GPIO,GP5  ;make led come on GP5
    	goto	Main	  ;let main program run
      else
            goto    KeyLoop   ;if not a mach go back and cheack buffer
      endif
    
    
    ;here KeyBuffer will contain 4 key values.
    Main:      ; what happens when you get it unlocked 
    
    
    Delay10mS                         ; delay W x 10ms
          		;9998 cycles
    	movlw	0xCF
    	movwf	d1
    	movlw	0x08
    	movwf	d2
    Delay_0
    	decfsz	d1, f
    	goto	$+2
    	decfsz	d2, f
    	goto	Delay_0
    
    			;2 cycles
    	goto	$+1
      
    
            return				
    
    
    
    	END                       ; directive 'end of program'
    

  6. #21
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    You do not have to use a stamp to use basic or other higher language. See the SourceBoost series of compilers. Free for up to 2k programs, quite reasonable for unlimited.
    I Know I just haven't found what i like. And I don't think i should start with just
    basic or C I want to learn assembly I would of had hi-tech C I like it. But I lost my Job thay close the plant I worked at. Can't buy it now lol. I'm going to try SourceBoost
    It looks good thank you russ and Swordfish Basic when my pic18f's get here

  7. #22
    russ_hensel Newbie
    Join Date
    Jan 2009
    Location
    South Dartmouth, Ma
    Posts
    42

    Default More on SourceBoost

    SourceBoost also has a C, a C++ and more. All pretty much the same deal. I think they work on the 16 and 18 chips ( not optimized for the 18 ). Take a look at BoostC tiny Wiki - Open Circuits if you choose C, or maybe just for info if you do not.

  8. #23
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    Some thing like this
    Code:
    	list      p=12F683        ; list directive to define processor
    	#include <p12F683.inc>    ; processor specific variable definitions
    
    	errorlevel  -302          ; suppress message 302 from list file
    
    	__CONFIG   _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT 
    
    ; '__CONFIG' directive is used to embed configuration word within .asm file.
    ; The lables following the directive are located in the respective .inc file.
    ; See data sheet for additional information on configuration word settings.
    
          	cblock 0x20
       		InBuffer
    		combo1
    		combo2
    		combo3
    		combo4
    		dbctr
    		swlatch
                    NoGo
    		d1
    		d2
    
    	endc
    		org   	0x0000      	; org sets the origin, 0x0000
            goto    Start   		; go to beginning of program 
    		org	  	0x0004			;interrupt vector
    		goto 	Start
    
    Start		
    
    		movlw   07h            		; Set GPIO <2:0) to
                    movwf   CMCON0          	; digital I/O
    		clrf   	ANSEL           	        ; digital I/0
    		movlw	b'001111'
    		banksel	TRISIO
    		movwf	TRISIO
    		banksel	GPIO
    		clrf	GPIO	  
    
    getinput
            movlw   InBuffer        ; 4 character input buffer address
            movwf   FSR             ; FSR = &InBuffer
    getnext
            call    getbutton       ; get a button press
            movwf   INDF            ; add to buffer (1, 2, 4, or 8)
            incf    FSR,F           ;
            movlw   InBuffer+4      ;
            xorwf   FSR,W           ; all 4 buttons added?
            bnz     getnext         ; no, branch, else,
    chkcombo
            movf    InBuffer+0      ; W = InBuffer[0]
            xorlw   combo1          ; same as combination key 1?
            bnz     NoGo              ; no, branch, else
            movf    InBuffer+1      ; W = InBuffer[1]
            xorlw   combo2          ; same as combination key 2?
            bnz     NoGo              ; no, branch, else
            movf    InBuffer+2      ; W = InBuffer[2]
            xorlw   combo3          ; same as combination key 3?
            bnz     NoGo             ; no, branch, else
            movf    InBuffer+3      ; W = InBuffer[3]
            xorlw   combo4          ; same as combination key 4?
            bnz     NoGo            ; no, branch, else
    ;
    ;  we've got a good combo
    ;
    getbutton
            movlw   20              ; reset debounce counter
            movwf   dbctr           ; to 20 msecs
    dbdelay 
            call      DelayCy         ; use 1 msec sample interval
            comf    GPIO,W          ; sample active low switches
            andlw   0x0F            ; sample only b3..b0 bits
            xorwf   swlatch,W       ; a difference (press or release)?
            bz      getbutton       ; no, branch (reset), else
            decfsz  dbctr,f         ; debounced? yes, skip, else
            goto    dbdelay         ; sample again
            xorwf   swlatch,F       ; update debounced switch state latch
            andwf   swlatch,W       ; a debounced "new press"?
            bz      getbutton       ; no, branch (a "new release"), else
            return                  ; returns W = 1, 2, 4, or 8
    
    DelayCy			;998 cycles
    		movlw	0xC7
    		movwf	d1
    		movlw	0x01
    		movwf	d2
    Delay_0
    		decfsz	d1, f
    		goto	$+2
    		decfsz	d2, f
    		goto	Delay_0
    
    			;2 cycles
    		goto	$+1
    
    
    	END                       ; directive 'end of program'
    
    I need a delay named DelayCy
    Last edited by be80be; 7th February 2009 at 10:22 PM.

  9. #24
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    I tried it like Pommie I'll see how this works
    Code:
    	list      p=12F683        ; list directive to define processor
    	#include <p12F683.inc>    ; processor specific variable definitions
    
    	errorlevel  -302          ; suppress message 302 from list file
    
    	__CONFIG   _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT 	
    	cblock 0x20
    		KeyBuffer:4
    		Keys
    		Previous
    		codevalue
    		d1
    		d2
    	endc
    	org   	0x0000      	; org sets the origin, 0x0000
            goto    main   		; go to beginning of program 
    		org	  	0x0004			;interrupt vector
    		goto 	main
    	
    main
    		movlw   07h            		; Set GPIO <2:0) to
                    movwf   CMCON0          	; digital I/O
    		clrf   	ANSEL           	; digital I/0
    		movlw	b'001111'
    		banksel	TRISIO
    		movwf	TRISIO
    		banksel	GPIO
    		clrf	GPIO	  
    		clrf	Previous
    		movlw	KeyBuffer
    		movwf	FSR
    		movlw	b'1001'
    		movwf	codevalue
    open
    		call   	KeyLoop
                    subwf  	codevalue, W      ; is it same as code?
                    btfss  	STATUS, Z         ; zero set if yes
                    goto   	open
                    call 	ledOn         ; frist thing to do
                    goto 	open
    
    KeyLoop		
    		call	Delay10mS	;debounce delay
    		movfw	Keys		;keep copy of previous keys
    		movwf	Previous
    		movfw	GPIO		;get key state
    		xorlw	0xff		;1 = key pressed
    		andlw	0x0f		;keep only 0-3 bits  <-added
    		movwf	Keys		;save for later
    		xorwf	Previous,W	;find keys that have changed
    		andwf	Keys,W		;and are currently pressed
    		btfsc	STATUS,Z	
    		goto	KeyLoop
    		movwf	INDF		;store the key
    		incf	FSR,f		;move pointer forward
    		movfw	FSR		    ;see if we have 4 keys yet
    		xorlw	KeyBuffer+4
    		btfss	STATUS,Z
    		goto	KeyLoop
    ;here KeyBuffer will contain 4 key values.
    ledOn
    		banksel	GPIO		;turn on led on GP5
    		bsf     GPIO,GP5 
    		 
    
    
    
    Delay10mS		        	;9998 cycles
    		movlw	0xCF
    		movwf	d1
    		movlw	0x08
    		movwf	d2
    Delay_0
    		decfsz	d1, f
    		goto	$+2
    		decfsz	d2, f
    		goto	Delay_0
    
    			;2 cycles
    	goto	$+1
    
     end
    
    I wish I was smarter. more of my mom would of helped lol
    Last edited by be80be; 8th February 2009 at 01:19 AM.

  10. #25
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    Well I'm still dum as a coal bucket I don't think this part is right how do I load the value to compare
    Code:
    		movlw	b'1001'
    		movwf	codevalue
    open
    		call   	KeyLoop
                    subwf  	codevalue, W      ; is it same as code?
                    btfss  	STATUS, Z         ; zero set if yes
                    goto   	open
                    call 	ledOn         ; frist thing to do
                    goto 	open
    

  11. #26
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,807

    Default

    You code is going to crash as you have subroutines without a return, especially the delay routine. When it has completed the delay it will continue executing the code after it which is just empty space. Whenever you call a piece of code it has to have a return instruction to go back to the instruction after the calling instruction. See this page.

    Mike.
    Last edited by Pommie; 9th February 2009 at 03:29 AM.

  12. #27
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    Thanks that's a good site. I played a little with my code last night and found where it was getting lost at the delay I added the return like you said. I found a lock that use's a 16f84
    on picklist but i gave away all my 16f84 and that code would be hard to port to the 12f683
    it save's the key press to porta. It help with the buffer I think I'm getting it 1 bit at time.
    Thanks agin Mike for the help

  13. #28
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,807

    Default

    I just had a play with your code and put some returns in and a test for the 4 key pushes.

    See if this makes any sense,

    Code:
    	list      p=12F683        ; list directive to define processor
    	#include <p12F683.inc>    ; processor specific variable definitions
    
    	errorlevel  -302          ; suppress message 302 from list file
    
    	__CONFIG   _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT 	
    	cblock 0x20
    		KeyBuffer:4
    		Keys
    		Previous
    		codevalue
    		d1
    		d2
    	endc
    	org   	0x0000      	; org sets the origin, 0x0000
            goto    main   		; go to beginning of program 
    		org	  	0x0004			;interrupt vector
    		goto 	main
    	
    main
    		movlw   07h            		; Set GPIO <2:0) to
                    movwf   CMCON0          	; digital I/O
    		clrf   	ANSEL           	; digital I/0
    		movlw	b'001111'
    		banksel	TRISIO
    		movwf	TRISIO
    		banksel	GPIO
    		clrf	GPIO	  
    		clrf	Previous
    GetLoop		movlw	KeyBuffer
    		movwf	FSR
    		movlw	b'1001'
    		movwf	codevalue
    		call   	KeyLoop
    
    		movfw	KeyBuffer	;test the first key press
    		xorlw	b'0001'		;was it key 1	
    		btfss	STATUS,Z	;yes so skip
    		goto	GetLoop		;no so go back and get new keys
    
    		movfw	KeyBuffer+1	;test the second key press
    		xorlw	b'0010'		;2
    		btfss	STATUS,Z
    		goto	GetLoop
    
    		movfw	KeyBuffer+2	;test the third key press
    		xorlw	b'0100'		;3
    		btfss	STATUS,Z
    		goto	GetLoop
    
    		movfw	KeyBuffer+3	;test the fourth key press
    		xorlw	b'0001'		;1
    		btfss	STATUS,Z
    		goto	GetLoop
    
    ;if it get's to here then keys 1,2,3,1 were pressed.
    
    	;turn on LED here
    
                    goto 	GetLoop
    
    KeyLoop		
    		call	Delay10mS	;debounce delay
    		movfw	Keys		;keep copy of previous keys
    		movwf	Previous
    		movfw	GPIO		;get key state
    		xorlw	0xff		;1 = key pressed
    		andlw	0x0f		;keep only 0-3 bits  <-added
    		movwf	Keys		;save for later
    		xorwf	Previous,W	;find keys that have changed
    		andwf	Keys,W		;and are currently pressed
    		btfsc	STATUS,Z	
    		goto	KeyLoop
    		movwf	INDF		;store the key
    		incf	FSR,f		;move pointer forward
    		movfw	FSR		    ;see if we have 4 keys yet
    		xorlw	KeyBuffer+4
    		btfss	STATUS,Z
    		goto	KeyLoop
    ;here KeyBuffer will contain 4 key values.
    		return		 
    
    
    
    Delay10mS		        	;9998 cycles
    		movlw	0xCF
    		movwf	d1
    		movlw	0x08
    		movwf	d2
    Delay_0
    		decfsz	d1, f
    		goto	$+2
    		decfsz	d2, f
    		goto	Delay_0
    
    			;2 cycles
    		goto	$+1
    		return
     end
    
    Mike.

  14. #29
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    I don't need this part do I
    Code:
                    movlw	b'1001'
    		movwf	codevalue
    
    My buttons are low going high on press

    When i get to here all need is something like this
    Code:
    ;if it get's to here then keys 1,2,3,1 were pressed.
    
    	;turn on LED here
                    call    LedOn
                    goto 	GetLoop
    LedOn 
                    banksel  GPIO         
                    bsf        GPIO,GP5     ;turn on led on GP5
                    goto      LedOn         ;keeps it in this loop for now
    
    I tried it it didn't turn on the led

  15. #30
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,807

    Default

    Quote Originally Posted by be80be View Post
    I don't need this part do I
    Code:
                    movlw	b'1001'
    		movwf	codevalue
    
    Correct.
    My buttons are low going high on press
    In that case remove the xorlw 0xff.
    Code:
    KeyLoop		
    		call	Delay10mS	;debounce delay
    		movfw	Keys		;keep copy of previous keys
    		movwf	Previous
    		movfw	GPIO		;get key state
    	;;	xorlw	0xff		;1 = key pressed <-remove  
    		andlw	0x0f		;keep only 0-3 bits  <-added
    		movwf	Keys		;save for later
    
    Mike.
    Last edited by Pommie; 9th February 2009 at 05:59 AM.

+ Reply to Thread
Page 2 of 3
First 1 2 3 Last

Similar Threads

  1. RPM activated switch to save motor from nitrous blow up
    By MalcolmV8 in forum General Electronics Chat
    Replies: 22
    Latest: 21st November 2008, 12:28 AM
  2. how can i save videos from tv ?
    By haytham in forum Electronic Projects Design/Ideas/Reviews
    Replies: 19
    Latest: 11th October 2008, 04:04 PM
  3. Plan for simple Press on press off circuit?
    By Robot builder 101 in forum Electronic Projects Design/Ideas/Reviews
    Replies: 16
    Latest: 8th August 2007, 02:43 AM
  4. save voltage
    By Fahime in forum General Electronics Chat
    Replies: 10
    Latest: 22nd November 2006, 08:29 AM
  5. simple circuit with miniature press switch
    By Musisoft in forum Electronic Projects Design/Ideas/Reviews
    Replies: 18
    Latest: 23rd July 2006, 06:44 PM

Tags for this Thread