Shake_ECET209
New Member
Hi guys, im writing a program that takes two analog voltages VA[0] and VA[1]. whenever a switch is closed on port B0, blink a LED on portb4 for 100ms only if voltage VA[0] exceeeds voltage VA[1].
I am trying to modify a previous code form another lab, I am kinda lost. I just need to add a switch at b0 and blink an led at b4 for 10mms only if the voltage at Va[0] exceeds Va[1]
Thanks for any help guys
I am trying to modify a previous code form another lab, I am kinda lost. I just need to add a switch at b0 and blink an led at b4 for 10mms only if the voltage at Va[0] exceeds Va[1]
Thanks for any help guys
Code:
#include<C:\Program Files\Microchip\Third Party\PICC\Devices\16f88.h>
#fuses INTRC_IO, NOWDT, PUT, NOMCLR, NOBROWNOUT
#use delay(clock=4000000)
unsigned char value;
void setup_16F88();
void infiniteloop(void) ;
void main()
{ setup_16F88();
infiniteloop() ;
}
void setup_16F88(void)
{ set_tris_a(0xbf); //Define all possible input Bits as Input
set_tris_b(0x00); //Define as all output bits
/*Setting Analog comparator mode in which there are two analog comparators Comp1 and Comp2. Our analog inputs are applied on Channel AN1 and AN2, the output is available on C2OUT, which is either a ‘0’ or ‘1’. The input to other comparator COMP1 are AN0 and AN3 and the output is available on C1OUT bit. AN0 and AN3 input ports are grounded in this configuration. */
setup_adc_ports(sAN0|sAN1 |sAN2 |sAN3);
delay_us(20); // for stabilization
setup_comparator(A0_A3_A1_A2); //A0 and A3 input to Comp1 with output at C1OUT
//A1 and A2 input to Comp2 with output at C2OUT
}
void infiniteloop(void)
{ while(1)
{ output_b(C2OUT); // the C2OUT is a single bit, put on port_B0.
}
}
Last edited: