Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic led chaser using pic 16f877a

Status
Not open for further replies.

kgavionics

Full Member level 3
Full Member level 3
Joined
Jun 12, 2012
Messages
167
Helped
7
Reputation
14
Reaction score
11
Trophy points
1,298
Location
Alberta.Canada
Visit site
Activity points
2,482
hi guys
i have programmed my pic 16f877a to do led chaser and here's the code in assembly languge

main:

clrf PORTD
bsf STATUS,RP0
movlw 0x00
movwf TRISD
bcf STATUS,RP0




movlw 0x09 ; number of shifts that the pic will do
movwf n1
movlw 0x08
movwf n2
movlw 0x07
movwf n3
movlw 0x06
movwf n4
movlw 0x05
movwf n5
movlw 0x04
movwf n6
movlw 0x03
movwf n7
movlw 0x02
movwf n8
movlw 0x01
movwf n9

Movlw 0x25
Movwf FSR
movlw 0x08
movwf var2
movlw 0x01
movwf var3
proc Clrf shift ; clear the varialble shift
Bsf STATUS,C ; set the carry to 1
incf FSR,f ; initialize the pointer

loop3

rrf shift,f ; rotate right
movf shift,w ; move the value from shift tot w
Movwf PORTD ; display the value on portd
call delay1 ; delay routine

Decfsz INDF,f ; decremenent the value of number of shift
goto loop3 ; if the number of shift is superior to zero continue shifting to the right
decfsz var2,f ; have we reached 8?
goto proc ; goto to label proc
goto main ; loop for ever

the result is on the folowing video :https://www.youtube.com/watch?v=ZBIOi3K2kz0

i have a little problem : i want that every time the led reached the number of shift, all the led at right remains on.can some one help me because i can't find a way to do a bit test instruction because the bit i want to test is not fixed and its changing from 1 to 8.

thank you in advance guys
 

Simple short code for LED Chaser in MikroC :



Also you can easily get assembler code in MikroC if you need.

The code is the same for PIC16F877, just choose that uC in project settings and adjust oscillator.


Best regards,
Peter
 

Simple short code for LED Chaser in MikroC :



Also you can easily get assembler code in MikroC if you need.

The code is the same for PIC16F877, just choose that uC in project settings and adjust oscillator.


Best regards,
Peter

thank you for this tpetar, but i don't use microC for the moment.I only use assembler.
 

You can try the following code. I could not simulate it properly, maybe a few adjustments will do the trick. Please post your results here.

Code:
    LIST   P=PIC16F877A
    #include "P16F877A.INC"
    RADIX	DEC

cont    equ 0x20
max     equ 0x21
fixed   equ 0x22
shift   equ 0x23



    org 0x0000

    bsf     STATUS,RP0
    clrf    TRISD
    clrf    STATUS

chaser_start
    clrf    PORTD
    clrf    fixed
    clrf    shift
    movlw   8
    movwf   max
    movwf   cont

do_the_shift
    bcf     STATUS,C
    movf    shift,f
    btfsc   STATUS,Z
    bsf     STATUS,C
    rrf     shift,f
    movf    shift,W
    iorwf   fixed,W
    movwf   PORTD
    call    delay
    decfsz  cont,f
    goto    do_the_shift

    decf    max,f
    btfsc   STATUS,Z
    goto    chaser_done

    movf    max,W
    movwf   cont
    bsf     STATUS,C
    rlf     fixed,f
    clrf    shift
    goto    do_the_shift

chaser_done
    goto    chaser_start

    end
 
thank you YSBA you have been very helpful for me, i copied you code and just add the delay routine, burned the hex on pic and there we go you program works like a charm.
here's the result

https://www.youtube.com/watch?v=DJzDfA2d8mw

i verified your code and give me a idea, so i modified my program and now my code is working also.
here's the code



Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
;============================================================
; File name:chaser
; Date:24-06-2013
; Author:kgavionics
; Processor:16f877a
; Reference circuit:
;============================================================
; Copyright notice:
;============================================================
; Program Description:
;
;===========================
; configuration switches
;===========================
List P = PIC16F877a, R=DEC; 
#include <P16f877a.INC>
__config  _XT_OSC & _PWRTE_OFF & _WDT_OFF & _CP_OFF
;=====================================================
; constant definitions
;=====================================================
;=====================================================
; PIC register equates
pcl  EQU 2
;=====================================================
;=====================================================
; variables in PIC RAM
;=====================================================
cblock 0x20
counter1 :  1 
counter2  : 1
shift : 1
var1 : 1 ;0x23
var2 : 1  ;0x24
n1 : 1    ;0x25
n2 : 1    ;0x26
n3 : 1    ;0x27
n4 : 1    ;0x28 
n5 : 1    ;0x29
n6 : 1    ;0x2a 
n7 : 1    ;0x2b
n8 : 1     ;0x2c
n9 : 1     ;0x2d
fixed : 1
toffset: 1
endc
;============================================================
; program
;============================================================
org 0X00 ; start at address
goto main
; Space for interrupt handlers
org 0x08
 
display
        movwf PORTD
        return
 
delay
        movlw   0x48
        movwf   counter2
loop1
        movlw   0xff
        movwf   counter1
loop2
        nop
        decfsz counter1
        goto loop2
        decfsz counter2
        goto loop1
return
main:
 
        clrf    PORTD           
    bsf         STATUS,RP0
        movlw   0x00
        movwf   TRISD   
        bcf             STATUS,RP0
        
        
        
        clrf    fixed
        movlw 0x09
        movwf  n1
        movlw 0x08
        movwf  n2
        movlw 0x07
        movwf  n3
        movlw 0x06
        movwf  n4
        movlw 0x05
        movwf  n5
        movlw 0x04
        movwf  n6
        movlw 0x03
        movwf  n7
        movlw 0x02
        movwf  n8
        movlw 0x01
        movwf  n9
        
        Movlw 0x25
        Movwf FSR
        movlw   0x08
        movwf   var2
        movlw   0x00
        movwf   toffset
        
kais    Clrf  shift
                Bsf STATUS,C
                incf    FSR,f
                incf    toffset
        loop3
        
        rrf shift,f
        movf    toffset,w
        call    table
        movwf   fixed
        
        iorwf   shift,w
        Movwf PORTD
        call delay
        Decfsz INDF,f
        goto loop3
        decfsz var2,f
        goto  kais
        goto  main
table 
        addwf   pcl
        retlw   0x00
        retlw   0x01
        retlw   0x03
        retlw   0x07
        retlw   0x0f
        retlw   0x1f
        retlw   0x3f
        retlw   0x7f
        retlw   0xff
        end
;============================================================
end ; END OF PROGRAM
;============================================================



i know that my code is not optimized like yours ,but it works lolthank you again for you code Ysba.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top