Code Issue - select case or 'if' issue - not sure why


Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Aug 2005
    Posts
    44

    Default Code Issue - select case or 'if' issue - not sure why

    Hi all,

    Im messing around with some code off a project below:

    The problem im having is either in this code (just below all the rpm calcs):

    Code:
    if rpm > 6600 then			'exceeding redline > light on
    let alert = 1:portc.3 = 1
    else
    portc.3 = 0:let alert = 0	
    endif
    or in the select case code, basically it is not selecting case 1 (alert = 1) and updating the last line of the lcd correctly.
    All other 'select case's seem to be working?

    Anyone have any clues?

    Just a few notes - the code is over 2k compiled, thererfore im getting crossing page boundary warnings but that shouldnt be the problem?
    Also i've tried moving a few things around in the code with no luck....


    Code:
    '		|1 - mclr  			b7 	- 28| lcd
    'temp in|2 - ra0/an0		b6 	- 27| lcd
    'volt in|3 - ra1/an1		b5 	- 26| lcd
    '		|4 - ra2/an2		b4 	- 25| lcd
    '		|5 - ra3/an3		b3 	- 24| lcd
    '		|6 - ra4/tocki		b2 	- 23| lcd
    'fuel	|7 - an4			b1 	- 22|
    '		|8 - gnd			b0 	- 21|
    '		|9 - xtal			+  	- 20|
    '		|10 - xtal			gnd	- 19|
    'fan sen|11 - c0			c7/rx-18| serial rx
    'wp sen	|12 - c1			c6/tx-17| serial tx
    'tach	|13 - ccp1 /c2		c5 	- 16| out 3 - fan relay
    'outLITE|14 - c3			c4 	- 15| out 2 
    
    
    DEFINE  LCD4X20  1
    INCLUDE "LCDbar_INC.bas"     ' Include the BARgraph routines
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    DEFINE LCD_DREG PORTB 		' Set LCD Data port
    DEFINE LCD_DBIT 4 			' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB 		' Set LCD Register Select port
    DEFINE LCD_RSBIT 2 			' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB 		' Set LCD Enable port
    DEFINE LCD_EBIT 3 			' Set LCD Enable bit
    DEFINE LCD_BITS 4 			' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 4 			' Set number of lines on LCD
    
    TRISA = %00101111			' Port A all defines
    TRISB = %00000000			' Port B all defines
    TRISC = %00000111
    CMCON = 7		 			' Comparators Off
    ADCON0 = %11000001	
    ADCON1 = %10000010
    CCP1CON = %00000110  		' Capture mode, capture on 4th rising
    T1CON = %00100001			' Set Timer 1, On and 1/4 prescale (overflow every 260ms)
    
    DEFINE ADC_BITS 10           ' Number of bits in ADCIN results
    DEFINE ADC_SAMPLEUS 50
    
    Temperature  VAR  WORD Bank0     ' Must be a WORD even though AD is 8bit
    Fuel	 	 VAR  Word Bank0		' Must be a WORD even though AD is 8bit
    Fan 		 VAR  Bit  Bank0
    WP			 VAR  Bit  Bank0
    
    Overflow 	VAR PIR1.0			' Timer1 overflow flag
    inRPM 		VAR	WORD Bank0		' Word variable that stores the value
    RPM 		var word Bank0
    maxrpm		var word Bank0
    maxrpmreset var word Bank0
    alert		var byte Bank0
    
    
    
    
    '==========================================================================================================
    ASM
    INT_LIST  macro    	 ; IntSource,   Label,  	Type, ResetFlag?
            INT_Handler	   CCP1_INT,  _gotrpmpulse,	PBP, 	yes
    
    			
        endm
        INT_CREATE               	; Creates the interrupt processor
    	INT_ENABLE 	 CCP1_INT	  	; enable CCP port change interrupt
    
    ENDASM
    
    
    '==========================================================================================================
    
    
    LCDOUT $FE, 1  ' Clear Screen
    Pause 2000 ' lcd settle time
    LCDOUT $FE, 2,   " Digital Panel"  ' intro screen
    LCDOUT $FE, $D4, "2007"  ' intro screen
    Pause 3000
    LCDOUT $FE, 1  ' Clear Screen
    inrpm  = 2
    maxrpmreset = 1600
    alert = 0
    portc.3 = 1		' shift light on test
    pause 600		' pause 0.5  sec
    portc.3 = 0
    
    Loop1:
        ADCIN  0, Temperature
        Temperature = 889 - Temperature  ' invert it
    	Temperature = Temperature * 10
    	Temperature = Temperature / 66	  ' divider
    
    	ADCIN  4, Fuel
    	fuel = fuel / 7
        fuel = fuel - 2
    
    	fan = portc.0
    	wp  = portc.1
       
    RPM = 10000
    RPM = RPM * 1500 
    RPM = DIV32 inrpm 
    RPM = RPM / 100
    RPM = RPM * 100
    
    if rpm > 6600 then			'exceeding redline > light on
    let alert = 1:portc.3 = 1
    else
    portc.3 = 0:let alert = 0	
    endif
    
    LCDOUT $FE,1,"Temp:",DEC Temperature,"   Fuel:",DEC Fuel," L    "  
    
    If fan = 0 and wp = 0 then
    	LCDOUT $FE,$C0,"Fans:OFF  W/Pump:OFF":alert = 2
    endif
    If fan = 1 and wp = 0 then
        LCDOUT $FE,$C0,"Fans:ON   W/Pump:OFF":alert = 3
    endif
    If fan = 0 and wp = 1 then
        LCDOUT $FE,$C0,"Fans:OFF  W/Pump:ON":alert = 0
    endif
     If fan = 1 and wp = 1 then
        LCDOUT $FE,$C0,"Fans:ON   W/Pump:ON":alert = 0
    endif
    
    LCDOUT $FE,$94,"Rpm: ",DEC rpm, " Max:", DEC maxrpm
    
    
    select case alert
    		case 0 
    			    ; syntax- BARgraph   Value,  	  Row, Col, Width, Range, Style
       				@         BARgraph  _RPM,   		4,   0,    19,   7500,   lines
    		case 1
    			LCDOUT $FE,$D4,"ALERT: !!! RPM !!!! " 
    		case 2
    			pulsout portc.3, 700:LCDOUT $FE,$D4,"ALERT:FAN + W/P FAIL" 
    		case 3
    			pulsout portc.3, 700:LCDOUT $FE,$D4,"ALERT: W / PUMP FAIL" 
    		case else
    end select
    
    
    if rpm > maxrpm then		' check max rpm and update if needed
    maxrpm = rpm
    endif
    
    if maxrpmreset < 100 then 			' reset max rpm
    maxrpm=0
    maxrpmreset = 1600
    endif
    
    maxrpmreset = maxrpmreset -1
    
    pause 80
    
    GOTO Loop1
    
    
    '=======================================================================================
    '---[CCP1 - interrupt handler - We got an input Pulse] ---------------------------------
    
    gotrpmpulse:
    				if overflow = 0 then
    				inRPM.highbyte = CCPR1H		' Store the time to do 4 revs value in
    				inRPM.lowbyte = CCPR1L		' inRPM variable
    				TMR1H = 0					' Clear Timer1 high register
    				TMR1L = 0					' Clear Timer1 low register
    				endif		
    			
    				if overflow = 1 then
    				TMR1H = 0					' Clear Timer1 high register
    				TMR1L = 0					' Clear Timer1 low register
    				overflow = 0
    				inrpm = 2
    				endif
    
    @ INT_RETURN
    
    '==============================================================================================
    Last edited by jamie_s; - 6th October 2007 at 10:47.

Similar Threads

  1. Multiple "AND"'s in select case?
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st January 2010, 19:10
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. Help needed with Select Case?
    By jessey in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd January 2008, 00:12
  4. universal lcd setup menu
    By ShoKre in forum Code Examples
    Replies: 2
    Last Post: - 7th August 2007, 11:08
  5. select case question
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th March 2006, 10:01

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