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
Bookmarks