Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 5th September 2008, 04:14 AM   #16
Default

Ya you lost me at RLF haha wow this may seem alot more complicated then I thought it would be there's no simple way to take a string and seperate it is there ? haha I've just looked on google with little answer's the only problem is that the 509 doesn't have a interrupt so im not sure what to do from there. I know how to place the string into a variable then read that variable im just not sure how to take each bit apart. I also know how how to write it too the pin I just can't take the bit's apart and thats the problem bc soon as I get that my code goes from a whole bunch of lines to almost half and making sequences are so much easyer as well. Also I think if I understand it right your way of doing it with RLF will only allow me to have on pin on at a time

Last edited by Darkstar64; 5th September 2008 at 04:16 AM.
Darkstar64 is offline  
Old 5th September 2008, 04:36 AM   #17
Default

Quote:
Originally Posted by Darkstar64 View Post
Ya you lost me at RLF haha wow this may seem alot more complicated then I thought it would be
That's why I said you might be a bit too green to tackle something like this.

Quote:
there's no simple way to take a string and seperate it is there?
A byte is not a string. And rotating the bit you want to test into the carry is pretty darn simple.

Quote:
the only problem is that the 509 doesn't have a interrupt so im not sure what to do from there.
Oh! This is that PIC. I really would recommend you use a bigger, more capable PIC for a job like this. Without interrupts, and with so few resources, this will be hard! Get a 16F88 or better yet, an 18F1320. Or even a bigger PIC. The little 8-pinners are tough for beginners. They're tight for resources and pins. Great for saving money if you're in production or your project is very simple, but tough to do more complex things without a lot of planning and knowhow.

Quote:
I know how to place the string into a variable then read that variable im just not sure how to take each bit apart. I also know how how to write it too the pin I just can't take the bit's apart and thats the problem bc soon as I get that my code goes from a whole bunch of lines to almost half and making sequences are so much easier as well.
Learning how to isolate, move and test bits, nybbles and whole bytes is what it's all about when programming PICs (or any computer) in any but the most elementary way. You must understand bit operations fluently before you'll be able to complete a project like this.

Sounds very much like you need to work up to a project like this. Start with some simpler projects (sub-sections of this project would be great!) and gradually you'll learn the things you need to know to tackle tougher projects like a LED cube.

Quote:
Also I think if I understand it right your way of doing it with RLF will only allow me to have on pin on at a time
Not true at all. You just keep rotating bits in and checking them, and putting the results on the data line and clocking them out.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 5th September 2008 at 04:45 AM.
futz is offline  
Old 5th September 2008, 12:27 PM   #18
Default

ok ya I might have to work up to it like you said can you give me a few project names or links too where I can start learning more about this ?
Darkstar64 is offline  
Old 5th September 2008, 03:22 PM   #19
Default

Quote:
Originally Posted by Darkstar64 View Post
ok ya I might have to work up to it like you said can you give me a few project names or links too where I can start learning more about this ?
Start by breadboarding up your 12F509 and the 74HC595 with 8 LEDs. Tinker with getting the 595 to light LEDs under your control. Learn to use rlf and rrf.

Once you have that working, take the high nybble of one byte and use that to light the left 4 LEDs and take the low nybble of another byte and use that to light the right 4 LEDs. Have fun!
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 5th September 2008 at 03:23 PM.
futz is offline  
Old 5th September 2008, 03:50 PM   #20
Default

Srry im still not understanding We have the whole thing figured out other then the engine now looking at one that was made before by someone ealse who was helping me but we were not using shift regiesters at the time it looks like this using just the I/0 pins on the PIC. Also since im going to be using all the I/0 pins on the pick what do I need to do In curcuit programming. I'm not sure what pins the 509 uses to program and what I need to do to seperate the PIC from the rest of the curcuit as well. When I am programming the PIC I know it needs to be seperated from everything so that it doesn't fail in programming. Ok I get what rlf and rrf do now they move the bits left and right now from there I just write the carry bit to the data pin and move to the next bit right ? Now how do I write the carry flag im not sure what location its in ? Basically your telling me to first set what LED's I want on by something like this b'10100100'. Then I would use RLF to move the first bit into the carry flag and write that to the data pin. Then I would then use RLF again and that would take the bit in the carry flag and move it too the end so it would then be '01001001' right ? and put the new bit in then I would write that to the shift etc etc ?

