Problem with ports help plz


Closed Thread
Results 1 to 34 of 34

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    23


    Did you find this post helpful? Yes | No

    Smile

    I finally found the solution. You cannot clear PORTA
    when I removed the code
    'PORTA = %01000000 ' Clear PORTA
    It worked on the first 'release from reset'. Now all I need is to indivually clear each bit.

  2. #2
    Join Date
    Jul 2009
    Posts
    23


    Did you find this post helpful? Yes | No

    Talking

    How's this for Spaghetti Code

    PORTA.1 = 0 :PORTA.2 = 0 :PORTA.3 = 0 :PORTA.4 = 0 :PORTA.5 = 0 :PORTA.6 = 0

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wbubel View Post
    How's this for Spaghetti Code

    PORTA.1 = 0 :PORTA.2 = 0 :PORTA.3 = 0 :PORTA.4 = 0 :PORTA.5 = 0 :PORTA.6 = 0
    A friend of mine writes code that way. Here is a mild sample.
    http://www.picbasic.co.uk/forum/showthread.php?t=5407
    After you do it that way for awhile it begins to make sence.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Boat-load of errors in wbubels code Dave.

    Got an E-Beer ready for the first one to fix em all & explain in detail why...;o}
    Last edited by Bruce; - 31st July 2009 at 02:06.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Boat-load of errors in wbubels code Dave.

    Got an E-Beer ready for the first one to fix em all & explain in detail why...;o}
    But he said it was working
    I was planning on going through it when I get back to the shop. A phone and traveling is not the best place to write and or fix code.

    Maybe some one will else will get that beer
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default E Beer, is there anything it can't do ?

    HiYa wbubel,
    PortA = %01000000 means portA.6 is going high when port is made an output, so if it crosses that place in space time while the PIC is initializing you will see PortA.6 output high. You want to set PortA.6 as zero and do it before you set the tris register to input or output so when it becomes an output or input the latch register is set in a known state, setting it as 1 does not enable pullups or anything like that, so you should have:
    Code:
    PortA = %00000000 ' set port latches low
    TrisA  = %01000000 ' make RA6 input
    You ever watched an old mechanical slot machine? Figure your registers are going like that until the pic boots and settles into the default mode, usualy 11111111, then it follows your code.
    Last edited by Archangel; - 31st July 2009 at 03:21.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Code:
    DEFINE OSC 4 'Define the Osc to 8 MHz
    
    asm
        bsf OSCCON, SCS1 ; 1x = Internal Block
        bcf OSCCON, SCS0 ; 00 = Primary Oscillator (20Mhz?)
        bsf OSCCON, IRCF2 ; 111=8000 110=4000 101=2000
        bsf OSCCON, IRCF1 ; 100=1000 011=0500 010=0250
        bcf OSCCON, IRCF0 ; 001=0125 000=0032
        MSTABLE010 btfss OSCCON, IOFS
        bra MSTABLE010 ; wait until Oscillator is stable
    endasm 
    data @0,0 'Initialize location 0 on eeprom to zero
    LED2 var PORTB.2 ' LED
    cntr var word
    FET  var PORTA.0
    'PORTB = %00000100 ' Clear PORTB, and set B2
    PortB = %00000000 ' clear port latch bits 
    'PORTA = %01000000 ' Clear PORTA
    PortA = %00000000  ' Clear PortA latches
    'TRISA = %01000000 ' Set PORTA port 2 and 7 to input, 0, 3-6 ,8 Output
    TRISA = %10000100  'Set PORTA port 2 and 7 to input, 0, 3-6 ,8 Output
    TRISB = %00000000 ' Set PORTB to all output
    led2 = 1 ' PortB.2 high LED on
    
    read 0,cntr 'read location 0 or eeprom
    FET = 0 ' PortA.0 Low
    if (PORTA.7 = 0) then pause 255 ' pause 255 milliseconds
    If (PORTA.7 = 0) then write 0,0 'reset eeprom to 0 when port A Bit 7 has been forced to 0
    
    
    Main:
    led2 = 0    'PortB.2 Low LED off
    pause 64    ' very strange choice of pause 64 milliseconds
    led2 = 1    ' LED on
    if (cntr < 10) then
    Pause 255 'slow blink under ten cycles  cycles of what ?
    pause 255 ' why this duplicate pause is good for something like 65535 ms
    else
    Pause 64 'fast blink over 10 cycles  cycles of what ?
    endif
    cntr = cntr + 1 'increment cntr
    write 0,cntr                  'write new cntr value into eeprom
    if (cntr <= 20) then goto main
    FET = 1 'Shut down RF Current
    ' cntr = 0
    'stop  stop stops all brain activity how can it goto main?
    goto main
    'Stop
    
    End
    Here is your code with comments . . .changes
    Last edited by Archangel; - 31st July 2009 at 04:33.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    Great!
    I saw you configs and was wondering about the OSC setting.
    But if it is working...
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. sleep problem help plz >>>.
    By Mus.me in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 16th November 2009, 09:21
  2. Replies: 6
    Last Post: - 10th January 2008, 11:38
  3. ESC problem plz help
    By al000y in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 21st January 2007, 11:21
  4. Problem reading multiple ADC ports
    By jswayze in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 4th November 2004, 17:46
  5. Problem with intensity.. plz help
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th October 2004, 18:25

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