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
 
Thread Tools Display Modes
Old 21st May 2008, 02:06 AM   (permalink)
Default

thanks, I will give it a try now.
matlark is offline   Reply With Quote
Old 21st May 2008, 02:43 AM   (permalink)
Default

OK 1 question

Are you trying to pick a radom value from the table?

If so why dont you just make a loop that increases a value in the WREG and when a interrupt occurs then put the value into a variable and at the end of the loop or in the ISR have it goto the specific location in the table by adding that value to the PCL.

Ill try to make you a example
AtomSoft is offline   Reply With Quote
Old 21st May 2008, 03:05 AM   (permalink)
Default

hope you can understand this its like 11pm here and ive been up since 5am so hope im not going nuts

Code:
	list		p=16f887	; list directive to define processor
	#include	<p16f887.inc>	; processor specific variable definitions

	__CONFIG    _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
	__CONFIG    _CONFIG2, _WRT_OFF & _BOR21V

    cblock     0x20
	Delay1         ; Assign an address to label Delay1
	Delay2
	Display        ; define a variable to hold the diplay
	Direction
	LookingFor
	temp1
	die1
	temp2
	die2 
    endc
     
    cblock      0x70
	W_Save              
	STATUS_Save
	MyVar
	MyVar2
    endc
	
    org 0x00
    goto Start

    org	0x004				; interrupt vector location
    goto ISR

Init:
     clrf   PORTA   ; Clears memory in file register A
     clrf   PORTB   ; Clears memory in file register B
     clrf   PORTC   ; Clears memory in file register C
     clrf   PORTD   ; Clears memory in file register D
     clrf   PORTE   ; Clears memory in file register E 
     bsf    STATUS,RP0     ; select Register Bank 
     bsf    IOCB,0
     movlw     0x01
     movwf     TRISB          ; Make RB0 input
     clrf      TRISD          ; Make PortD all output
     movlw     b'10011000' 
     movwf     INTCON
     bcf    STATUS,RP0
     bsf    STATUS,RP0
     movlw     b'00000111'
     movwf     OPTION_REG     ; Maximum Prescale
     bcf       STATUS,RP0     ; back to Register Bank 0 
     return

ISR:   
	movwf     W_Save              ; Save context
	movf      STATUS,w
	movwf     STATUS_Save
	bcf       INTCON,INTF

DieNumSel:
	bcf     INTCON,0
	btfsc	MyVar, 0
	call 	Tabledie1    ;calls tabledie1
	btfsc	MyVar2, 0
	call	Tabledie2
	NOP
	movwf   PORTD
ExitISR:
	movf      STATUS_Save,w       ; Restore context
	movwf     STATUS
	swapf     W_Save,f            ; swapf doesn't affect Status bits, but MOVF would
	swapf     W_Save,w
	retfie

Tabledie1:
	MOVF 	MyVar, 0
    addwf   PCL,f            ;jump to
	retlw	b'10000000'
	retlw	b'00000001'
	retlw	b'00000010'
	retlw	b'00000011'
	retlw	b'00000100'
	retlw	b'00000101'
	retlw	b'00000110'
	retlw	b'10000111'
Tabledie2:
	MOVF 	MyVar2, 0
    addwf   PCL,f            ;jump to
	retlw	b'10000000'
	retlw	b'00000001'
	retlw	b'00000010'
	retlw	b'00000011'
	retlw	b'00000100'
	retlw	b'00000101'
	retlw	b'00000110'
	retlw	b'10000111'

Start:
    call Init
	movlw 0x00
	movwf MyVar
	movwf MyVar2
rotate:
     bsf       STATUS,RP0     ; select Register Bank 1
     clrf      TRISD          ; make IO PortD all output
     bcf       STATUS,RP0     ; back to Register Bank 0
     movlw     0xDF
     movwf     Display

MainLoop:
     movf      Display,w      ; Copy the display to the LEDs
     movwf     PORTD
OndelayLoop:
     decfsz    Delay1,f       ; Waste time.  
     goto      OndelayLoop    ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
     decfsz    Delay2,f       ; The outer loop takes and additional 3 instructions per lap * 256 loops
     goto      OndelayLoop    ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
                              ; call it two-tenths of a second.
     
     bcf       STATUS,C       ; ensure the carry bit is clear
     rrf       Display,f
     btfsc     STATUS,C       ; Did the bit rotate into the carry?
     bsf       Display,7      ; yes, put it into bit 7.

	INCF MyVar
	;add delay
	INCF MyVar
	;add delay
	INCF MyVar
	;add delay
	INCF MyVar
	;add delay
	INCF MyVar
	;add delay
	INCF MyVar
	;add delay
	INCF MyVar
	;add delay
	INCF MyVar
	;add delay
	movlw 0x00
	movwf MyVar
	INCF MyVar2
	;add delay
	INCF MyVar2
	;add delay
	INCF MyVar2
	;add delay
	INCF MyVar2
	;add delay
	INCF MyVar2
	;add delay
	INCF MyVar2
	;add delay
	INCF MyVar2
	;add delay
	INCF MyVar2
	;add delay
	movlw 0x00
	movwf MyVar2
	
    goto MainLoop
	
	 end
