Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone fix this code if it needs corrections. I have 7 colors being displayed for PORTB. My goal is to reverse the order of

Can someone fix this code if it needs corrections. I have 7 colors being displayed for PORTB. My goal is to reverse the order of these colors and output the sequence in PORTD. The colors displayed in port B are 0 to 0x20.

In lines 34 through 37 of the code(I labeled it in the code) I want to subtract the Literal 0x08 (assuming 0x08 stores the last color in the original sequence) to subtract 0x20 so that the order can be reversed.

That is my thought process but I have no way of testing if this correct until Monday. Any feedback or corrections would be appreciated on lines 34-37.

I am working with a PIC18F4620.

image text in transcribedimage text in transcribed

#include config OSC = INT1067 config WDT = OFF config LVP = OFF config BOREN = OFF ORG Ox0000 ; CODE STARTS FROM THE NEXT LINE START: ORG Ox0000 START: MOVLW OXOF ; Load W with ex@F MOVWF ADCON1 ; Make ADCON1 to be all digital MOVLW MOVWF OxFF TRISA ; Load W with OxFF ; Set PORT A as all inputs MOVLW MOVWF 0x00 TRISB ; Load W with @x00 ; Make PORT B as outputs 0x00 MOVLW MOVWF ; Load W with 0x00 ; Make PORT B as outputs TRISD MAIN_LOOP: MOVLW 0x00 MOVWF 0x20 MOVLW 0x08 MOVWF 0x21 ; start of While LOOP ; load W with i store w to location Ox20 ; load W with 08 ; store w to location @x21 FOR_LOOP: MOVF 0x20,W MOVWF PORTB ; read content of Ox20 into w ; output w to PORT B LINE34)MOVLW LINE35) MOVWF LINE36) SUBLW LINE37)MOVWF Ox08 TRISB 0x20 PORTD ; read content of Ox08 into W ; Port B as initial condition ; Subtract ox20 FROM OX08 ; Output to PORTD CALL DELAY_ONE_SEC ; wait one sec INCF 0x20,F DECF @x21, F BNZ FOR_LOOP ; increment location 0x20 by 1 ; decrement location Ox21 by 1 ; if not equal, then (0x21) not equal to o ; go back to FOR_LOOP ; go back to While LOOP GOTO MAIN_LOOP DELAY_ONE_SEC: MOVLW Oxff MOVWF 0x28 ; Load Oxff into W ; Load W to memory ox20 LOOP_1_OUTER: NOP MOVLW Oxff MOVWF 0x29 ; Do nothing ; Load constant Delay2 into W ; Load saved inner loop value ox20 LOOP_1_INNER: NOP DECF 0x29, F BNZ LOOP_1_INNER ; Do nothing ; Decrement memory location @x20 ; If value not zero, go back to loop inner 2 DECF BNZ RETURN END 0x28, F LOOP_1_OUTER ; Decrement memory location @x28 ; If value not zero, go back to loop outer 2 #include config OSC = INT1067 config WDT = OFF config LVP = OFF config BOREN = OFF ORG Ox0000 ; CODE STARTS FROM THE NEXT LINE START: ORG Ox0000 START: MOVLW OXOF ; Load W with ex@F MOVWF ADCON1 ; Make ADCON1 to be all digital MOVLW MOVWF OxFF TRISA ; Load W with OxFF ; Set PORT A as all inputs MOVLW MOVWF 0x00 TRISB ; Load W with @x00 ; Make PORT B as outputs 0x00 MOVLW MOVWF ; Load W with 0x00 ; Make PORT B as outputs TRISD MAIN_LOOP: MOVLW 0x00 MOVWF 0x20 MOVLW 0x08 MOVWF 0x21 ; start of While LOOP ; load W with i store w to location Ox20 ; load W with 08 ; store w to location @x21 FOR_LOOP: MOVF 0x20,W MOVWF PORTB ; read content of Ox20 into w ; output w to PORT B LINE34)MOVLW LINE35) MOVWF LINE36) SUBLW LINE37)MOVWF Ox08 TRISB 0x20 PORTD ; read content of Ox08 into W ; Port B as initial condition ; Subtract ox20 FROM OX08 ; Output to PORTD CALL DELAY_ONE_SEC ; wait one sec INCF 0x20,F DECF @x21, F BNZ FOR_LOOP ; increment location 0x20 by 1 ; decrement location Ox21 by 1 ; if not equal, then (0x21) not equal to o ; go back to FOR_LOOP ; go back to While LOOP GOTO MAIN_LOOP DELAY_ONE_SEC: MOVLW Oxff MOVWF 0x28 ; Load Oxff into W ; Load W to memory ox20 LOOP_1_OUTER: NOP MOVLW Oxff MOVWF 0x29 ; Do nothing ; Load constant Delay2 into W ; Load saved inner loop value ox20 LOOP_1_INNER: NOP DECF 0x29, F BNZ LOOP_1_INNER ; Do nothing ; Decrement memory location @x20 ; If value not zero, go back to loop inner 2 DECF BNZ RETURN END 0x28, F LOOP_1_OUTER ; Decrement memory location @x28 ; If value not zero, go back to loop outer 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

13-4 What are alternative methods for building information systems?

Answered: 1 week ago