Help with the PIC12F509

Status
Not open for further replies.

Darkstar64

New Member
Hey all ive been working with the PIC 12F509 for a little while before I upgrade to some more complex more interesting PIC's that I can do alot more projects with anyways currently im working on some multiplexing of LEDS now I understand that the 509 is a little small at this but im only doing some small multiplexing anyways I currently am thinking im going to use 2 or 3 of them to create a interesting effect for a school project but am stuck on the code part I have looked at a few tutorials on the workings of the 509 and
how to flash a LED and a few other small tutorials and have created a delay subroutine of 10ms for the project the code for this delay is below now im not sure if this is correct or not. Also I would like to be able to run this program on my Computer for Debug Using MPLAB how would I go about doing that and being able too see in real time what the Output pins are showing if they are high or low etc

;Variables
dc1 res 1
dc2 res 1
dc3 res 1

delay10 ; Delay W x 10ms
movwf dc3 ; Delay = 1 + W x (3 + 10009 + 3) - 1 + 4 -> W x 10.015ms
dly2 movlw .13 ; Repeat inner loop 13 times
movwf dc2 ; -> 13 x (767 + 3) - 1 = 10009 cycles
clrf dc1 ; Inner loop = 256 x 3 - 1 = 767 cycles
dly1 decfsz dc1,f
goto dly1
decfsz dc2,f ; End middle loop
goto dly1
decfsz dc3,f ; End outer loop
goto dly2
retlw 0

Now for the LED code im going to be using all the output pins exluding GP3 bc it only is a input pin now from reading up on multiplexing I have found that I have to be able to change the pins from a high,low or input now in the tutorials I read for the flashing LED and turning a LED on it uses the following code but first I had to make the pins outputs this is how I think its done that is

movlw b'001000' ; Confifure GP0,GP1,GP2,GP4,GP5 to outputs
tris GPl0

Then to output a high on GP0 I would use

movlw b'000001'
movwf GPI0 ; This I think writes the 1 to something im not sure what

Then to make it a low on GP0 I would use

movlw b'000000'
movwf GPI0 ; This then writes the 0 to something again not sure of what

What im asking now is how do I implement it using the delay since each command runs at 1us I have to slow it down so the eye can see it also I have to be able to change the pins to inputs as well if any of this is incorrect can you please correct me thanks


start
movlw b'001000' ; Confifure GP0,GP1,GP2,GP4,GP5 to outputs
tris GPl0
movlw b'000001' ; Sets GP0 to high
movwf GPI0 ; Writes 1 to GP0
movlw .10
call delay10 ; Delay of 100ms or .1s using the Delay Subroutine
movlw b'000000' ; Sets GP0 to low
movwf GPI0 ; Writes 0 to GP0
End
 
Last edited:
Hi, Darkstar.

Sounds like you're off to a good start. There are a few areas where you are not solid, but basically you have the right ideas.

I would suggest your delay is not long enough; one-tenth second isn't going to put up much of a display. Try loading W with .50 to get a half-second cycle. Also, if you loop back to start, then you will have blinking LED.

For a better understanding of multi-plexing, one source is Microchip itself. Go to their website, and in the search engine, enter: Tips n' Tricks, then select documents. On the page that opens, near the bottom, you'll see a line labeled "Tips n' Tricks". Click on that pdf symbol, and go to Tip #2. The table there will show you how to arrange your I/O's for multiplexing 6 LEDS on three pins.

I like your approach. Keep up the good work.

Edit: When you download the Tips n' Tricks page, bookmark it in favorites for later reference.
 
Last edited:
ty AllVol for your help is there any way to Simulate the code using MPLAB since I do not have the programmer it is at the school witch is closed for the summer is there a way I can run the code and see the outputs if they are high or low I have tried looking on Microchip's website but can't seem to find anything about it and I will probly loop after a few times so that I will not have to keep repeating the code over and over again also im unsure of how to change a pin to be a input while keeping the others as outputs I was looking at the Micochip Tips and Tricks thing you gave me and it shows that one pin can be a input while another pin a output also when ever I quick build it I get the following error every time I don't know what I did wrong

