Unable to get 2 inputs to work


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2007
    Posts
    11

    Default Unable to get 2 inputs to work

    I'm using a PIC 16F747 as a BCD decoder w/ LCD display. I've also included a stopwatch function. Everything works as desired except I can't get pins RB4 & RB5 to work as digital inputs. RB6 & RB7 are working as inputs for the timer (start & clear). Can anybody look at this and see what I'm missing? I suspect I need to use ADCON, but I'm having difficullty finding info on the proper usage.

    Thanks,

    Code:
    'initialize device
    @ device pic16f747, INTRC_OSC_NOCLKOUT, MCLR_OFF
    OSCCON = $60			'internal 4mHz oscillator
    define lcd_ereg porte
    define lcd_ebit 0
    
    'Initialize ports
    TRISA.6 = 1
    TRISA.7 = 1
    TRISB = $F0
    TRISC = $FF			'set all PORTC pins to inputs
    TRISD = 0
    PORTD = 0
    
    'initialize variables
    Index var byte
    x var byte
    switches var byte
    Symbol START_button = PORTB.6
    Symbol STOP_button = PORTB.5
    Symbol CLEAR_button = PORTB.7
    Ticks var byte
    Minute var byte
    Second var byte
    Disp var byte
    Delay var byte  
    
    'Initialize LCD
    	Pause 1000			'pause 1 sec to let LCD initialize
    	LCDOUT $FE,1,"            Firing Panel V.2"
    	pause 2000
    
    SETUP:
    	LCDOUT $FE,1,"Firing Mode:"
    	LCDOUT $FE,150,"Panel Selected:"
    	LCDOUT $FE,192,"Wireless Bank:"
    	lcdout $FE,214,"Time:"
    	Minute = 0
    	Second = 0
    	Ticks = 0
    	Disp = 1
    	OPTION_REG = $05
    	ON INTERRUPT GOTO ISR 
    
    LOOP:	
        	Index = PORTc & $0F		'Read DIP switch AND mask lsb
      	LOOKUP2 Index,[ 1, 2, 3, 4, 5,06,07,08,09,10,11,12,13,14,15,16],x
        	LCDOUT $FE,166, #x
    
    DISPLAY:
    	IF Index = 0 THEN		'Panel 1 selected
    		PORTD = $06	'display 1 on LED display
    	endif
    	IF Index = 1 THEN
    		PORTD = $5B	'...
    	endif
    	IF Index = 2 THEN
    		PORTD = $4F
    	endif
    	IF Index = 3 THEN
    		PORTD = $66
    	endif
    	IF Index = 4 THEN
    		PORTD = $6D
    	endif
    	IF Index = 5 THEN
    		PORTD = $7C
    	endif
    	IF Index = 6 THEN
    		PORTD = $07
    	endif
    	IF Index = 7 THEN
    		PORTD = $7F
    	endif
    	IF Index = 8 THEN
    		PORTD = $67
    	endif
    	IF Index = 9 THEN
    		PORTD = $BF
    	endif
    	IF Index = 10 THEN
    		PORTD = $86
    	endif
    	IF Index = 11 THEN
    		PORTD = $BB
    	endif
    	IF Index = 12 THEN
    		PORTD = $CF
    	endif
    	IF Index = 13 THEN
    		PORTD = $E6
    	endif
    	IF Index = 14 THEN
    		PORTD = $ED
    	endif
    	IF Index = 15 THEN
    		PORTD = $FC
    	endif
    
    LEDS:
    	switches = (PORTC >> 4) & $0F
    	if switches > 0 then
    		goto LEDSLCD:
    	else 
    		goto BLANK:
    	endif
    
    LEDSLCD:
    	IF switches = %00000001 THEN
    		lcdout $FE,207," J  "
    		portB=1
    	endif
    	IF switches = %00000010 THEN
    		lcdout $FE,207," K  "
    		portB=2
    	endif
    	IF switches = %00000100 THEN
    		lcdout $FE,207," L  "
    		portb=4
    	endif
    	IF switches = %00001000 THEN
    		lcdout $FE,207," M  "
    		portb=8
    	endif
    	
    BLANK:
      	IF PORTA.6 = 1 THEN
    		portb = 0
    		lcdout $FE,207,"None "
    	endif
    
    SAFETY:
    	IF PORTA.7 = 1 THEN
    		lcdout $FE,141,"ARMED"
    	ELSE
    		lcdout $FE,141,"SAFE "
    	endif
    
    RESET:
    	IF portb.4 = 1 THEN
    		goto setup:
    	endif
    
    TIMER:
    	IF START_button = 1 THEN
    		TMR0 = 0
    		INTCON = $a0
    		Disp = 1
    	endif
    
    	IF STOP_button = 1 THEN
    		INTCON = 0
    		Disp = 1
    	endif
    
    	IF CLEAR_button = 1 THEN
    		INTCON = 0
    		Minute = 0
    		Second = 0
    		Ticks = 0
    		Disp = 1
    	endif				'Line 171
    
    	IF Disp = 1 THEN
    		lcdout $FE,220
    		lcdout DEC2 Minute, ":",DEC2 Second
    		Disp = 0
    	endif
    	GOTO Loop:
    
    DISABLE					'Line 180
    ISR:
    	Ticks = Ticks + 1
    	IF Ticks < 61 THEN NoUpdate	
    		Ticks = 0
    		Second = Second + 1
    		IF Second = 60 THEN
    			Second = 0
    			Minute = Minute + 1
    			IF Minute = 60 THEN
    				Minute = 0
    			endif
    		endif
    
    	Disp = 1
    
    NoUpdate:
    	INTCON.2 = 0
    	Resume
    	Enable
    
    	End
    	
    END

  2. #2
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rangerdoc View Post
    I'm using a PIC 16F747 as a BCD decoder w/ LCD display. I've also included a stopwatch function. Everything works as desired except I can't get pins RB4 & RB5 to work as digital inputs. RB6 & RB7 are working as inputs for the timer (start & clear). Can anybody look at this and see what I'm missing? I suspect I need to use ADCON, but I'm having difficullty finding info on the proper usage.
    The best place to get answers to these type of questions is to read the device datasheet.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Check the value shown in the data sheet to load into ADCON1 to make all pins digital.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This thread will also apply to your PIC even though we are talking about PORTB.
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Aug 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    This thread will also apply to your PIC even though we are talking about PORTB.
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    Thanks... This put me on the right track.

Similar Threads

  1. pls help me verify my code not work, why???
    By chai98a in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th January 2010, 09:19
  2. Replies: 20
    Last Post: - 13th May 2007, 05:10
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. 10bits adc using 16f877
    By sixty9sandals in forum mel PIC BASIC
    Replies: 7
    Last Post: - 8th March 2007, 18:23
  5. Pin RA4 doesn't work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 12:03

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