Error in C program for PIC16F505

Thread Starter

devilsoundwave

Joined Jun 30, 2014
3
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.

Rich (BB code):
/*******************************/
/* Written by: Ross MacDougall */
/* Date: 2014/04/27            */
/* Version: 1.0.0              */
/* File Saved as: Logic Latch  */
/* For PIC16F505               */
/* Clock Frequency: 4 MHz      */
/*******************************/
 //PROGRAM FUNCTION: Stuff and things - add proper description later
 #include "xc.h"
#include "16F505.H"
 #pragma config WDT=ON
#pragma config OSC=XT
#pragma config CP=OFF
#pragma config MCLRE=ON 
 void main () {
    TRISB=0b00011011;            // Set pin 3, 4, 12, 13 as input and 2, 11 as output
 TRISC=0;              // Set all pins on PORTC as outputs
 PORTC=0b00000000;           // Set all pins on PORTC as 0
  for(;;){             //endless loop
 if(PORTB.RB0 == 1 && PORTB.RB2 == 1)       // If switch 1 is pressed
 PORTC = 0b00000001;           // Set outputs of port C to Binary 1
 else if(PORTB.RB0 == 1 && PORTB.RB5 == 1)     // If switch 2 is pressed
 PORTC = 0b00000010;           // Set outputs of port C to Binary 2
 else if(PORTB.RB0 == 1 && PORTC.RC4 == 1)     // If switch 3 is pressed
 PORTC = 0b00000011;           // Set outputs of port C to Binary 3
 else if(PORTB.RB0 == 1 && PORTC.RC5 == 1)     // If switch 4 is pressed
 PORTC = 0b00000100;           // Set outputs of port C to Binary 4
 else if(PORTB.RB1 == 1 && PORTB.RB2 == 1)     // If switch 5 is pressed
 PORTC = 0b00000101;           // Set outputs of port C to Binary 5
 else if(PORTB.RB1 == 1 && PORTB.RB5 == 1)     // If switch 6 is pressed
 PORTC = 0b00000110;           // Set outputs of port C to Binary 6
 else if(PORTB.RB1 == 1 && PORTC.RC4 == 1)     // If switch 7 is pressed
 PORTC = 0b00000111;           // Set outputs of port C to Binary 7
 else if(PORTB.RB1 == 1 && PORTC.RC5 == 1)     // If switch 8 is pressed
 PORTC = 0b00001000;           // Set outputs of port C to Binary 8
 else if(PORTB.RB4 == 1 && PORTB.RB2 == 1)     // If switch 9 is pressed
 PORTC = 0b00001001;           // Set outputs of port C to Binary 9
 else if(PORTB.RB4 == 1 && PORTB.RB5 == 1)     // If switch 10 is pressed
 PORTC = 0b00001010;           // Set outputs of port C to Binary 10
 else if(PORTB.RB4 == 1 && PORTC.RC4 == 1)     // If switch 11 is pressed
 PORTC = 0b00001011;           // Set outputs of port C to Binary 11
 else if(PORTB.RB4 == 1 && PORTC.RC5 == 1)     // If switch 12 is pressed
 PORTC = 0b00001100;           // Set outputs of port C to Binary 12
 else if(PORTB.RBO == 0 && PORTB.RB1 == 0 && PORTB.RB4 == 0) // While no switch is pressed, do nothing
 continue;             // Do nothing
 
 }
}
 

ErnieM

Joined Apr 24, 2011
8,183
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.
 
Top