When I was growing up and Mom said that she was getting a SWITCH...She was not referring to an electrical component![]()
When I was growing up and Mom said that she was getting a SWITCH...She was not referring to an electrical component![]()
Dave
Always wear safety glasses while programming.
There you go people, my point has been backed up by these last few replies. I notice there are alot of assumptions being made.
E.g. 1 From skimask: "You wanted it handed to you on a platter so you could modify it and call it your own and impress your teachers or your buddies...whatever..."
Now that is some assumption. You jumped to that conclusion skimask, I know some other people on this form may do that, but all I needed was a somewhere to start. Go and look at my first post. See how innocent that looks? I guess the assumptions started right there. (:
E.g. 2 From mackrackit: "Whatever happened to people that want to learn.. Seems like all anyone wants these days is their problems solved for them with as little effort as possible on their part."
This person made the same assumption. What made you think I just wanted the answer straight up? It would have helped if someone could step me through how to set up Timer0.
Acetronics thought this was a cut and paste party. All I needed was some guidance.
Hmm I wonder what's going to be said next?
Last edited by wasssup1990; - 15th February 2008 at 03:20.
It's suppoased to be a loop every 10ms.
Not an insult every 10 ms.
It's like a "Pack of Wolves".
And wasssup didn't start anything.
Y'all need to mellow out, and write some code.
Here's mine...
HTH,Code:ReadingTaken VAR BIT TRM0IF VAR INTCON.2 TMR0IE VAR INTCON.5 TimerReload CON 60 OPTION_REG = %11010111 ; Assign Prescaler to TMR0, 1:256, internal clock TMR0 = TimerReload ; Load timer for first delay TMR0IF = 0 ; Clear the interrupt flag ReadingTaken = 0 ; indicate reading hasn't been taken yet TMR0IE = 1 ; Enable TMR0 interrupt ON INTERRUPT GOTO TakeReading Main: If ReadingTaken then ; Wait for reading to be taken ReadingTaken = 0 ; Indicate the reading has been handled ; -- Reading has been taken, do something with it here -- endif GOTO Main DISABLE TakeReading: TMR0 = TimerReload ; reload timer for next period TMR0IF = 0 ; Clear the interrupt flag ; -- this is called every ~10.036ms -- (with 20mhz OSC) ; Take your reading ReadingTaken = 1 ; Tell main loop that a reading has been taken RESUME ENABLE
DT
Thankyou Darrel
Admin has come to the rescue.
Thankyou for that usefull code. If I ever use any of it I will put credit to you in my source code and whoever else you think deserves credit for it.
I hope I never run into trouble like this again on this forum. I'm just a electronics and programming hobbiest needing a little programming help. I didn't need any of that rubbish above.
MHhhhhh,
Thinking to it, Darrel is perfectly right ... ( as most of time ! )
We are here for programming pics tricks ... and Everything else is just "optionnal". May be this thought could avoid further fighting parties ...
Here are My two cents !
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Minor correction to DT's code above:
TRM0IF VAR INTCON.2 should be TMR0IF VAR INTCON.2
Also, I agree with DT. Here is my code thingie with my approach:
1.03mS interrupt at 4 MHz, 1:4 Prescaler Assigned to TMR0.
This works the opposite way of what DT does.
DT's code interrupts every 10mS, my code interrupts every 1mS.
Work on either one.
Code:<font color="#008000">@ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON, BOD_OFF </font>SetAll: <font color="#000080"><b>CLEAR </b></font>TRISA = <font color="#FF0000"><b>%00000000 </b></font>TRISB = <font color="#FF0000"><b>%00000000 </b></font>CMCON = <font color="#FF0000"><b>7 </b></font>VRCON.<font color="#FF0000"><b>7 </b></font>= <font color="#FF0000"><b>0 </b></font>VRCON.<font color="#FF0000"><b>6 </b></font>= <font color="#FF0000"><b>0 </b></font>PORTA = <font color="#FF0000"><b>0 </b></font>PORTB = <font color="#FF0000"><b>0 </b></font>TimeAdder <font color="#000080"><b>VAR BYTE </b></font>OPTION_REG.<font color="#FF0000"><b>5 </b></font>= <font color="#FF0000"><b>0 </b></font><font color="#000080"><i>' TMR0 internal clk select bit. </i></font>OPTION_REG.<font color="#FF0000"><b>3 </b></font>= <font color="#FF0000"><b>0 </b></font><font color="#000080"><i>' Prescaler Assigned to TMR0. </i></font>OPTION_REG.<font color="#FF0000"><b>2 </b></font>= <font color="#FF0000"><b>0 </b></font><font color="#000080"><i>' Bit 2,1,0 : 1:4 prescaler. </i></font>OPTION_REG.<font color="#FF0000"><b>1 </b></font>= <font color="#FF0000"><b>0 </b></font>OPTION_REG.<font color="#FF0000"><b>0 </b></font>= <font color="#FF0000"><b>1 </b></font>T0IE <font color="#000080"><b>VAR </b></font>INTCON.<font color="#FF0000"><b>5 </b></font><font color="#000080"><i>'INTCON.5 = 1 ' Enable TMR0 interrupt. </i></font>T0IF <font color="#000080"><b>VAR </b></font>INTCON.<font color="#FF0000"><b>2 </b></font><font color="#000080"><i>'INTCON.2 = 0 ' TMR0 interrupt overflow bit. Must be cleared in software. </i></font>T0IF = <font color="#FF0000"><b>0 </b></font><font color="#000080"><i>' Cleared. </i></font>T0IE = <font color="#FF0000"><b>1 </b></font><font color="#000080"><i>' Enable TMR0 interrupt. </i><b>ON INTERRUPT GOTO </b></font>TMR0_Int Begin: <font color="#000080"><b>IF </b></font>TimeAdder = <font color="#FF0000"><b>10 </b></font><font color="#000080"><b>THEN </b><i>' We have 10mS cycle. </i></font>TimeAdder = <font color="#FF0000"><b>0 </b></font><font color="#000080"><i>' Clear time adder. 'Do something here. '. '.. '... </i><b>ENDIF GOTO </b></font>Begin <font color="#000080"><b>DISABLE </b></font>TMR0_Int: <font color="#000080"><i>'This routine is called every 1.03mS. Act Fast here. </i></font>TimeAdder = TimeAdder + <font color="#FF0000"><b>1 </b></font>T0IF = <font color="#FF0000"><b>0 </b></font><font color="#000080"><i>' Clear interrupt flag bit. </i><b>RESUME ENABLE </b></font>
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
WooHoo!, Somebody's paying attention. I love it!Originally Posted by sayzer
Dang dyslexia.
Thanks Sayzer!
<br>
DT
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Bookmarks