Originally Posted by smitty505000
Once you check over the hardware to eliminate any problems there, then post the code you are using. Lots of folks can help out with that!
Steve
Originally Posted by smitty505000
Once you check over the hardware to eliminate any problems there, then post the code you are using. Lots of folks can help out with that!
Steve
Hey Steve, seems we use the same source for this 'Dancing Awesome'
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=881&d=1148640458">
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
LOL, Thanks for the help and support guys!
Here is the run down
Code from Steve on post 12 works but looses count if rotated too fast so I know the circuit is good.
I then went to the code in post 6 with both asm routines and compiled it with microcode studio. Compiled fine. The only things I changed in the code from post 6 was adding:
DEFINE OSC 20
PAUSE 1000
SEROUT2 on PORTB.0 FOR LCD clear
SEROUT2 ON PORTB.0 FOR DISPLAY
Here it is:
Old_Bits VAR BYTE
New_Bits VAR BYTE
RotEnc1_val VAR BYTE 'Connected to PORTB<4:5>
RotEnc2_val VAR BYTE 'Connected to PORTB<6:7>
TRISB = %11110000
RotEncDir VAR BIT
'************************
' SETUP YOUR LCD HERE!!!
'************************
DEFINE OSC 20
PAUSE 1000 'Pause for LCD Power up
SEROUT2 PORTB.0, 84,[254, 88] 'Clear LCD
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _Rot_Encoder, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE RBC_INT ;RB Port Change Interrupt
Old_Bits = PORTB & (%11110000)
Main:
SEROUT2 PORTB.0, 84,[254, 71, 1, 1, "ROT1:", DEC2 RotEnc1_val,"ROT2:",_
DEC2 RotEnc2_val]
pause 10
GOTO Main
'---[RBC - interrupt handler]---------------------------------------------------
Rot_Encoder:
New_Bits = PORTB & (%11110000)
IF (New_Bits & %00110000) = (Old_Bits & %00110000) then No_Change_Rot1
RotEncDir = New_Bits.5 ^ Old_Bits.4
if RotEncDir = 1 then
RotEnc1_val = RotEnc1_val + 1
if RotEnc1_val = 36 then RotEnc1_val = 0
ELSE
RotEnc1_val = RotEnc1_val - 1
if RotEnc1_val = 255 then RotEnc1_val = 35
ENDIF
No_Change_Rot1:
IF (New_Bits & %11000000) = (Old_Bits & %11000000) then DoneRotEnc
RotEncDir = New_Bits.7 ^ Old_Bits.6
if RotEncDir = 1 then
RotEnc2_val = RotEnc2_val + 1
if RotEnc2_val = 36 then RotEnc2_val = 0
ELSE
RotEnc2_val = RotEnc2_val - 1
if RotEnc2_val = 255 then RotEnc2_val = 35
ENDIF
DoneRotEnc:
Old_Bits = New_Bits
@ INT_RETURN
The LCD comes up and displays ok. Then when I rotate an encoder, sometimes I get a little garbage on the screen and then it just seams to hang. I can go thru many restarts before the LCD will display properly again. It kinda seams like the chip is stuck. Is that possible even though I disconnect power and then reconnect? Is the pic holding something in memory where it hangs? I am using a 16F876A
Thanks guys!
Smitty
OK, I found an error in the interrupt setup. Make the change highlighted in red.
I tried this out on a 16F877a (since I don't have your model). Worked fine with the one encoder I have available hooked to Rot1. Don't see any reason it wouldn't work with both hooked up.Code:ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler RBC_INT, _Rot_Encoder, PBP, yes endm INT_CREATE ; Creates the interrupt processor INT_ENABLE RBC_INT ;RB Port Change Interrupt ENDASM
Steve
Since you are using a serial LCD and software based serial routine, the interrupts will be disrupting the timing of the serial output. I would recommend using HSEROUT. The timing won't be affected with the interrupts.
EDIT:
Here is how you can do this:
1) Switch your serial cable to RB2 (pin 8)
3) Setup the HSER defines:
3) Change your SEROUT2 commands to HSEROUT.Code:'Setup for 9600 baud ' Set transmit register to TXEN =1 (TX enabled) and BRGH = 1 DEFINE HSER_TXSTA 24h ' Set baud rate DEFINE HSER_BAUD 9600
Code:HSEROUT [254, 88] 'Clear LCD and HSEROUT [254, 71, 1, 1, "ROT1:", DEC2 RotEnc1_val," ROT2:", DEC2 RotEnc2_val]
Steve
Last edited by SteveB; - 30th September 2006 at 17:35.
I think someone dosnt want this to work
I did the hserout just as you said and still got garbage. I then checked the pbp manual and double checked the define's. all ok. Wait a sec, the 16f876a has the usart tx on pin c6! Right? So I moved the lcd serial line to c6 and still got garbage! What is going on! So then I programed a simple code into the pic to just do a hserout to print to the lcd. I used the proper define's and still got garbage. At this point I am thinking what the heck is going on. So then went back to a simple program to print on the lcd with the serout2 command just to check the lcd. And sure enough garbage! Is the lcd bad? Well I then hooked it to the pc and ran a program that tests it and sure enough the lcd is shot! Not sure what happened. I never hooked it up reverse polarity. Is it possible that with the initial garbage coming out of the pic it sent something to the lcd that screwed something up? I am totaly scratching my head. LOL
The only thing that I might have done is connect the serial line going to the lcd to 5v. Would that kill it?
I am going to try the my old parallel lcd and see what happens.
Thank you for putting up with me this long. I will get this thing running if it kills me! LOL
Smitty
In your first post in the thread, you said you were using the following:
So, I figured you opted for a serial LCD to save on I/O lines with an 18 pin pic. So my last post was geared to the 16F628.Originally Posted by smitty505000
Seems you switched PIC as well.Originally Posted by smitty505000
Guess I could have been more generic and just said to hook up the serial out to the TX pin.
Not likely. But worth a query to the distributor/manufacturer.Originally Posted by smitty505000
Well, I am sure it won't come to that. But this is one of those things that most of us have been through at least once (often multiple times), where we learn more than we expected going into it.Originally Posted by smitty505000
Steve
Bookmarks