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
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: