16F628A - Stops if release power switch.


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Feb 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Code

    Sorry, i thought it can be simply added to whatever code...

    Here is my messy code. I couldn't have done it better. Any help would be very welcome, i needed 12-15 days of study of this pic&mpasm&icprog&stuff just to get to this level, i'm not blind yet but not far... Hope not to make an attack because of so much sitting, omg.

    It only gives some warnings, no errors and it works;

    So, the problems are;
    -1. the code does not allow the PIC to power itself and the sequence stops when i release the pushbutton that powers it. Need to fix that or i will need to sacrifice an output [12 leds] to power an electromagnetic relay etc, etc. I need it to "play" the sequence only once, after a "short touch" of a push button [not retaining]. At this moment, it plays the seq. for 8 times, don't know why... althoug no looping is specified...
    - 2. i need to "group" 2 or more delays in a shorter way; ex. "call delay 10x"... Actually, the code contains much longer delays.
    - 3. code is horrible, need help to optimize it, correct it and maybe simplifying it, without loosing the ability to preciselly&independently control al the leds.

    Thanks for your kindness, i hope my english is good enough, i'm in Romania
    .
    Code:
    	LIST	p=16F628		;tell assembler what chip we are using
    	include "P16F628.inc"		;include the defaults for the chip
    	__config 0x3D18			;config settings (osc. type etc.)
    	cblock 	0x20 			;start of general purpose registers
    		count1 			;used in delay routine
    		counta 			;used in delay routine 
    		countb 			;used in delay routine
    	endc
    	LEDA0	       Equ	0		;set constant LED = 0
    	LEDPORTA0     Equ	PORTA		;set constant LEDPORT = 'PORTA'
    	LEDA1	       Equ	1		;set constant LED = 1
    	LEDPORTA1     Equ	PORTA		;set constant LEDPORT = 'PORTA'
    	LEDA2	       Equ	2		;set constant LED = 2
    	LEDPORTA2    Equ	PORTA		;set constant LEDP0RT = 'PORTA'
    	LEDA3	       Equ	3		;set constant LED = 3
    	LEDPORTA3     Equ	PORTA		;set constant LEDPORT = 'PORTA'
    	LEDA4	       Equ	4		;set constant LED = 4
    	LEDPORTA4     Equ	PORTA		;set constant LEDPORT = 'PORTA'
    	LEDA5	       Equ	5		;set constant LED = 5
    	LEDPORTA5     Equ	PORTA		;set constant LEDPORT = 'PORTA'
    	LEDB0	       Equ	0		;set constant LED = 0
    	LEDPORTB0     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB1	       Equ	1		;set constant LED = 1
    	LEDPORTB1     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB2	       Equ	2		;set constant LED = 2
    	LEDPORTB2     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB3	       Equ	3		;set constant LED = 3
    	LEDPORTB3     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB4	       Equ	4		;set constant LED = 4
    	LEDPORTB4     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB5	       Equ	5		;set constant LED = 5
    	LEDPORTB5     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB6	       Equ	6		;set constant LED = 6
    	LEDPORTB6     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB7	       Equ	7		;set constant LED = 7
    	LEDPORTB7     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDPORT	Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDTRIS	Equ	TRISB		;set constant for TRIS register
    	org	                0x0000		;org sets the origin, 0x0000 for the 16F628,
    					;this is where the program starts running	                LEDTRIS	    Equ	TRISB		;set constant for TRIS register
    	movlw	    0x07
    	movwf	    CMCON			;turn comparators off (make it like a 16F84)
       	bsf 	    STATUS, RP0	               ;select bank 1
                    clrf	   TRISA	                               ;set PortA all outputs
       	movlw 	    b'00000000'	               ;set PortB all outputs
       	movwf 	    LEDTRIS
    	bcf	    STATUS, RP0	               ;select bank 0
    ;--------------------------------------------------------------------------------
    Loop
                    BSF	LEDPORTA0, LEDA0	                ; RA0 ON
    	call	Delay
    	call	Delay
    	call	Delay
    	call	Delay
    	call	Delay
    	call	Delay
    	call	Delay
               	movlw	b'11111111'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	call	Delay
               	movlw	b'00000000'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	call	Delay
               	movlw	b'11111111'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	call	Delay
    
    	call	Delay	
               	movlw	b'00000000'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	call	Delay
               	movlw	b'11111111'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	call	Delay
               	movlw	b'00000000'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	call	Delay
               	movlw	b'11111111'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	
    	call	Delay
               	movlw	b'00000000'
    	movwf	LEDPORT
    	call	Delay
    	call	Delay
               	movlw	b'00010000'
    	movwf	LEDPORT	
    	call	Delay
               	movlw	b'00001000'
    	movwf	LEDPORT	
    	call	Delay
               	movlw	b'00010000'
    	movwf	LEDPORT	
    	call	Delay
               	movlw	b'00000000'
    	movwf	LEDPORT	
    	call	Delay
    	call	Delay	
    	   bcf	    LEDPORTA0, LEDA0	                    ; RA0 off
    ;-------------------------------------------------------------------------------------
    
    Delay	movlw	d'250'			;delay 250 ms (4 MHz clock)
    	movwf	count1
    d1	movlw	0xC7
    	movwf	counta
    	movlw	0x01
    	movwf	countb
    Delay_0
    	decfsz	counta, f
    	goto	$+2
    	decfsz	countb, f
    	goto	Delay_0
    
    	decfsz	count1	,f
    	goto	d1
    	retlw	0x00
    	end

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default

    I'm not sure if this is what you're looking for. I think there should be an END statement just above the Delay routine or a GOTO loop if you want to repeat the sequence.

    Code:
    	movwf	LEDPORT	
    	call	Delay
    	call	Delay	
    	   bcf	    LEDPORTA0, LEDA0	                    ; RA0 off
                 
                 END  ; if you want to stop right here
                 GOTO loop   ; if you want to repeat some section of code.  Ofcourse you have to 
                                  ; put the label 'loop' where you want it.
    ;-------------------------------------------------------------------------------------
    
    Delay	movlw	d'250'			;delay 250 ms (4 MHz clock)
    	movwf	count1

  3. #3
    Join Date
    Feb 2009
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    So far, so good. We need a schematic to solve problem #1, however.

Similar Threads

  1. Switch mode power supply Pic Micro
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th July 2009, 13:11
  2. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 07:12
  3. Replies: 3
    Last Post: - 29th April 2009, 00:45
  4. 'Soft' On/Off Power Switch
    By Art in forum General
    Replies: 19
    Last Post: - 14th November 2008, 01:54
  5. Newbie - 16F628A and switch latching
    By malc-c in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 19th May 2006, 02:35

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts