Error in C program for PIC16F505

Discussion in 'Embedded Systems and Microcontrollers' started by devilsoundwave, Jun 30, 2014.

  1. devilsoundwave

    Thread Starter New Member

    Jun 30, 2014
    3
    0
    I wonder if someone can help me...

    I've been working on a piece of code for a friend for an audio controller thingy, and have debugged it right down to a final error which is suggesting that a struct/union is required in and around my nested "if else", however I don't see were it would be appropriate.

    Am using MPLAB IDE, and am programming for PIC16F505.

    Code ( (Unknown Language)):
    1. /*******************************/
    2. /* Written by: Ross MacDougall */
    3. /* Date: 2014/04/27            */
    4. /* Version: 1.0.0              */
    5. /* File Saved as: Logic Latch  */
    6. /* For PIC16F505               */
    7. /* Clock Frequency: 4 MHz      */
    8. /*******************************/
    9.  //PROGRAM FUNCTION: Stuff and things - add proper description later
    10.  #include "xc.h"
    11. #include "16F505.H"
    12.  #pragma config WDT=ON
    13. #pragma config OSC=XT
    14. #pragma config CP=OFF
    15. #pragma config MCLRE=ON
    16.  void main () {
    17.     TRISB=0b00011011;            // Set pin 3, 4, 12, 13 as input and 2, 11 as output
    18.  TRISC=0;              // Set all pins on PORTC as outputs
    19.  PORTC=0b00000000;           // Set all pins on PORTC as 0
    20.   for(;;){             //endless loop
    21.  if(PORTB.RB0 == 1 && PORTB.RB2 == 1)       // If switch 1 is pressed
    22.  PORTC = 0b00000001;           // Set outputs of port C to Binary 1
    23.  else if(PORTB.RB0 == 1 && PORTB.RB5 == 1)     // If switch 2 is pressed
    24.  PORTC = 0b00000010;           // Set outputs of port C to Binary 2
    25.  else if(PORTB.RB0 == 1 && PORTC.RC4 == 1)     // If switch 3 is pressed
    26.  PORTC = 0b00000011;           // Set outputs of port C to Binary 3
    27.  else if(PORTB.RB0 == 1 && PORTC.RC5 == 1)     // If switch 4 is pressed
    28.  PORTC = 0b00000100;           // Set outputs of port C to Binary 4
    29.  else if(PORTB.RB1 == 1 && PORTB.RB2 == 1)     // If switch 5 is pressed
    30.  PORTC = 0b00000101;           // Set outputs of port C to Binary 5
    31.  else if(PORTB.RB1 == 1 && PORTB.RB5 == 1)     // If switch 6 is pressed
    32.  PORTC = 0b00000110;           // Set outputs of port C to Binary 6
    33.  else if(PORTB.RB1 == 1 && PORTC.RC4 == 1)     // If switch 7 is pressed
    34.  PORTC = 0b00000111;           // Set outputs of port C to Binary 7
    35.  else if(PORTB.RB1 == 1 && PORTC.RC5 == 1)     // If switch 8 is pressed
    36.  PORTC = 0b00001000;           // Set outputs of port C to Binary 8
    37.  else if(PORTB.RB4 == 1 && PORTB.RB2 == 1)     // If switch 9 is pressed
    38.  PORTC = 0b00001001;           // Set outputs of port C to Binary 9
    39.  else if(PORTB.RB4 == 1 && PORTB.RB5 == 1)     // If switch 10 is pressed
    40.  PORTC = 0b00001010;           // Set outputs of port C to Binary 10
    41.  else if(PORTB.RB4 == 1 && PORTC.RC4 == 1)     // If switch 11 is pressed
    42.  PORTC = 0b00001011;           // Set outputs of port C to Binary 11
    43.  else if(PORTB.RB4 == 1 && PORTC.RC5 == 1)     // If switch 12 is pressed
    44.  PORTC = 0b00001100;           // Set outputs of port C to Binary 12
    45.  else if(PORTB.RBO == 0 && PORTB.RB1 == 0 && PORTB.RB4 == 0) // While no switch is pressed, do nothing
    46.  continue;             // Do nothing
    47.  
    48.  }
    49. }
     
  2. NorthGuy

    Active Member

    Jun 28, 2014
    604
    121
    It says that PORTB is not a strut or union. I guess you need to use PORTBBits or something of that sort.
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    You just need to replace every instance of "PORTB." with "PORTBbits." and every instance of "PORTC." with "PORTCbits."

    Once you complete that you have to correct "PORTBbits.RBO" Hint: you can't use a letter for a number.
     
  4. devilsoundwave

    Thread Starter New Member

    Jun 30, 2014
    3
    0
    Thanks guys, I'll go try all that.

    I'm terrible for typing O instead of 0. What a clown!
     
  5. devilsoundwave

    Thread Starter New Member

    Jun 30, 2014
    3
    0
    All compiled nicely and burned to my PIC. Thanks guys! :)
     
Loading...