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





Bookmarks