FYI, the missing % is a new Code Box forum feature...
FYI, the missing % is a new Code Box forum feature...
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Hi,
I searched in the forum and found a peice of code by Bruce...
Everytime I press RA.4 it toggle RB0, I also put a variable that will display the value to the LCD, from the code I observed (please correct me if I wrong).Code:DEFINE LCD_DREG PORTBDEFINE LCD_DBIT 0 DEFINE LCD_EREG PORTB DEFINE LCD_EBIT 5 DEFINE LCD_RSREG PORTB DEFINE LCD_RSBIT 4 DEFINE LCD_BITS 4 DEFINE LCD_LINES 2 DEFINE LCD_COMMANDUS 2000 DEFINE LCD_DATAUS 50 PAUSE 100 TRISA.4 = 1 ' RA4/T0CKI = input to TMR0 counter TRISB.0 = 0 ' RB0 = output for LED CMCON = 7 ' All digital i var byte i=0 ' Assign prescaler to WDT for 1:1 prescale on TMR0 ' TMR0 clock will be from your external input on RA4/T0CKI ' Increment on high-to-low transitions OPTION_REG = 111000 ' If you prefer, then increment on low-to-high transitions ' OPTION_REG = 101000 Lcdout $fe, 128, "Counter: ", #i pause 100 Main: TMR0 = 0 ' Clear TMR0 count before start Loop1: WHILE TMR0 = 0 ' Wait for high-to-low transition WEND ' on RA4/T0CKI PORTB.0 = 1 ' LED on to indicate transition seen i=i+1 ' Increment Lcdout $fe, 128, "Counter: ", #i PAUSE 200 PORTB.0 = 0 ' LED off GOTO Main ' Start over END
a. Timer0 is selected
b. The signal entry is RA.4
c. It increments on low-to-high transitions
d. Pre scale value is 1:2 (000 of Bits 2,1)
d. The configuration setting used OPTION_REG = 111000
So if connect the multi coin acceptor to the RA.4 this should count the number of pulse?
thanks in advance,
tacbanon
Last edited by tacbanon; - 1st October 2011 at 07:01.
Hi,
Yes, that would work. I'd probably add a little pause directly after the WHILE-WEND loop to allow the coin acceptor to push out all the pulses before the code reads the timer.
As for the prescaler, yes, the bits indicate a a 1:2 ratio but since bit 3 is set the prescaler isn't assigned to TMR0 but to the WDT so you get a 1:1 ratio which is what you want in this case.
Steve,
Thanks for the heads-up on the % character, great feature... Must try/verify:And here's how my post looks in preview:Code:This is a test, percent char %00110011 This is a test, no percent char 00110011
Looks fine in the preview. (Appologies to tachbanon for trying this here).
EDIT: And in the final post, I don't see a problem... Is it when there's a = infront?Again, looks fine in the preview.Code:OPTION_REG = %00110011
EDIT: And in the final post.
/Henrik.
Last edited by HenrikOlsson; - 1st October 2011 at 08:13.
Hi, now I'm trying to incorporate the coin acceptor, but I observered that when I connect PULSE line to RA4..it continues to count, even if the device is turned off or if I touched the wire. Please see the attachment, I'm using easypic6. What do you think causing it?
regards,
tacbanon
Hi,
Try adding a pullup or pulldown resistor on the input.
I tried both using the built in switch to enabled Pull up/down.. no changes.
Please see attach image, I'm using the blue wire.
thanks,
tacbanon
Hi, I finally got it right, what was missing was the GND.Thanks Henrik for the help, my next target is to run the codes on PIC18F4550..hope it wont be a problem.
regards,
tacbanon
Bookmarks