Using LCD from Mechatronics Demo Board


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Location
    Copenhagen
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    After all, the LCD works. Here is the code that I use to display "1234":

    PAUSE 1000 'wait for LCD start up

    LCDPS = %00110001 'Selecting the frame prescale

    LCDSE0.0 = 1 'Segment pins
    LCDSE0.1 = 1
    LCDSE0.2 = 1
    LCDSE0.3 = 1
    LCDSE0.6 = 1
    LCDSE1.3 = 1
    LCDSE2.0 = 1
    LCDSE2.5 = 1
    LCDSE2.6 = 1
    LCDSE2.7 = 1

    LCDCON = %01000011 'Multiplex,bias,timing, sleep

    LCDDATA0 = %01001000 'initial LCD values "1234"
    LCDDATA1 = %00001000
    LCDDATA2 = %10100000
    LCDDATA3 = %00000000
    LCDDATA4 = %00001000
    LCDDATA5 = %11100000
    LCDDATA6 = %00001100
    LCDDATA7 = %00000000
    LCDDATA8 = %10100000
    LCDDATA9 = %01001000
    LCDDATA10 = %00000000
    LCDDATA11 = %00000000

    PIR2.4 = 0 'clearing LCD interrupt flag

    LCDCON = %01010011 'enabling bias voltage pins
    LCDCON = %11010011 'enabling the LCD module

    however, I have problems when trying to run PWM module while using LCD. I will post about it soon.

  2. #2
    Join Date
    Apr 2007
    Location
    Copenhagen
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    As mentioned above, I have problems when trying to use LCD (code above) and HPWM at the same time.

    This is my HPWM program:

    'Connections:
    'SW2->RD1 increase switch
    'SW3->RA4 decrease switch
    'P1->Vdd motor turned on constantly
    'RC5/CCP1->N2 CCP1 is pwm output pin
    'DC motor is connected to DRIVE 1 and DRIVE 2



    'HPWM initialization
    duty VAR WORD ' Duty cycle value )

    TRISC.5 = 0 ' Set PORTC.5 (CCP1) to output
    CCP1CON = %00001100 ' Set CCP1 to PWM

    T2CON = %00000101 ' Turn on Timer2, Prescale=4

    PR2 = 249 ' Set PR2 to get 1KHz out

    duty = 500 ' Set duty cycle to 50%


    up var PORTD.1 'user-friendly names for ports
    down var PORTA.4

    'Main program loop
    loop:

    CCP1CON.4 = duty.0 ' Store duty to registers as
    CCP1CON.5 = duty.1 ' a 10-bit word
    CCPR1L = DUTY >> 2

    'check if button "up" is pressed and duty is not maximum
    IF (up=0) AND (duty<1000) THEN
    duty=duty+50
    PAUSE 200
    ENDIF

    'similar as before but for reducing the speed
    IF (down=0) AND (duty>0) THEN
    duty=duty-50
    PAUSE 200
    ENDIF

    GoTo loop ' Do it forever
    End

    When I combine these two programs (first LCD then HPWM) it starts to work that is I get "1234" on the LCD and then motor starts to turn but only for 2-3sec. Later is just stops. It looks like PWM signal just dies...?!
    I have no idea why these two modules (LCD and HPWM) cannot work togather? I have checked the pins and timing sources but don't see any possible conflicts?

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Michlis View Post
    IF (down=0) AND (duty>0) THEN
    duty=duty-50 : PAUSE 200
    ENDIF
    If duty is 10 and you subtract 50 from it, you'll end up with a negative number, which PBP doesn't handle. I think you want the lines to be:
    IF (down = 0) AND (duty => 50) THEN blah blah blah...

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Nah, PBP handle it. if 0-50 in a byte variable will return 205 or 206.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Nah, PBP handle it. if 0-50 in a byte variable will return 205 or 206.
    But 'duty' is a word and, if it does end up being a 'negative number', it'll be above the 1000 limit set in the IF/THEN above and nothing will happen to 'duty' and the program will appear to go stupid.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Talking

    <table><td></td><td>hum hum... pfff i knew... it was a test to know if you follow... HUM HUM</td><td></td></table>
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    hum... pfff i knew... it was a test to know if you follow... HUM HUM
    Do I get anything as a prize?

  8. #8
    Join Date
    Apr 2007
    Location
    Copenhagen
    Posts
    7


    Did you find this post helpful? Yes | No

    Smile Conclusions

    Quote Originally Posted by skimask View Post
    If duty is 10 and you subtract 50 from it, you'll end up with a negative number
    You are of course right, but I start the program with duty=500 and use only +/-50 steps, so this IF statement is correct in my case.

    After some time I found the bug. At first I set all LCDSEn registers and it was a mistake since the LCD uses only few pins, so my button input pins were in segment functionality instead of I/O. Now I only set the segment pins that are actually used by LCD.

Similar Threads

  1. 16f688 LCD what have I done wrong
    By spitfiredriver in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th August 2009, 19:54
  2. 16f887 44 pin demo board code problem?
    By jessey in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 7th December 2008, 14:17
  3. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. Replies: 8
    Last Post: - 7th December 2006, 15:42

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts