LCD Clock, Interrup


Closed Thread
Results 1 to 2 of 2
  1. #1
    Patrick's Avatar
    Patrick Guest

    Question LCD Clock, Interrup

    I have the following

    Clock on LCD LINE 1 Timer0 overflow Interrup
    Line two I measure temp and voltage with different pushbuttons

    Clock stop when I do measurement
    Can get voltage to display correct but then temp is not correct or visa versa
    How do I nest something outside the interrup toovercome the clock stopping

    Problem with setup of ADC

    Help
    '************************************************* ***************
    '* Name : lcdclocktemp001.BAS *
    '* Author : P van Biljon *
    '* Notice : Copyright (c) 2006 Ver:2.44 *
    '* : All Rights Reserved *
    '* Date : 2006/07/15 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    ' LCD clock program using On Interrupt
    ' Uses TMR0 and prescaler. Watchdog Timer should be
    ' set to off at program time and Nap and Sleep should not be used.
    ' Buttons may be used to set time
    DEFINE LOADER_USED 1 ' If using bootloader to program pic
    DEFINE LCD_DREG PORTC 'Define PIC port used for LCD Data lines
    DEFINE LCD_DBIT 0 'Define first pin of portc connected to LCD DC4
    DEFINE LCD_RSREG PORTC 'Define PIC port used for RS line of LCD
    DEFINE LCD_RSBIT 4 'Define Portc pin used for RS connection
    DEFINE LCD_EREG PORTC 'Define PIC port used for E line of LCD
    DEFINE LCD_EBIT 5 'Define PortC pin used for E connection
    DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
    DEFINE LCD_LINES 2 'Define using a 2 line LCD
    DEFINE LCD_COMMANDUS 2000 'Define delay time between sending LCD commands
    DEFINE LCD_DATAUS 50 'Define delay time between data sent.
    DEFINE ADC_BITS 10 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS


    hour var byte ' Define hour variable
    dhour var byte ' Define display hour variable
    minute var byte ' Define minute variable
    second var byte ' Define second variable
    ticks var byte ' Define pieces of seconds variable
    update var byte ' Define variable to indicate update of LCD
    i var byte ' Debounce loop variable
    samples var word
    sample var byte
    temp var byte


    sample9 var word
    @ device WDT_OFF



    Pause 100 ' Wait for LCD to startup

    hour = 0 ' Set initial time to 00:00:00
    minute = 0
    second = 0
    ticks = 0

    update = 1 ' Force first display

    ' Set TMR0 to interrupt every 16.384 milliseconds
    OPTION_REG = $55 ' Set TMR0 configuration and enable PORTB pullups
    INTCON = $a0 ' Enable TMR0 interrupts





    On Interrupt Goto tickint
    PORTB = 1 ' PORTB lines low to read buttons
    TRISB = %11111111 ' Enable buttons
    mainloop:
    ' Check any button pressed to set time
    if PORTB.1 = 0 then decmin
    if PORTB.2 = 0 then incmin
    if portb.3 = 0 then temp1
    if portb.4 = 0 then loop
    'disable

    'enable


    ' Main program loop - in this case, it only updates the LCD with the time

    ' Check for time to update screen
    chkup: If update = 1 Then
    Lcdout $fe, 1 ' Clear screen

    ' Display time as hh:mm:ss
    dhour = hour ' Change hour 0 to 12
    If (hour // 12) = 0 Then
    dhour = dhour + 12
    Endif

    ' Check for AM or PM
    If hour < 12 Then
    Lcdout $fe,1," ", dec2 dhour , ":", dec2 minute, ":", dec2 second, " AM"
    Else
    Lcdout $fe,1," ", dec2 (dhour - 12), ":", dec2 minute, ":", dec2 second, " PM"
    Endif

    update = 0 ' Screen updated
    Endif

    Goto mainloop ' Do it all forever


    ' Increment minutes
    incmin: minute = minute + 1
    If minute >= 60 Then
    minute = 0
    hour = hour + 1
    If hour >= 24 Then
    hour = 0
    Endif
    Endif
    Goto debounce
    return
    ' Decrement minutes
    decmin: minute = minute - 1
    If minute >= 60 Then
    minute = 59
    hour = hour - 1
    If hour >= 24 Then
    hour = 23
    Endif
    Endif
    Goto debounce
    return
    ' Debounce and delay for 250ms
    debounce: For i = 1 to 25
    Pause 10 ' 10ms at a time so no interrupts are lost
    Next i

    update = 1 ' Set to update screen

    Goto chkup


    'sample1 var byte


    loop:
    trisa = %11111111
    adcon1 = %10000010

    pause 500


    adcin 2,sample9

    sample9 = (sample9 */ 500)>>2
    'samples = samples * 2
    lcdout $fe,$C0,"Voltage is: ",DEC (sample9/100),".", DEC2 sample9
    pause 1500
    goto mainloop



    temp1:
    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %10000010 'Set to analog ports A
    'samples = 0


    loop1:

    'for sample = 0 to 20
    adcin 4 ,temp
    'samples= samples + temp
    'pause 50
    'next sample
    'temp = samples / 20
    temp = (temp */ 500)>>2
    lcdout $fe,$C0,"Temp is: " ,DEC temp,".",dec1 temp," C In "

    pause 1000
    goto mainloop


    ' Interrupt routine to handle each timer tick
    disable ' Disable interrupts during interrupt handler
    tickint:
    ticks = ticks + 1 ' Count pieces of seconds
    If ticks < 61 Then tiexit ' 61 ticks per second (16.384ms per tick)
    ticks = 0 ' One second elasped - update time
    second = second + 1
    If second >= 60 Then
    second = 0
    minute = minute + 1
    If minute >= 60 Then
    minute = 0
    hour = hour + 1
    If hour >= 24 Then
    hour = 0
    Endif
    Endif
    Endif

    update = 1 ' Set to update LCD

    tiexit: INTCON.2 = 0 ' Reset timer interrupt flag
    Resume

    End

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


    Did you find this post helpful? Yes | No

    Default

    first observation... you'll have a Stack overflow soon by using some
    Code:
    Goto debounce
    return
    Please use the code bracket to make it easier to read for us.
    http://www.picbasic.co.uk/forum/misc.php?do=bbcode
    Steve

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

Similar Threads

  1. Is this code not initialising the LCD properly?
    By Platypus in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 30th January 2010, 19:14
  2. 16f688 LCD what have I done wrong
    By spitfiredriver in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th August 2009, 19:54
  3. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 16:56
  4. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07
  5. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30

Members who have read this thread : 1

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