Last edited by Darkstar64; 5th September 2008 at 04:00 PM.
Darkstar64 is offline  
Old 5th September 2008, 04:09 PM   #21
Default

srry for the double post but like this ? Im still not sure how to access the carry flag im not sure the location of it ? and would I be able to do the same thing with a 12 output shift register using 12 digits instead of 8 ? like so '000000000000' then do the same thing with RLF to move it into the carry flag like the same thing with the 8 output shift

Code:
                    C 76543210
                    0 00000001
            RLF     0 00000010
            RLF     0 00000100
            RLF     0 00001000
            RLF     0 00010000
            RLF     0 00100000
            RLF     0 01000000
            RLF     0 10000000
            RLF     1 00000000
            RLF     0 00000001

Last edited by Darkstar64; 5th September 2008 at 04:41 PM.
Darkstar64 is offline  
Old 6th September 2008, 01:46 AM   #22
Default

Quote:
Originally Posted by Darkstar64 View Post
We have the whole thing figured out other then the engine now. Looking at one that was made before by someone else who was helping me, but we were not using shift registers at the time.
I was thinking about it today. You're right - it probably can be done without interrupts. It'll be tight for code space, but you can probably squeeze it in.

Quote:
Also since I'm going to be using all the I/0 pins on the PIC what do I need to do in circuit programming?
What I do is just put in SPDT switches for the PGD, PGC and MCLR lines, like in this project. You could do it with jumpers too, but they're not nearly so convenient.

Quote:
I'm not sure what pins the 509 uses to program and what I need to do to separate the PIC from the rest of the curcuit as well. When I am programming the PIC I know it needs to be seperated from everything so that it doesn't fail in programming.
Look at the datasheet in section 7.12. GP0 is PGD, GP1 is PGC and GP3 is MCLR. Isolate them as noted above when programming.

Quote:
Now how do I write the carry flag im not sure what location its in?
Here's another thing you must learn. The STATUS register is covered in section 4.4 of the datasheet (page 20). You must know this register by heart. It gets used constantly.

Use a BTFSC or BTFSS to test the carry bit and either write one value if no branch or if there is a branch to write the other value to the data pin.

Quote:
Basically your telling me to first set what LED's I want on by something like this b'10100100'. Then I would use RLF to move the first bit into the carry flag and write that to the data pin.
Don't write that exact bit, but say if that bit is 1, the test takes execution to a line that puts a 1 on the data pin. If that bit is 0 it goes to another line that puts a 0 on the data pin. Then it goes to code that blips the clock and repeats the whole thing.

Quote:
Then I would then use RLF again and that would take the bit in the carry flag and move it to the end so it would then be '01001001' right? and put the new bit in then I would write that to the shift etc etc?
Sort of, ya.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 6th September 2008, 01:48 AM   #23
Default

Quote:
Originally Posted by Darkstar64 View Post
Im still not sure how to access the carry flag im not sure the location of it?
See previous post regarding status register.

Quote:
Would I be able to do the same thing with a 12 output shift register using 12 digits instead of 8 ? like so '000000000000' then do the same thing with RLF to move it into the carry flag like the same thing with the 8 output shift
Not exactly like that because the PIC you're using is an 8-bit model. You would have to use one byte and half of another and write code to use them both in the proper order.

Quote:
like this?
Code:
                    C 76543210
                    0 00000001
            RLF     0 00000010
            RLF     0 00000100
            RLF     0 00001000
            RLF     0 00010000
            RLF     0 00100000
            RLF     0 01000000
            RLF     0 10000000
            RLF     1 00000000
            RLF     0 00000001
Yes. You would stop before that last line. Do a loop count of 8, for 8 bits.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 6th September 2008 at 01:57 AM.
futz is offline  
Old 6th September 2008, 06:45 PM   #24
Default