AtomSoft is offline   Reply With Quote
Old 21st May 2008, 02:55 PM   (permalink)
Default

Thanks for all your help. I dont have my computer with me but I will give it a shot this afternoon. I am trying to pick a random number.
matlark is offline   Reply With Quote
Old 21st May 2008, 03:18 PM   (permalink)
Default

ok good luck
AtomSoft is offline   Reply With Quote
Old 21st May 2008, 06:42 PM   (permalink)
Default

I am working on the same project as matlark. we are working with a PIC 16F887 on MPLAB IDE 8.0 software.

we are trying to display LEDs in rotation initially, then when a button is pushed two die values should display, after another button push the program should return to the LEDs rotating.

however the interrupt for the button seems to go unrecognized. I attached my program as well.
Attached Files
File Type: asm dice w interupt.asm (7.9 KB, 4 views)
cumbybl is offline   Reply With Quote
Old 21st May 2008, 06:43 PM   (permalink)
Default

i forgot to mention that i tried your(atomsoft) code and the LEDs rotated but the button did not change the state.
cumbybl is offline   Reply With Quote
Old 21st May 2008, 09:40 PM   (permalink)
Default

when you say die do you mean dice?
AtomSoft is offline   Reply With Quote
Old 21st May 2008, 10:19 PM   (permalink)
Default

if its not to much to ask can i see a schematic or at least some type of layout
AtomSoft is offline   Reply With Quote
Old 21st May 2008, 10:38 PM   (permalink)
Default

Quote:
Originally Posted by AtomSoft View Post
when you say die do you mean dice?
Yes, he does. Dice - Wikipedia, the free encyclopedia
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline   Reply With Quote
Old 21st May 2008, 10:42 PM   (permalink)
Default

so instead of two die values you want 2 dice values lol ok maybe i can understand more now lol So you have LEDs representing some dice and want its to rotate the LEDs and when a button is pressed it stops on a random dice values and then waits and continues like its rolling dice?
Does this sound true?
AtomSoft is offline   Reply With Quote
Old 21st May 2008, 11:39 PM   (permalink)
Default

Based on what I read;

the dice should be rotating on startup, when the button is pressed, they would stop on a random(As Random as it can get) value. It should remain on those values until the button is pressed again, where it would go back to rotation.

I looked through the code (quickly) and I didn't see a de-bounce, or did I miss it??


-BaC
__________________
Error: {Panic!} when trying to load: [reality shell]. kernel: "universe has been halted"...
Information Underground

Last edited by BaCaRdi; 21st May 2008 at 11:46 PM.
BaCaRdi is offline   Reply With Quote
Old 22nd May 2008, 01:28 AM   (permalink)
Default

sorry everyone. i was thinking of two values, one for each die. Anyways here is how the program should work:

LEDs rotate--> button press-->display dice-->button press again-->go back to LEDs just rotating. the rotation is just shifting of the LEDs thats all.

There is not a debounce as of yet.
cumbybl is offline   Reply With Quote
Old 22nd May 2008, 12:10 PM   (permalink)
Default

im still here but had to work yesterday sorry um... we have to make another variable that has to be set when isr is done so when we go into isr again thats the first thing we check and if set skip and goto rotate and if not set then skip all other code and goto a infinite loop until a interrupt is brought up again like:

check IntVar if 0
show dice
if 1 then
rotate...
AtomSoft is offline   Reply With Quote
Old 22nd May 2008, 01:50 PM   (permalink)
Default

Funny, I didn't know there was programmers in Brooklyn, let alone good ones! Next you will tell me your from Bensonhurst..hehe jk

Have to say, I miss home! Cali is OK but it's no NY!

-BaC

Quote:
Originally Posted by AtomSoft View Post
im still here but had to work yesterday sorry um... we have to make another variable that has to be set when isr is done so when we go into isr again thats the first thing we check and if set skip and goto rotate and if not set then skip all other code and goto a infinite loop until a interrupt is brought up again like:

check IntVar if 0
show dice
if 1 then
rotate...
__________________
Error: {Panic!} when trying to load: [reality shell]. kernel: "universe has been halted"...
Information Underground

Last edited by BaCaRdi; 22nd May 2008 at 01:51 PM.
BaCaRdi is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Interrupt triggering communication with a host computer and counting interrupt calls ssylee Micro Controllers 1 12th May 2008 06:08 AM
odd project, 1 button adds a light 1 button takes a light away with sound. KevinAlaska Electronic Projects Design/Ideas/Reviews 15 6th June 2007 04:38 AM
Interrupt problems! amindzo Micro Controllers 16 9th November 2006 08:11 PM
RB0 interrupt problems amindzo Micro Controllers 4 26th August 2006 12:14 PM
Timer: Interrupt Flag (IF) and Interrupt Enable (IE) patricktran Micro Controllers 0 25th April 2004 05:11 AM



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


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