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 16f877a prob with RRF & RLF command

Status
Not open for further replies.

Sheritronics

Newbie level 6
Joined
Feb 1, 2014
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
80
I am a beginner to the programming can any one help me why the code below is not working i have to make a sequential led circuit on portE and portB, I am using pic16f877a in Mplab 8.76


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
DELAY    EQU 0x20
DELAY2   EQU 0x21
DELAY3   EQU 0x22
start:
 ORG 0x00
 #INCLUDE "P16F877A.INC"
 __CONFIG _WDT_OFF
 
main:
 BSF      0X03,5
 MOVLW    B'00000000'
 MOVWF    0X86
 MOVWF    0x89
 
red:
 BCF      0x03,5
 MOVLW    B'00000001'
 MOVWF    0x06
 MOVLW    B'00000100'
 MOVWF    0x09
 CALL     delay
 
yellow:
 RLF      0x06,F
 RRF      0x09,F
 CALL     delay
 
green:
 RLF      0x06,F
 RRF      0x09,F
 CALL     delay
 GOTO     fin
 
 
delay:
       MOVLW  D'50'
       MOVWF  DELAY
loop1: DECFSZ DELAY
       GOTO   loop1
       MOVWF  DELAY
loop2: DECFSZ DELAY2
       GOTO   loop2
       MOVWF  DELAY3
loop3: DECFSZ DELAY3
       GOTO   loop3
       RETURN
 
fin    GOTO   red
       END

 
Last edited by a moderator:

Hi,

Assume you have got the code from the web; its a very poor example of how to write assembler code.

I have made 2 very small changes to the code to run on my MPlab and it works in that it sequentially changes Portb 0,1 and 2 and Flashes
PortE 2

If you look at these tutorials you will see that properly written code is a lot easier to follow and understand.

Try the flashing led examples and then you should be able to make your own sequential chaser.

If you get stuck post your code for help.

**broken link removed**

http://www.winpicprog.co.uk/pic_tutorial.htm

http://www.amqrp.org/elmer160/lessons/
[





Code:
DELAY1   EQU 0x20
DELAY2   EQU 0x21
DELAY3   EQU 0x22
start:
 ORG 0x00
 #INCLUDE "P16F877A.INC"
 __CONFIG _WDT_OFF
 
main:
 BSF      0X03,5
 MOVLW    B'00000000'
 MOVWF    0X86
 MOVWF    0x89
 
red:
 BCF      0x03,5
 MOVLW    B'00000001'
 MOVWF    0x06
 MOVLW    B'00000100'
 MOVWF    0x09
 CALL     delay
 
yellow:
 RLF      0x06,F
 RRF      0x09,F
 CALL     delay
 
green:
 RLF      0x06,F
 RRF      0x09,F
 CALL     delay
 GOTO     fin
 
 
delay:
       MOVLW  D'50'
       MOVWF  DELAY1
loop1: DECFSZ DELAY1,F
       GOTO   loop1
       MOVWF  DELAY
loop2: DECFSZ DELAY2,F
       GOTO   loop2
       MOVWF  DELAY3
loop3: DECFSZ DELAY3,F
       GOTO   loop3
       RETURN
 
fin    GOTO   red
       END
 

Attachments

  • 000048.jpg
    000048.jpg
    46.5 KB · Views: 109
It is a bit easier to read code, if you use the names for SFR's and Ports, such as STATUS. Also using the Microchip template aids readability.
You do not seem to have defined the processor.
Capture.PNG

What are you using for an oscillator? Frequency?
Have you turned off the analog functions (e.g., comparators) for those ports (Port E)?

At what point is there failure? Is it in simulation or real life? Do the red LED's on PortB and PortE turn on? Do they turnoff? Have you simulated your delay?

John
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top