Basically the whole thing would look something like this right ? but im having some build errors all post them under the code

Code:
;******** Main Code

start
		movlw   b'001000'       ; Configure only GP3 as a input
        tris    GPIO
        
loop

		movlw	b'00100001'
		movwf	Display
		call	Engine
		
		goto	loop


;******** Subroutines

Engine
		RLF		Display
		call	test_clock
		RLF		Display
		call	test_clock
		RLF		Display
		call	test_clock
		RLF		Display
		call	test_clock
		RLF		Display
		call	test_clock
		RLF		Display
		call	test_clock
		RLF		Display
		call	test_clock
		RLF		Display
		call	test_clock
		movlw	b'000100'
		movwf	GPIO
		retlw	0
		
test_clock
		BTFSC 03h,b
		movlw	b'000000'		; Moves 0 on Data pin
		movwf	GPIO
		movlw	b'000010'		; Clocks it
		movwf	GPIO
		movlw	b'000000'
		movwf	GPIO
		BTFSC 03h,b
		movlw	b'000001'		; Moves 1 on Data pin
		movwf	GPIO
		movlw	b'000010'		; Clocks it
		movwf	GPIO
		movlw	b'000000'
		movwf	GPIO
		retlw	0		
	END					; End of Program !
Code:
----------------------------------------------------------------------
Debug build of project `C:\PIC12F509\Programs\LED_Matrix.disposable_mcp' started.
Preprocessor symbol `__DEBUG' is defined.
Sat Sep 06 13:45:30 2008
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p12F509 "LED_Matrix.ASM" /l"LED_Matrix.lst" /e"LED_Matrix.err" /d__DEBUG=1
Error[149]   C:\PIC12F509\PROGRAMS\LED_MATRIX.ASM 57 : Directive only allowed when generating an object file
Error[149]   C:\PIC12F509\PROGRAMS\LED_MATRIX.ASM 62 : Directive only allowed when generating an object file
Message[305] C:\PIC12F509\PROGRAMS\LED_MATRIX.ASM 85 : Using default destination of 1 (file).
Message[305] C:\PIC12F509\PROGRAMS\LED_MATRIX.ASM 87 : Using default destination of 1 (file).
Message[305] C:\PIC12F509\PROGRAMS\LED_MATRIX.ASM 89 : Using default destination of 1 (file).
Message[305] C:\PIC12F509\PROGRAMS\LED_MATRIX.ASM 91 : Using default destination of 1 (file).
Message[305] C:\PIC12F509\PROGRAMS\LED_MATRIX.ASM 93 : Using default destination of 1 (file).
Message[305] C:\PIC12F509\PROGRAMS\LED_MATRIX.ASM 95 : Using default destination of 1 (file).
Message[305] C:\PIC12F509\PROGRAMS\LED_MATRIX.ASM 97 : Using default destination of 1 (file).
Message[305] C:\PIC12F509\PROGRAMS\LED_MATRIX.ASM 99 : Using default destination of 1 (file).
Error[113]   C:\PIC12F509\PROGRAMS\LED_MATRIX.ASM 106 : Symbol not previously defined (b)
Error[113]   C:\PIC12F509\PROGRAMS\LED_MATRIX.ASM 113 : Symbol not previously defined (b)
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\PIC12F509\Programs\LED_Matrix.disposable_mcp' failed.
Preprocessor symbol `__DEBUG' is defined.
Sat Sep 06 13:45:31 2008
----------------------------------------------------------------------
Darkstar64 is offline  
Old 6th September 2008, 11:39 PM   #25
Default

One issue that I have not seen mentioned is the memory addressing limitations of baseline PICs of which the 12F509 is a member. These PICs have the instruction space divided into 512 word pages. Only the first 256 words of a page can be used as the destination of a subroutine call or instruction that modifies PCL. In addition, care must be taken that the page select bits in the STATUS register are set for a GOTO, CALL, or instruction that modifies the PCL. These characteristics can severely limit table lookups used for pattern generation.

An inexpensive mid-range chip such as a 16F627A/628A is much better suited for this project and is probably cheaper in the long run, i.e. one PIC vs One PIC and two shift registers.
skyhawk is online now  
Old 7th September 2008, 05:03 AM   #26
Default

Yes many have said such things about getting a new PIC but as for now im sticking too the 509 untill I understand assembly much more. As of right now im just going back looking how I did things in the past following tut's etc... So at the moment I just need help on what ive written and if its correct or not and why its not building right ?
Darkstar64 is offline  
Old 7th September 2008, 05:31 AM   #27
Default

Some of your errors I can't help with as you haven't included all your code.

The Message[305]s are caused by not having a destination on your RLFs. You need either F for file or W for W tagged on the end of the instructions.
I.E.
Code:
		RLF	Display,F
or
		RLF	Display,W
The Error[113]s are caused by the BTFSC 03h,b instructions.
I assume you are trying to test the Carry flag and if so it should be BTFSC STATUS,C.
You should also note that this instruction only skips the following instruction, you appear to expect it to jump over several.

Can I suggest you change your subroutine to,
Code:
test_clock
		movlw	b'000001'	;value to send 1 bit
		BTFSS	STATUS,C	;carry set
		movlw	b'000000'	;no so use value to send zero bit
		movwf	GPIO		;put it on port
		nop			;avoid RMW problem
		bsf	GPIO,1		; Clocks it
		nop			;short delay
		bcf	GPIO,1		;finish clocking
		retlw	0
HTH

Mike.
Pommie is online now  
Old 8th September 2008, 02:06 AM   #28
Default

Thanks Mike all errors are fixed now so now all I have to do is just make my pattern and call the engine and it should understand what im giving it and write what I need to the Data Pin and clock it then go to the next pattern right since I now have the engine figured out ? And thanks again for helping my teacher is going to be happy haha

Last edited by Darkstar64; 8th September 2008 at 03:39 AM.
Darkstar64 is offline  
Old 8th September 2008, 12:24 PM   #29
Default

Quote:
Yes many have said such things about getting a new PIC but as for now im sticking too the 509 untill I understand assembly much more. As of right now im just going back looking how I did things in the past following tut's etc... So at the moment I just need help on what ive written and if its correct or not and why its not building right ?
But most of my post was a warning about addressing quirks of baseline PICs. If your program gets longer than 256 words there are issues with regard to where you place your subroutines. If you should choose to implement your patterns using table lookups this can become important if the tables occupy a large portion of memory.

I also remind you that the return stack is two levels deep so there is a servere restriction on the nesting of subroutines, at lest on those invoked with a CALL instruction.

Perhaps it is best just to let you discover these thing for yourself!
skyhawk is online now  
Old 8th September 2008, 05:24 PM   #30
Default

Hi skyhawk,

I agree totally that switching to a better chip would be the best solution.

However, you are not completely correct on your description of the 12 bit chips. On the 509 you can make calls to addresses in the 0x200-0x2ff region by setting the PA0 bit in status. You can also use the two pages that are not accessible to calls for tables as computed gotos will still work.

Darkstar,
What skyhawk states is so true. You are making your life so much harder by staying with the 12 bit chips. Switching to a 14 bit chip (12F683 - still 8 pins) will give you so much more flexibility.


Mike.
Pommie is online now  
Reply

Tags
pic, registers, shift, working

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
16 bit serial in parallel out shift registers forder Electronic Projects Design/Ideas/Reviews 14 2nd March 2009 09:17 AM
Cascading Shift Registers Help Suraj143 Electronic Projects Design/Ideas/Reviews 13 5th June 2008 08:33 AM
Load shift-registers via SPI? Mike, K8LH Micro Controllers 14 14th February 2008 03:00 AM
Help loading shift registers... jrz126 Micro Controllers 0 14th November 2005 01:13 PM
shift registers jrz126 Electronic Projects Design/Ideas/Reviews 8 25th September 2004 02:35 AM



All times are GMT. The time now is 02:17 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker