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
 
LinkBack Thread Tools Display Modes
Old 17th August 2008, 02:29 AM   (permalink)
Default

Yes this Main code builds fine Pommie here is the log file of it also what about the switch part of it is it possible if you hold the switch down for X number of seconds it will go to one routine but if you just hold it for lets say 1 second it runs a different routine ? I also see how you call the LED's now but im not sure what your getting at about changing the numbers since 0x55 in binary is 01010101 and in decimal its 85 ? and 10101010 doesn't correspond to anything under Multiplex unless you where just showing me how to do it without giving it away in that case I would just need to get the binary changed to Hexadeciaml and thats pretty simple

Code:
----------------------------------------------------------------------
Debug build of project `C:\PIC12F509\Programs\LED_Cube_rev3 .disposable_mcp' started.
Preprocessor symbol `__DEBUG' is defined.
Sat Aug 16 21:04:46 2008
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p12F509 "LED_Cube_rev3 .ASM" /l"LED_Cube_rev3 .lst" /e"LED_Cube_rev3 .err" /d__DEBUG=1
Loaded C:\PIC12F509\Programs\LED_Cube_rev3 .cod.
----------------------------------------------------------------------
Debug build of project `C:\PIC12F509\Programs\LED_Cube_rev3 .disposable_mcp' succeeded.
Preprocessor symbol `__DEBUG' is defined.
Sat Aug 16 21:04:47 2008
----------------------------------------------------------------------
BUILD SUCCEEDED
Darkstar64 is offline  
Old 17th August 2008, 03:17 AM   (permalink)
Default

What does the code do? What it should do is light half the LEDs when the button is pressed. Changing the two numbers should light different LEDs. If this part is working then to make it change patterns is the next step.

Mike.
Pommie is offline  
Old 17th August 2008, 03:29 AM   (permalink)
Default

I can't really test it as I don't have the programmer to do so at the moment its at school and its locked for the summer so all keep this code as a backup can you explain how to get the LED's to light up without just randomly trying numbers and seeing what works and what doesn't ? is it using Hex ? not sure bc 0x55 doesn't correspond to any of the values of the Multiplex routine ?
Darkstar64 is offline  
Old 17th August 2008, 03:49 AM   (permalink)
Default

The 12 LEDs are lit by setting a bit in the variables LEDs and LEDs2 (only 4 bits in this one). So, 0x555 should light every odd numbered LED, 0xAAA would light the even LEDs, 0x001 would light just LED1, 0x007 would light LED1,2 & 3 etc.

Without being able to test it on the hardware makes it very difficult to progress. Coding is best done in little steps, get one bit working and then move on to the next.

Mike.
Pommie is offline  
Old 17th August 2008, 04:09 AM   (permalink)
Default

Ok well all wait till I get the hardware then but I do still need to know how to do the timed switch if its possible ? allowing 2 different routines to be called depending on how long you hold the switch for

Last edited by Darkstar64; 17th August 2008 at 04:10 AM.
Darkstar64 is offline  
Old 17th August 2008, 05:05 AM   (permalink)
Default

This is how I would write code so that a pattern is displayed when the switch is pressed and then a different pattern would be displayed 1 second later.
Code:
;******** Main Code
start
        movlw   b'001000'       ; Configure only GP3 as a input
        tris    GPIO
loop	btfsc   GPIO,3          ; Is switch 3 pressed?
        goto    TurnOn          ;yes so go turn on LEDs
	clrf	LEDs		;turn off LEDs
	clrf	LEDs2
	clrf	DisplayCount	;reset counter
	goto	Display
TurnOn	movfw	DisplayCount
	xorlw	.10		;reached 1 second
	btfsc	STATUS,Z
	goto	Pattern2	;yes, go do pattern 2
	incf	DisplayCount,F	;increment counter - only if displaying pattern 1
	;do pattern 1
	movlw	0x55		;setup pattern 1
	movwf	LEDs
	movlw	0x05
	movwf	LEDs2
	goto	Display
Pattern2
	movlw	0xAA		;setup pattern 2
	movwf	LEDs
	movlw	0x0A
	movwf	LEDs2
Display
	movlw	.25		;400uS * 25 = 10mS
	movwf	MultiCount	
DisLoop	call	Multiplex	;this takes 400uS
	decfsz	MultiCount,F	;time up
	goto	DisLoop		;no, so do it again
	goto	loop		

;****************** Delay Subroutine ( 10 ms )
Note how calling multiplex 25 times makes up a delay of 10mS and therefore makes timing 1 second very easy.

Have fun.

Mike.
Pommie is offline  
Old 17th August 2008, 08:02 AM   (permalink)
Default

Pommie I ment like if you just hit the switch for a second then released it it would run a routine but if you held it for 5 seconds it would play the other routine and not the first one is this possible it will maby be a week before I can get any of the hardware at all so im still just trying to figure out the code for the switch but other then that everything is great including the multiplex routine and im kinda understanding how to turn each LED on and what not now I just have to find the 12F509's again in my house ahah by that time all have all the stuff I need and can start scewing with things to see what works what doesn't thanks

Last edited by Darkstar64; 18th August 2008 at 02:04 AM.
Darkstar64 is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Help with the PIC12F509 Darkstar64 Micro Controllers 13 31st July 2008 04:59 PM
is this the correct code for DS18s20?? neels Micro Controllers 0 13th March 2005 05:13 AM
Am I correct? Jef Patat Electronic Projects Design/Ideas/Reviews 2 8th February 2005 04:49 PM
Is this correct? brodin Micro Controllers 7 14th March 2004 01:01 PM
basic code need help: cannot produce correct result huanyong Micro Controllers 7 22nd October 2003 11:16 PM



All times are GMT. The time now is 04:09 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker