#case //#include "c:\picc\examples\16F84.H" #include "C:\Program Files\PICC\Devices\16f88.h" // Configure PIC to use: HS clock, no Watchdog Timer, // no code protection, enable Power Up Timer // //#fuses HS,NOWDT,NOPROTECT,PUT #fuses INTRC_IO,NOWDT,NOPROTECT,PUT, NOLVP, MCLR, NODEBUG, NOFCMEN, NOIESO #DEVICE ADC=10 // Returns a long 0-FFC0 use 10bit resolution for the ADC // Tell compiler clock is 8MHz. This is required for delay_ms() // and for all serial I/O (such as printf(...). These functions // use software delay loops, so the compiler needs to know the // processor speed. // //#use DELAY(clock=10000000) #use delay (clock=8000000) // Declare that we'll manually establish the data direction of // each I/O pin on port B. // #use fast_io(B) // Standard definitions for the irx2_1 board // #define RS232_XMT PIN_B1 // (output) RS232 serial transmit #define RS232_RCV PIN_B5 // (input) RS232 serial receive #define SWITCH_ONE PIN_B6 // (input) NO #define SWITCH_TWO PIN_B7 // (input) NO #define RED_LED PIN_B3 // (output) Red LED (low true) #define BLUE_LED PIN_B4 // (output) Red LED (low true) //#use rs232(baud=9600, xmit=RS232_XMT, rcv=RS232_RCV) // Macros to simplify I/O operations // #define RED_LED_ON output_low(RED_LED) #define RED_LED_OFF output_high(RED_LED) #define BLUE_LED_ON output_low(BLUE_LED) #define BLUE_LED_OFF output_high(BLUE_LED) // Default tri-state port direction bits: all PORT B bits are // output except for IR_SENSOR (bit 4) and RC232_RCV (bit 5). // #define IRX_B_TRIS 0b11000000 //#define IRX_A_TRIS 0b00000000 void main() { float adc_value, volts_read; int delay_time; // since we've declared #use fast_io(B) (above), we MUST // include a call to set_tris_b() at startup. // set_tris_b(IRX_B_TRIS); // set_tris_a(IRX_A_TRIS); setup_adc_ports(sAN0 | sAN1 | VSS_VDD); setup_adc(ADC_CLOCK_DIV_64); set_adc_channel(0); // int num; RED_LED_ON; delay_ms(500); RED_LED_OFF; delay_ms(500); while(TRUE){ while( (input(SWITCH_ONE) && input(SWITCH_TWO)) ){ // Blink LED's while there is no switch pressed RED_LED_ON; delay_ms(200); RED_LED_OFF; delay_ms(200); BLUE_LED_ON; delay_ms(200); BLUE_LED_OFF; delay_ms(200); } if( !(input(SWITCH_ONE) || input(SWITCH_TWO)) ) { //if Both Switches pressed... delay_cycles(255); //the blinking rate is controlled by the voltage applied to PIN_0. adc_value = read_adc() ; //if PIN_A0 is connected to ground-->lights should blink really fast volts_read = ( (adc_value*4.995117)/1024); //if PIN_A0 is connected to 5v --> light should blink slower delay_time = (int)(volts_read*200); //from 0ms to 1000ms RED_LED_ON; delay_ms(delay_time); RED_LED_OFF; delay_ms(delay_time); BLUE_LED_ON; delay_ms(delay_time); BLUE_LED_OFF; delay_ms(delay_time); } else if( !input(SWITCH_ONE) ) { //Only SWITCH pressed RED_LED_ON; delay_ms(200); RED_LED_OFF; delay_ms(200); } else { //Only SWITCH_TWO pressed BLUE_LED_ON; delay_ms(200); BLUE_LED_OFF; delay_ms(200); } } // Repeat main while forever }