Help setting an output pin high.

Thread Starter

ATM

Joined Oct 8, 2009
31
Greetings all,

I'm in the middle of a project at the minute and i'm stumped. Basically i'm using one of the internal comparators of the PIC16F88 to monitor a sensor input on pin RA1, when this input drops below the reference voltage, I want to induce an output on pin RB4. This part of my project works correctly.

However I also want to set pin RB4 high if another input pin RA4 is high. I have wrote the following 'C' code in Source Boost;
#include <system.h>
#include <pic16F88.h> //Pic Chip being used

void main() //start of main function
{

volatile bit RA1 @ PORTA.1; //declare port bits
volatile bit RA4 @ PORTA.4;
volatile bit RB4 @ PORTB.4;

trisa=10010b; //set RA4 and RA1 as inputs
trisb=0b; //set RB4 as outputs
portb=0; //initialise Portb
osccon=0x7E; //internal 8Mhz clock

cmcon=00000010b; //configure comparators 010,
cvrcon=11000100b; //set reference voltage of 2.88 volts


delay_s(10); //create 10 second delay
while(1) //infinite loop
{
RB4=cmcon.7; //assign the comparison result to RB4
if (cmcon.7==0 && RA4==1) //if comparison is low but switch at RA4 is pressed set RB4 high for 10 seconds
{
RB4=1;
delay_s(10);
}
} //end of while loop
} //end of main
If the result of the comparison is high I am receiving an output on Pin RB4, but if the result of the comparison is low and I set Pin RA4 high, there is no output on pin RB4 when I plug the PIC into my circuit which is what I require.

Can anyone see anything wrong with the above code?
 
Top