And after that just to clarify things for Multiplexing 12 LED's using 4 pins it would be as like this the image I based my chart off is the attachment

Pins then the LED's that are on
GP0 GP1 GP2 GP4

1 0 0 X A
0 1 0 0 B
X 1 0 X C
X 0 1 X D
X X 1 0 E
X X 0 1 F
1 X 0 X G
0 X 1 X H
X 1 X 0 I
X 0 X 1 J
1 X X 0 K
0 X X 1 L

Assuming this is correct then this code should turn on LED A for .5s then turn it off ( The reason im doing it as subroutines is that it makes the code easyer to understand bc all it does is call the subroutines so that I can make any pattern without having to type alot of the code over again I can then just loop the calls to make a pattern

This is the full code and quick build im having some problems with it

list p=12F509 ; list directive to define processor
#include <p12F509.inc> ; processor specific variable definitions

__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.




;***** VARIABLE DEFINITIONS
dc1 res 1 ; Delay Loop Counters
dc2 res 1
dc3 res 1



;**********************************************************************
RESET_VECTOR CODE 0x3FF ; processor reset vector

; Internal RC calibration value is placed at location 0x3FF by Microchip
; as a movlw k, where the k is a literal value.

MAIN CODE 0x000
movwf OSCCAL ; update register with factory cal value

;******** Main loop

start

call lightled1
goto start

END



;************* Subroutines

lightled1
movlw b'111000' ; Configure GP4 as input
tris GPI0
movlw b'000001' ; Change corresponding bit of GP0 to 1
movwf GPI0 ; Writes 1 to GP0
movlw .50 ; Stays on for .5s:
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw b'000000' ; Change corresponding bit of GP0 to 0
movwf GPI0
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPI0 ; Write 0 to GP0
retlw 0



delay10 ; Delay W x 10ms
movwf dc3 ; Delay = 1 + W x (3 + 10009 + 3) - 1 + 4 -> W x 10.015ms

dly2 movlw .13 ; Repeat inner loop 13 times
movwf dc2 ; -> 13 x (767 + 3) - 1 = 10009 cycles

clrf dc1 ; Inner loop = 256 x 3 - 1 = 767 cycles
dly1 decfsz dc1,f
goto dly1

decfsz dc2,f ; End middle loop
goto dly1

decfsz dc3,f ; End outer loop
goto dly2

retlw 0

And finally the Quick Build of it and the errors

Debug build of project `C:\PIC12F509\Programs\Multi+Plexing LEDS.disposable_mcp' started.
Preprocessor symbol `__DEBUG' is defined.
Wed Jul 30 13:28:23 2008
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p12F509 "Multi+Plexing LEDS.ASM" /l"Multi+Plexing LEDS.lst" /e"Multi+Plexing LEDS.err" /d__DEBUG=1
Error[149] C:\PIC12F509\PROGRAMS\MULTI+PLEXING LEDS.ASM 57 : Directive only allowed when generating an object file
Error[149] C:\PIC12F509\PROGRAMS\MULTI+PLEXING LEDS.ASM 62 : Directive only allowed when generating an object file
Error[113] C:\PIC12F509\PROGRAMS\MULTI+PLEXING LEDS.ASM 69 : Symbol not previously defined (lightled1)
Warning[205] C:\PIC12F509\PROGRAMS\MULTI+PLEXING LEDS.ASM 72 : Found directive in column 1. (END)
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\PIC12F509\Programs\Multi+Plexing LEDS.disposable_mcp' failed.
Preprocessor symbol `__DEBUG' is defined.
Wed Jul 30 13:28:24 2008
----------------------------------------------------------------------
BUILD FAILED
 

Attachments

  • multileds.jpg
    36.6 KB · Views: 460
Last edited:
ty AllVol for your help is there any way to Simulate the code

Yes, you can use the debugger sim in MPLAB to see what's going on with your program, but first, you have to have a build that succeeds.

Three errors in your build ---not bad! Here's a little trick I use for error control. While on the output box (where the errors are listed), if you double-click on the error itself it will show you the exact line containing the error. You will see this on the editor page. If it's something you can fix immediately, do so, then compile again. (F10). Do it one error at a time because some times, fixing one error will take care of a bunch of others. If you get an error you just don't know what to do, try commenting out that line and then compiling. The object is to get a build that succeeds, so you can then work with the debugger. (Hint on the lightled1 error: Try putting it in the left-hand column to itself)

Try this, and let me know how you make out. Then, we'll get into the debugger part, if you're ready.

Code:
;Also, when submitting code on the forum, use the # (number)
;symbol on the toolbar at the top of the box. That will put 
;your code in proper form
 
Last edited:
Code:
;Also, when submitting code on the forum, use the # (number)
;symbol on the toolbar at the top of the box. That will put 
;your code in proper form
Or you can type [code] before your code and [/code] after it. Does the same thing as the # icon mentioned above.
 
Or you can type [code] before your code and [/code] after it. Does the same thing as the # icon mentioned above.

If that's all you can find to add to my simple attempt at assistance, then I'm truly humbled and honored. lol!!

By the way, recently, at the advice and assistance of you and others, I managed to download an updated OS for the PICkit2, so I could get into UART. However; the first time I attempt to compile a program in MPLAB, it loadS me back into an older (2.0 something) OS. Which means if I want to use the PICkit2 as stand-alone, if have to re-install the 2.52 version.

I re-installed MPLAB last night, (because of another problem which took hours to figure out), but still have the download thingy.

Do you think I should go to the Microchip site and download perhaps a newer version of MPLAB?
 
I don't know much about that I just got the new version of MPLAB and it works good for me but im still confused as too what too do if I where to put lightled1 by itself like this

Code:
start
lightled1
end

it complies fine by itself without the call command but wouldn't it not call the subroutine lightled1 without the call command?

also I get this error Warning[205] C:\PIC12F509\PROGRAMS\MULTI+PLEXING LEDS.ASM 71 : Found directive in column 1. (END)

and then theres the more complicated ones I can't seem to understand bc its just setting up the PIC watch timer etc

Error[149] C:\PIC12F509\PROGRAMS\MULTI+PLEXING LEDS.ASM 57 : Directive only allowed when generating an object file
Error[149] C:\PIC12F509\PROGRAMS\MULTI+PLEXING LEDS.ASM 62 : Directive only allowed when generating an object file

and the code
Code:
RESET_VECTOR    CODE   0x3FF      ; processor reset vector

; Internal RC calibration value is placed at location 0x3FF by Microchip
; as a movlw k, where the k is a literal value.
    
MAIN    CODE    0x000
    movwf   OSCCAL            ; update register with factory cal value
 
Last edited:
Something like this might work. The compiler likes to see everything in its place:
Code:
lightled1
                   movlw      b'111000' ; Configure GP4 as input
                     tris          GPI0
                     movlw      b'000001' ; Change corresponding bit of GP0 to 1
                     movwf     GPI0 ; Writes 1 to GP0
                     movlw     .50 ; Stays on for .5s:
                     call         delay10 ; Delay of 50 x 10ms = 500ms or .5s
                     movlw     b'000000' ; Change corresponding bit of GP0 to 0
                     movwf     GPI0
                     movlw     b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
                     tris         GPI0 ; Write 0 to GP0
                     retlw 0

Don't worry about warnings just yet. They will not prevent compiling.

These errors are the ones I suggest you comment ( out for now:

Error[149] C:\PIC12F509\PROGRAMS\MULTI+PLEXING LEDS.ASM 57 : Directive only allowed when generating an object file
Error[149] C:\PIC12F509\PROGRAMS\MULTI+PLEXING LEDS.ASM 62 : Directive only allowed when generating an object file

]
 
Yeah fixed the code just added a Tab in front of the end command to fix that error since you said it likes to be all in order now everything is working find and here is the quick build report thats with these errors comment out now for the fun part can you teach me to set up MPLAB so that I can veiw the output pins of GP0-GP5 in real time instead of having to refresh all the time and stuff so that when I make the rest of my subroutines and code everything works correctly and I didn't waste like a hour making the code and it not working correctly or with alot of errors and such

Code:
Error[149] C:\PIC12F509\PROGRAMS\MULTI+PLEXING LEDS.ASM 57 : Directive only allowed when generating an object file
Error[149] C:\PIC12F509\PROGRAMS\MULTI+PLEXING LEDS.ASM 62 : Directive only allowed when generating an object file




Code:
----------------------------------------------------------------------
Debug build of project `C:\PIC12F509\Programs\Multi+Plexing LEDS.disposable_mcp' started.
Preprocessor symbol `__DEBUG' is defined.
Wed Jul 30 23:52:13 2008
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p12F509 "Multi+Plexing LEDS.ASM" /l"Multi+Plexing LEDS.lst" /e"Multi+Plexing LEDS.err" /d__DEBUG=1
Loaded C:\PIC12F509\Programs\Multi+Plexing LEDS.cod.
----------------------------------------------------------------------
Debug build of project `C:\PIC12F509\Programs\Multi+Plexing LEDS.disposable_mcp' succeeded.
Preprocessor symbol `__DEBUG' is defined.
Wed Jul 30 23:52:14 2008
----------------------------------------------------------------------
BUILD SUCCEEDED
 
Last edited:

Okay, looks like we're getting somewhere. But its late. I notice your last build at 11:52:14, way past my bedtime

Can we resume tomorrow?
 
Your code is written to use a linker script but you haven't included one in your project. I would suggest you just use absolute code (without the linker script) for now. You also have a few errors in your code, you have GPI0 (zero) instead of GPIO (letter O) and the end directive needs to be at the end of your code.

I took the liberty of tidying it up and getting it to compile.

Code:
		list	p=12F509	; list directive to define processor
#include	<p12F509.inc> 		; processor specific variable definitions

		__config _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC

; '__CONFIG' directive is used to embed configuration word within .asm file.  
; The lables following the directive are located in the respective .inc file.   
; See respective data sheet for additional information on configuration word.  


		cblock	0x07
;***** VARIABLE DEFINITIONS  
dc1		; Delay Loop Counters
dc2		
dc3		
		endc


;************************************************* *********************  
; Internal RC calibration value is placed at location 0x3FF by Microchip  
; as a movlw k, where the k is a literal value.  

		org	0
MAIN		
		movwf	OSCCAL		; update register with factory cal value 

;******** Main loop 

start
		call	lightled1
		goto	start


;************* Subroutines  

lightled1
		movlw	b'111000'	; Configure GP4 as input
		tris	GPIO
		movlw	b'000001'	; Change corresponding bit of GP0 to 1
		movwf	GPIO		; Writes 1 to GP0
		movlw	.50		; Stays on for .5s:
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	b'000000'	; Change corresponding bit of GP0 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO			; Write 0 to GP0
		retlw	0


delay10					; Delay W x 10ms 
		movwf	dc3		; Delay = 1 + W x (3 + 10009 + 3) - 1 + 4 -> W x 10.015ms
dly2		movlw	.13		; Repeat inner loop 13 times
		movwf	dc2		; -> 13 x (767 + 3) - 1 = 10009 cycles
		clrf	dc1		; Inner loop = 256 x 3 - 1 = 767 cycles
dly1		decfsz	dc1,f
		goto	dly1
		decfsz	dc2,f		; End middle loop
		goto	dly1
		decfsz	dc3,f		; End outer loop
		goto	dly2
		retlw	0

		end

With this code you should be able to select the simulator (Debugger->Select tool->MPLAB Sim) and run it. You can see the port values (+lots more) by viewing the file registers (View->File Registers). You may need to shorten (or remove) your delay when running in the simulator.

Have fun.

Mike.
Edit, having reread the above it is rather abrupt. It wasn't intentional, just the way it came out.
 
Last edited:
Ok thanks for all the help guys I seem to get getting it alot now since I'm now able to see what im doing in debug and in the SIM thanks now for a little add on I was considering since this is going to be placed in a cube fashion and put into clear acrilic plastic I need to have a power switch simple and easy to do theres no problem there but now I need to have two seperate switch's one for a cycle of the LED's from lightled1-lightled12 and one that execs rain drops that im going to be designing untill power is removed but I would like to be able to change it from one to the other so im thinking this since this is going to be programmed on 4 509's to allow for 48 LED's the 2 switches will be hooked onto all the PIC's and on GP3 and GP5 thats no problem as well its the

This is the Switch Code that ive been working on it enables me to have the cycle subroutine loop on pin GP3 when the switch is pressed and have the Random subroutine loop on GP5 when the second switch is pressed now this is my first project with the PIC's and coding them I just learn things really quickly is this the correct way of doing it or is there a better way ? Im posting the whole code so that everyone whos currently helping knows the subroutines since I contiune to add too them

For the Rain part it will just be a combination of all the lightled subroutines and will start at the top and go to the bottom of a cube it will look amazing just have to add delays and such so it looks a little random and will have to make it work with all 4 of the 509's but that shouldn't be too hard I already have the basic layout of the cube and a graph to show what pins need to be turned to what for each LED and I have also changed the subroutine names as well to letters instead of numbers since the scymatic I drew up makes more sence that way then with numbers


Srry updated code there where a few errors in compile that I saw and fixed as well as I updated it wit some of the Ideas I had with a new Cycle subroutine and a Rain subroutine how do you guys like it anything I can do to improve it maby change some of the delay times but I keep adding different effects in every time I work on it so ya how would I go about getting a 5s delay could I just use the delay10 and repeat this as shown below this would be for 1.5s

Code:
movlw	.5
movwf	delay10
movlw	.5
movwf	delay10
movlw	.5
movwf	delay10

Once again updated code but for some reason the debug is not stopping at he switch its going stright too the Cycle Subroutine

Code:
    	list	p=12F509	; list directive to define processor
#include	<p12F509.inc> 		; processor specific variable definitions

		__config _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC

; '__CONFIG' directive is used to embed configuration word within .asm file.  
; The lables following the directive are located in the respective .inc file.   
; See respective data sheet for additional information on configuration word.  


		cblock	0x07
;***** VARIABLE DEFINITIONS  
dc1		; Delay Loop Counters
dc2		
dc3
shadow	; Shadow variable used in rain to keep all top leds on or for cycle to resest all bits to 0
delaytime	; Adjustable delay variable		
		endc


;************************************************* *********************  
; Internal RC calibration value is placed at location 0x3FF by Microchip  
; as a movlw k, where the k is a literal value.  

		org	0
MAIN		
		movwf	OSCCAL		; update register with factory cal value 


;******** Main Code

start
		movlw	b'101000'	; Configure only GP3 and GP5 as a input
		tris	GPIO
		
loop

waitdn	btfsc	GPIO,3		; Wait untill button is pressed on GP3 ( GP3 low )
		goto	waitdn

		call	Cycle

		movlw	.2
		pagesel delay10
		call	delay10		; Delay of 20ms to debounce GP3 ( GP3 low )
		pagesel $

waitdn2	btfsc	GPIO,5		; Wait untill button is pressed on GP5 ( GP5 low )
		goto	waitdn2

;		call	random

		movlw	.2
		pagesel delay10
		call	delay10		; Delay of 20ms to debounce GP5 ( GP5 low )
		pagesel $

		goto	loop





;******** Main Subroutine's / Effects

Cycle
		movlw	.5
		movwf	delaytime
		movlw	b'000000'
		movwf	shadow
		call	lightledA
		call	lightledB
		call	lightledC
		call	lightledD
		call	lightledE
		call	lightledF
		call	lightledG
		call	lightledH
		call	lightledI
		call	lightledJ
		call	lightledK
		call	lightledL
		goto	Cycle

Rain

		movlw	b'000000'
		movwf	shadow
		movlw	.2
		movwf	delaytime
		call	lightledA
		call	lightledD
		call	lightledG
		call	lightledJ
		movlw	.9
		call	delay10
		movlw	.3
		movwf	delaytime
		call	lightledC
		call	lightledF
		call	lightledI
		call	lightledL
		movlw	.9
		call	delay10
		movlw	.9
		call	delay10
		movlw	.9
		movwf	delaytime
		call	lightledA
		call	lightledD
		call	lightledG
		call	lightledJ
		movlw	.9
		call	delay10
		movlw	.9
		call	delay10
		movlw	.9
		call	delay10
		movlw	.4
		movlw	delaytime
		call	lightledB
		call	lightledE
		call	lightledH
		call	lightledK
		goto	Rain

Randomeffect

		movlw	b'000000'
		movwf	shadow
		movlw	.2
		movwf	delaytime
		call	lightledE
		call	lightledH
		call	lightledA
		call	lightledB
		call	lightledC
		call	lightledF
		call	lightledI
		call	lightledL
		call	lightledK
		call	lightledJ
		call	lightledG
		call	lightledD
		call	lightledE
		call	lightledH
		call	lightledA
		call	lightledB
		call	lightledC
		call	lightledF
		call	lightledI
		call	lightledL
		call	lightledK
		call	lightledJ
		call	lightledG
		call	lightledD
		call	lightledE
		call	lightledH
		call	lightledA
		call	lightledB
		call	lightledC
		call	lightledF
		call	lightledI
		call	lightledL
		call	lightledK
		call	lightledJ
		call	lightledG
		call	lightledD
		goto	Randomeffect
		

	
		
		

;************* Subroutines

;****************** LED Subroutines 

lightledA
		movlw	b'111010'	; Configure GP4 and GP1 as input
		tris	GPIO
		movlw	b'000001'	; Change corresponding bit of GP0 to 1
		movwf	GPIO		; Writes 1 to GP0
		movlw	delaytime		; Get from dealytime variable
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	shadow	; Change corresponding bit of GP0 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO			; Write 0 to GP0
		retlw	0

lightledB
		movlw	b'001110'	; Configure GP1 and GP2 as inputs
		tris	GPIO
		movlw	b'000001'	; Change corresponding bit of GP0 to 1
		movwf	GPIO		; Writes 1 to GP0
		movlw	delaytime		; Get from dealytime variable
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	shadow	; Change correspoding bit of GP1 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO
		retlw	0

lightledC
		movlw	b'001110'	; Configure pins GP1 and GP2 to inputs
		tris	GPIO
		movlw	b'010000'	; Change corresponding bit of GP4 to 1
		movwf	GPIO		; Writes 1 to GP4
		movlw	delaytime		; Get from dealytime variable
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	shadow	; Change correspoding bit of GP4 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO
		retlw	0

lightledD
		movlw	b'011001'	; Configure pins GP1 and GP4 to inputs
		tris	GPIO
		movlw	b'000100'	; Change corresponding bit of GP2 to 1
		movwf	GPIO		; Writes 1 to GP2
		movlw	delaytime		; Get from dealytime variable
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	shadow	; Change correspoding bit of GP2 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO
		retlw	0

lightledE
		movlw	b'011001'	; Configure pins GP0 and GP4 to inputs
		tris	GPIO
		movlw	b'000010'	; Change corresponding bit of GP1 to 1
		movwf	GPIO		; Writes 1 to GP1
		movlw	delaytime		; Get from dealytime variable
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	shadow	; Change correspoding bit of GP2 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO
		retlw	0

lightledF
		movlw	b'001101'	; Configure pins GP0 and GP2 to inputs
		tris	GPIO
		movlw	b'010000'	; Change corresponding bit of GP4 to 1
		movwf	GPIO		; Writes 1 to GP4
		movlw	delaytime		; Get from dealytime variable
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	shadow	; Change correspoding bit of GP4 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO
		retlw	0

lightledG
		movlw	b'011100'	; Configure pins GP2 and GP4 to inputs
		tris	GPIO
		movlw	b'000010'	; Change corresponding bit of GP1 to 1
		movwf	GPIO		; Writes 1 to GP1
		movlw	delaytime		; Get from dealytime variable
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	shadow	; Change correspoding bit of GP0 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO
		retlw	0

lightledH
		movlw	b'011001'	; Configure pins GP0 and GP4 to inputs
		tris	GPIO
		movlw	b'000100'	; Change corresponding bit of GP2 to 1
		movwf	GPIO		; Writes 1 to GP2
		movlw	delaytime		; Get from dealytime variable
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	shadow	; Change correspoding bit of GP2 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO
		retlw	0

lightledI
		movlw	b'001011'	; Configure pins GP0 and GP1 to inputs
		tris	GPIO
		movlw	b'000110'	; Change corresponding bit of GP1 to 1
		movwf	GPIO		; Writes 1 to GP1
		movlw	delaytime		; Get from dealytime variable
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	shadow	; Change correspoding bit of GP1 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO
		retlw	0

lightledJ
		movlw	b'011100'	; Configure pins GP2 and GP4 to inputs
		tris	GPIO
		movlw	b'001001'	; Change corresponding bit of GP0 to 1
		movwf	GPIO		; Writes 1 to GP0
		movlw	delaytime		; Get from dealytime variable
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	shadow	; Change correspoding bit of GP1 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO
		retlw	0

lightledK
		movlw	b'011001'	; Configure pins GP0 and GP4 to inputs
		tris	GPIO
		movlw	b'000010'	; Change corresponding bit of GP1 to 1
		movwf	GPIO		; Writes 1 to GP1
		movlw	delaytime		; Get from dealytime variable
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	shadow	; Change correspoding bit of GP0 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO
		retlw	0

lightledL
		movlw	b'001110'	; Configure pins GP0 and GP1 to inputs
		tris	GPIO
		movlw	b'010000'	; Change corresponding bit of GP4 to 1
		movwf	GPIO		; Writes 1 to GP4
		movlw	delaytime		; Get from dealytime variable
		call	delay10		; Delay of 50 x 10ms = 500ms or .5s
		movlw	shadow	; Change correspoding bit of GP0 to 0
		movwf	GPIO
		movlw	b'101000'	; Configure GP0,GP1,GP2,GP4 to outputs
		tris	GPIO
		retlw	0

;****************** Delay Subroutine ( 10 ms )

delay10					; Delay W x 10ms 
		movwf	dc3		; Delay = 1 + W x (3 + 10009 + 3) - 1 + 4 -> W x 10.015ms
dly2		movlw	.13		; Repeat inner loop 13 times
		movwf	dc2		; -> 13 x (767 + 3) - 1 = 10009 cycles
		clrf	dc1		; Inner loop = 256 x 3 - 1 = 767 cycles
dly1		decfsz	dc1,f
		goto	dly1
		decfsz	dc2,f		; End middle loop
		goto	dly1
		decfsz	dc3,f		; End outer loop
		goto	dly2
		retlw	0

		end
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…