I need your help again!
I'm using PIC16F1847 and MikroC Pro using an 8MHZ internal clock.
I'm trying to read the value of dipswitches. Switches 1 to 5 are reading correctly and performing as expected, however, dip switches 6&7 use RA6 & RA7 which are the OSC1 & OSC2 pins and these pins are always reading high.
I've set the oscillator selection to 'INTOSC' in the 'Edit Project' settings but this does not seem to be settings the RA6 & RA7 pins as inputs.
I need to set pins RA6 & RA7 as inputs and I'm really struggling to get my head around this. Any help would be appreciated.
Code: Select all
sbit Start at RB0_bit;
sbit Relay at RB3_bit;
sbit Led at RB2_bit;
sbit Clr at RA5_bit;
sbit dip_sw_1 at RA2_bit;
sbit dip_sw_2 at RA3_bit;
sbit dip_sw_3 at RA4_bit;
sbit dip_sw_4 at RA1_bit;
sbit dip_sw_5 at RA0_bit;
sbit dip_sw_6 at RA7_bit; // I/O NOT WORKING ON THIS PIN
sbit dip_sw_7 at RA6_bit; // I/O NOT WORKING ON THIS PIN
sbit dip_sw_8 at RB1_bit;
sbit dip_sw_9 at RB4_bit;
sbit dip_sw_10 at RB5_bit;
// assign varibles
unsigned int i, timer_duration;
void main() {
OSCCON = 0x72;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISA = 0b00011111; //
ANSELA = 0b00000000; // PORTA all digital pins
PORTA = 0; // All PORTB pins are cleared
TRISB = 0b11110011; //
ANSELB = 0b00000000; // PORTB all digital pins
PORTB = 0; // All PORTB pins are cleared
LED = 1; // Switch the LED On
RELAY = 0; // Switch the RELAY Off
do {
//get binary value by reading dipswitches
timer_duration = 0;
if( dip_sw_1 == 0 ){ timer_duration = timer_duration + 1; }
if( dip_sw_2 == 0 ){ timer_duration = timer_duration + 2; }
if( dip_sw_3 == 0 ){ timer_duration = timer_duration + 4; }
if( dip_sw_4 == 0 ){ timer_duration = timer_duration + 8; }
if( dip_sw_5 == 0 ){ timer_duration = timer_duration + 16; }
if( dip_sw_6 == 0 ){ timer_duration = timer_duration + 32; }
//if( dip_sw_7 == 0 ){ timer_duration = timer_duration + 64; }
//Flash the Led to indicate the number read from the dipswitches
for (i = 1; i <= timer_duration; i++) {
Led = 0;
Delay_ms(200);
Led = 1;
Delay_ms(300);
}
Delay_ms(2000);
} while (1);
}