programming a pic16f877A

Status
Not open for further replies.

haya.a

New Member
I am new to programing micro-controllers.
I want to use the internal comparator of this PIC and compare a voltage say if greater than 2V, i want an output, say an LED to blink for simplicity.
By the way, i am using the program MicroC for programing.

void main()
{
TRISA=0b001111; //i understand im initializing the A ports. MSB as 0 and LSB as 1
CMCON=0b00000011 // I got this command off the datasheet to use the comparator
}


NOTE: Datasheet availabe --> https://www.electro-tech-online.com/custompdfs/2010/04/39582b-1.pdf


Well this doesnt work, could someone tell me whats wrong?
Or atleast guide me in the right direction...
Need help ASAP.... thanks....
 
haha... this is my complete program =)

i first tested the microcontroller using this program to blink a LED.

void main ()
{
PORTB=0;
TRISB=0;

while (1)
{
PORTB=~PORTB;
Delay_ms(1000);
}
}

using the same concept, i came up with the program posted above.

Thankyou for taking time to reply to my noob questions
 
yes tht program (the 2nd one) did work.
Im using the program MicroC for writing the code.
You specify the device and its architecture in the beginning of the project and then when it compiles the hex file, it automatically configures...

I just need to know which command will enable me to use the internal comparator and i also need to know what command can i use when i want to address a single pin and not the entire port. Say I need to specify IF portA pin 3 == 2... how can i translate that into code?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…