papunblg
Advanced Member level 3
- Joined
- Oct 22, 2010
- Messages
- 716
- Helped
- 172
- Reputation
- 344
- Reaction score
- 165
- Trophy points
- 1,343
- Location
- Kolkata India
- Activity points
- 6,421
This project may help a new hobbyist to understand how to interface ULN2803 with PIC micro to control loads up to 500mA with schematic, picture and video.
Please refer to ULN2803 datasheet at http://www.datasheetcatalog.org/datasheets/90/366828_DS.pdf
Here the given code will drive 8 lines of LEDs to produce few fascinating designs.
;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;Below is the code file;;;;;;;;;;;;;;;;;;;
Please refer to ULN2803 datasheet at http://www.datasheetcatalog.org/datasheets/90/366828_DS.pdf
Here the given code will drive 8 lines of LEDs to produce few fascinating designs.
;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;Below is the code file;;;;;;;;;;;;;;;;;;;
Code:
list p=16F84A
#include <p16F84A.inc>
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
ERRORLEVEL -302
COUNT2 EQU 09H
COUNT1 EQU 08H
PAGESEL START
GOTO START
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LTOR MACRO BY_N
[INDENT]VARIABLE I[/INDENT]
I=0
[INDENT]WHILE I<BY_N
CALL ALLOFB
CALL DELAY
CALL B0
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
CALL ALLOFB
CALL DELAY[/INDENT]
I+=1
[INDENT]ENDW
ENDM[/INDENT]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;
RTOL MACRO BY_N
[INDENT]VARIABLE I[/INDENT]
I=0
[INDENT]WHILE I<BY_N
CALL ALLOFB
CALL DELAY
CALL B7
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
CALL ALLOFB
CALL DELAY[/INDENT]
I+=1
[INDENT]ENDW
ENDM[/INDENT]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;
RTOL2 MACRO BY_N
[INDENT]VARIABLE I[/INDENT]I=0
[INDENT]WHILE I<BY_N
CALL ALLOFB
CALL DELAY
MOVLW B'11000000' ;RB7
MOVWF PORTB
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
CALL ALLOFB[/INDENT]
[INDENT]CALL DELAY[/INDENT]I+=1
[INDENT]ENDW
ENDM[/INDENT]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;
LTOR2 MACRO BY_N
[INDENT]VARIABLE I[/INDENT]
I=0
[INDENT]WHILE I<BY_N
CALL ALLOFB
CALL DELAY
MOVLW B'00000011' ;RB1
MOVWF PORTB
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
CALL ALLOFB
CALL DELAY[/INDENT]
I+=1
[INDENT]ENDW
ENDM[/INDENT]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;
RTOL3 MACRO BY_N
[INDENT]VARIABLE I[/INDENT]
I=0
[INDENT]WHILE I<BY_N
CALL ALLOFB
CALL DELAY
MOVLW B'11100000' ;RB7
MOVWF PORTB
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
CALL ALLOFB
CALL DELAY[/INDENT]
I+=1
[INDENT]ENDW
ENDM[/INDENT]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;
LTOR3 MACRO BY_N
[INDENT]VARIABLE I[/INDENT]
I=0
[INDENT]WHILE I<BY_N
CALL ALLOFB
CALL DELAY
MOVLW B'00000111' ;RB1
MOVWF PORTB
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
RLF PORTB,1
CALL DELAY
CALL ALLOFB
CALL DELAY[/INDENT]
I+=1
[INDENT]ENDW
ENDM[/INDENT]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;
LTOR1B MACRO BY_N
[INDENT]VARIABLE I[/INDENT]
I=0
[INDENT]WHILE I<BY_N
CALL ALLONB
CALL DELAY
MOVLW B'11111110' ;RB0
MOVWF PORTB
CALL DELAY
MOVLW B'11111101' ;RB1
MOVWF PORTB
CALL DELAY
MOVLW B'11111011' ;RB2
MOVWF PORTB
CALL DELAY
MOVLW B'11110111' ;RB3
MOVWF PORTB
CALL DELAY
MOVLW B'11101111' ;RB4
MOVWF PORTB
CALL DELAY
MOVLW B'11011111' ;RB5
MOVWF PORTB
CALL DELAY
MOVLW B'10111111' ;RB6
MOVWF PORTB
CALL DELAY
MOVLW B'01111111' ;RB7
MOVWF PORTB
CALL DELAY
CALL ALLONB
CALL DELAY[/INDENT]I+=1
[INDENT]ENDW
ENDM[/INDENT]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;
RTOL1B MACRO BY_N
[INDENT]VARIABLE I[/INDENT]
I=0
[INDENT]WHILE I<BY_N
CALL ALLOFB
CALL DELAY
MOVLW B'01111111' ;RB0
MOVWF PORTB
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
RRF PORTB,1
CALL DELAY
CALL ALLOFB
CALL DELAY[/INDENT]I+=1
[INDENT]ENDW
ENDM[/INDENT]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;
DELAY
LOOP1 [INDENT]decfsz COUNT1,1
goto LOOP1
decfsz COUNT2,1
goto LOOP1
RETURN[/INDENT]
ALLOFB
[INDENT]MOVLW B'00000000'
MOVWF PORTB
RETURN[/INDENT]ALLONB
[INDENT]MOVLW B'11111111'
MOVWF PORTB
RETURN[/INDENT]
B7 [INDENT]MOVLW B'10000000' ;RB7
MOVWF PORTB
CALL DELAY
RETURN[/INDENT]
B0 [INDENT]MOVLW B'00000001' ;RB1
MOVWF PORTB
CALL DELAY
RETURN[/INDENT]
START
[INDENT]BSF STATUS,RP0
MOVLW B'00000000'
MOVWF TRISB
BCF STATUS,RP0
LTOR 6
RTOL 6
RTOL2 6
CALL ALLONB
CALL DELAY
CALL ALLOFB
CALL DELAY
CALL ALLONB
CALL DELAY
CALL ALLOFB
CALL DELAY
LTOR1B 6
CALL DELAY
CALL DELAY
GOTO START
END[/INDENT]
Last edited by a moderator: