Problem with PortB Tris


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Location
    Kent, UK
    Posts
    52

    Default Problem with PortB Tris

    I have a funny problem with driving PortB.6 as a digital io. (18LF 44K22 PBP 2.6c)
    The first 3 flashes work fine using HIGH PORTB.6, but doing the same again using PORTB.6 = 1 doesn't work though the other pins work as expected.
    I have looked through the data sheet and can find no clues. Can anyone point me in the right direction?

    Tim.

    Code:
    TEMPB		VAR BYTE					'Temporary Byte sized register
    
    STARTUP:	        ANSELA = 0					'ALL DIGITAL INPUTS
    			ANSELB = 0
    			ANSELC = 0
    			ANSELD = 0
    			ANSELE = 0
    			
    			TRISA = %11011100			'PortA ins & outs
    			TRISB = %00010000			'PortB ins & outs
    			TRISC = %11011110			'PortC ins & outs
    			TRISD = %10000000			'PortD ins & outs
    			TRISE = %00000100			'PortE ins & outs
    			
    			FOR TEMPB = 1 TO 3						'ALL LED'S FLASH STARTUP SIGNAL
    				PORTB.5 = 1
    				HIGH PORTB.6
    				PORTB.7 = 1
    				PAUSE 200
    
    				PORTB.5 = 0
    				LOW PORTB.6
    				PORTB.7 = 0
    				PAUSE 300
    			NEXT TEMPB
    			
    			FOR TEMPB = 1 TO 3						'ALL LED'S FLASH STARTUP SIGNAL
    				PORTB.5 = 1
    				PORTB.6 = 1
    				PORTB.7 = 1
    				PAUSE 200
    
    				PORTB.5 = 0
    				PORTB.6 = 0
    				PORTB.7 = 0
    				PAUSE 300
    			NEXT TEMPB
    			
    			GOTO MAIN

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Problem with PortB Tris

    I don't have an answer, just a quick suggestion to trouble shoot. Try putting another TRISB = %00010000 between the FOR...NEXT loops and see what that does. Also, if you use PORTB.6 = 1...PORTB.6 = 0 in the first loop instead of HIGH...LOW, does it work properly?

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


    Did you find this post helpful? Yes | No

    Default Re: Problem with PortB Tris

    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Apr 2011
    Location
    Kent, UK
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Problem with PortB Tris

    Adding an extra TRISb.6 = 0 between loops made no difference.
    Changing to LATb.6 = 1 works. Thanks for that. Problem solved.

    Interestingly, further down the code is ON INTERRUPT. If I put the PORTb.6 = 1 loop after the ON INTERRUPT statement it works fine???

    I usually use DT's instant int's (fantastic by the way) but this programme uses I2CREAD and I2cWRITE and so had to go back to ON INTERRUPT to prevent the timing being upset by the ISR.

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


    Did you find this post helpful? Yes | No

    Default Re: Problem with PortB Tris

    If I put the PORTb.6 = 1 loop after the ON INTERRUPT statement it works fine???
    All I can say is sometimes we get lucky....

    Like in the beginning of your code
    The first 3 flashes work fine using HIGH PORTB.6
    the data latch was clear. That evidently is happening in your ISR.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Problem with PortB Tris

    Glad to see it get fixed!

    Quote Originally Posted by timmers View Post
    this programme uses I2CREAD and I2cWRITE and so had to go back to ON INTERRUPT to prevent the timing being upset by the ISR.
    You might look into using the hardware I2C. You'd have to write some routines to deal with the data, but it will work well once you do.

  7. #7
    Join Date
    Apr 2011
    Location
    Kent, UK
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Problem with PortB Tris

    I agree, hardware I2c is the way to go, but thats alot of effort to make it work. The I2cREAD/WRITE work so well outside an interrupt environment.

Similar Threads

  1. Replies: 6
    Last Post: - 12th March 2011, 13:11
  2. 16f886 interrupt on portB problem
    By antonjan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th October 2008, 20:06
  3. 16F689 PORTB.7 Problem
    By jderson in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th April 2008, 06:43
  4. Problem With Bootloader And Portb.3
    By bobonapoletano in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st December 2005, 16:10
  5. Problem with peek in portB
    By hawk72501 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th August 2005, 12: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