This should be simple?


Results 1 to 5 of 5

Threaded View

  1. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    You're adding in the overflow in OPLUS, but you aren't dropping the yvaltot value, so the next time around, it still sees the same 'almost overflowing' yvaltot, and still increments the overflow.
    If I was you...and this is just one way of doing things...make yvaltot hold a value from 0-9999, then another word variable, say yvaltot_high hold the next 4 digits to the left of that...
    Yes, I'm going to colonize your program, just for me
    Changes in bold...
    Code:
    @ DEVICE pic16F689, intrc_osc_noclkout, wdt_off, mclr_off, protect_off
    CM1CON0 = 0 : CM2CON0 = 0 : ADCON0 = 0 : ANSEL = 0 : ANSELH = 0 : OSCCON = $61
    TRISA = %101100 : TRISB = %0000 : TRISC = 0 : OPTION_REG = $c0
    Define LCD_DREG PORTC 'Set LCD data port
    DEFINE LCD_DBIT 0 'Set LCD starting data bit
    DEFINE LCD_RSREG PORTC 'Set LCD register select port
    DEFINE LCD_RSBIT 4 'Set LCD register select bit
    DEFINE LCD_EREG PORTC 'Set LCD enable port
    DEFINE LCD_EBIT 5 'Set LCD enable bit
    DEFINE LCD_BITS 4 'Set LCD bus size
    DEFINE LCD_LINES 2 'Set LCD number of lines
    DEFINE LCD_COMMANDUS 1500 'Set command delay time in us
    DEFINE LCD_DATAUS 200 'Set data delay time in us
    NCS VAR PORTB.5 : SPEAKER VAR PORTA.4 : MOSI VAR PORTA.0 : MISO VAR PORTA.3
    DATAIN VAR BYTE : MOTBYTE var BYTE : MOTBIT var BIT : MOTBIT = MOTBYTE.BIT7
    YVAL VAR BYTE : XVAL VAR BYTE : YVALTOT VAR WORD : YVALTOTHI VAR WORD
    MOTBIT = 0 : LOW PORTC.6 : LOW PORTC.7 : DATAIN = 0 : PAUSE 1000 : NCS = 0
    NCS = 1 : NCS = 0 : SHIFTOUT MOSI,PORTA.1,5,[$3a\8] 'Reset sensor
    PAUSE 10 : SHIFTOUT MOSI,PORTA.1,5,[$5a\8] : ncs = 1 : yval = 0 : yvaltot = 0
    yvaltothi = 0 : PORTB.7 = 0
    Main:
    ncs = 0 : shiftout mosi,PORTA.1,5,[$02\8] : PAUSE 10
    SHiftin miso,PORTA.1,6,[MOTBYTE\8]  : Pause 10 : ncs = 1
    If MOTByTE = $e0 then YCOUNT
    LCDOUT $fe,1,dec4 yvaltothi, dec4 yvaltot
    goto Main
    YCOUNT:
    ncs = 0 : SHIFTOUT MOSI,PORTA.1,5,[$03\8] 'input values
    SHIFTIN MISO,PORTA.1,6,[YVAL\8] : SHIFTOUT MOSI,PORTA.1,5,[$04\8]
    SHIFTIN MISO,PORTA.1,6,[XVAL\8] : ncs = 1
    yvaltot = yvaltot + yval 'count Y values
    if yvaltot > 10000 then OPLUS 'keep track of y overflows
    goto Main
    
    OPLUS:
    yvaltot = yvaltot - 10000 : yvaltothi = yvaltothi + 1
    goto main
    
    END
    Last edited by skimask; - 29th September 2008 at 21:38.

Similar Threads

  1. Simple RF remote control code
    By Bruce in forum Code Examples
    Replies: 13
    Last Post: - 22nd January 2014, 11:45
  2. Simple Blinking LED - WTF!!
    By johnnylynx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st February 2010, 07:19
  3. Simple LCD code not working!...WHY?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th November 2009, 20:48
  4. Replies: 0
    Last Post: - 3rd February 2009, 00:23
  5. Replies: 4
    Last Post: - 7th September 2005, 15:11

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