#include "pic.h" #include "delay.h" #define TRIM 80 // trimming for delay time to 100us __CONFIG(INTIO & WDTDIS & BORDIS & MCLRDIS);
main(){ // initialize unsigned long cnt, i; // cnt: counter, i: etc unsigned char f; // flag for the end of set process TRIS0=0; // LED: GPIO0 for digital output TRIS1=0; // BUZZ: GPIO1 for digital output TRIS2=1; // SW: GPIO2 for digital input CMCON=0x07;
while (1){
// reset LED, BUZZ and counter GPIO0=1; // LED OFF GPIO1=0; // BUZZ OFF cnt=0; // reset counter
// set process f=0; // count start flag while (!f){ while (GPIO2); // wait for SW-ON GPIO0=0; // LED ON cnt+=10; // 10 sec plus DelayUs(TRIM); // chattering off while (!GPIO2); // wait for SW-OFF GPIO0=1; // LED OFF DelayUs(TRIM);
i=0; while (GPIO2){ // count interval while SW-OFF DelayUs(TRIM); i++; if (i>20000){ f=1; break; } } }
// wait for start-SW while (GPIO2){ // wait for SW-ON GPIO0=0; // LED ON for (i=0;i<500;i++) DelayUs(TRIM); GPIO0=1; // LED ON for (i=0;i<500;i++) DelayUs(TRIM); }
// count down process while (cnt>0){ // count down cnt GPIO0=1; // LED OFF for (i=0;i<5000;i++) { DelayUs(TRIM); } GPIO0=0; // LED OFF for (i=0;i<5000;i++) { DelayUs(TRIM); } cnt--; }
// Timeout, BUZZ and LED ON while (GPIO2){ // wait for stop GPIO0=0; // LED ON GPIO1=1; // BUZZ ON for (i=0;i<10;i++) DelayUs(TRIM); GPIO1=0; // BUZZ OFF for (i=0;i<10;i++) DelayUs(TRIM); } DelayUs(TRIM); // chattering off while (!GPIO2); // wait for SW-OFF } }