PIC 18F4680

Discussion in 'Embedded Systems and Microcontrollers' started by AMJC77, May 1, 2015.

  1. AMJC77

    Thread Starter New Member

    Apr 2, 2015
    13
    0
    I'm using the PIC 18F4680 in college for my project. I have a simply piece of code below for toggling a port;

    Code (Text):
    1.  
    2. void main() {
    3.    TRISC =  0x00;               //When you invert the tri-state, it turns on all outputs on the board
    4.    while(1){
    5.    PORTC = 0x55;                // Hex number for 8 LED's    (01010101 in Binary, corresponding to LED position)
    6.    Delay_ms(1);              // Delay of 1000ms or 1 sec
    7.    PORTC = 0xAA;                // Hex number for 8 LED's    (10101010 in Binary, corresponding to LED position)
    8.    Delay_ms(1);              // Delay of 1000ms or 1 sec
    9. }
    10. }
    11.  
    I tested the pin at the time with a multimeter and the pin was pulsing between 0V - 5V. Im just wondering is there a way of finding that pin using the code above. When I add 0x55 + 0xAA = 0xFF which means that all the ports are on. But I remember at the time that I was only getting that pulse on one pin.
    Thanks.

    Moderators note: Please use code tags for pieces of code
     
    Last edited by a moderator: May 2, 2015
  2. ak52

    Member

    Oct 15, 2014
    145
    4
    Hi,
    When 0xFF is written ,which pin is toggling exactly?
    Use LATx to write values and PORTx to read values.

    AK
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    Why do you think "Delay_ms(1);" is a "// Delay of 1000ms or 1 sec"

    I do believe "Delay_ms(1);" will be a delay of 1ms or 0.001 sec.

    A .001 sec delay makes it rather hard for a multimeter to make any sort of reading, though it may see something on the AC scale given the 500Hz square wave.
     
  4. AMJC77

    Thread Starter New Member

    Apr 2, 2015
    13
    0
    That's the thing, I can't remember which pin was being toggled. It was being programmed by the EasyPIC V7 board and was written on that board first. I could see the LED's flashing on PORTC of the EasyPIC in the binary sequence above in the code. Just when the code was transferred to my own board that I was programming it created a pulse on one of the pins, which pin I cannot remember. I don't think its visable from my code either. I don't have the EasyPIC board myself so I cannot check at home.

    Sorry I was messing around with the code and changed the delay but never bothered changing the delay comment around, I know that it is a 1ms delay. Thanks.
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    MPLAB has a PIC simulator built in that will work just fine to test which pins wiggle, and it is only a download away.
     
  6. AMJC77

    Thread Starter New Member

    Apr 2, 2015
    13
    0
    Do I just paste my code in and it will give me a result?
     
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    MPLABX

    no you need to select the Simulator then compile + start simulation session.

    18F different than 16F needs LAT registers to be set, as well delay isnt really good you should use a timer interrupt.
     
Loading...