|
Skrevet av Jens Christoffersen
|
|
søndag 14. november 2010 16:09 |
|
Dette programmet styrer denne kretsen.
/*
Program: main.c
Description: Timer program for UV-box
PIC: 16F628
IDE: MPLAB
Compiler: Hi - Tech C
Date: Nov 2010
Author: Jens Christoffersen
web: www.nerdegutta.org
*/
#include <htc.h>
#define _XTAL_FREQ 4000000
/* Configuration */
__CONFIG (WDTDIS &
PWRTEN &
MCLREN &
BOREN &
LVPDIS &
DATUNPROT &
UNPROTECT &
XT);
/* Prototyping the functions */
void lightLED();
void beep();
/* Global variables */
unsigned char i;
/* Functions */
void lightLED()
{
PORTB = 0b00000011; // Setting bit 0 to HIGH
__delay_ms(1000);
PORTB = 0b00000000; // Setting all bits to LOW
} // end lightLED
void beep()
{
for (i=0;i<125;i++)
{
PORTB = 0b00000100; // Setting bit 1 to HIGH
__delay_ms(1);
PORTB = 0b00000000; // Setting bit 1 to LOW
__delay_ms(1);
} // end for-loop
} // end beep
/* Main program */
void main()
{
TRISA = 0b11111111; // Setting all bits on port a to input
TRISB = 0b00000000; // Setting all bits on port b to output
PORTA = 0b00000000; // Setting all bits on port a to LOW
PORTB = 0b00000000; // Setting all bits on port b to LOW
CMCON = 0x07; // Disabling the analogue comparators
while (1)
{
if (RA0)
{
for(i=0;i<2;i++) // Create a delay for 2 seconds
{
lightLED();
} // end for-loop
beep();
} // end if
if (RA1)
{
for(i=0;i<120;i++)
{
lightLED();
} // end for-loop
beep();
} // end if
if (RA2)
{
for(i=0;i<240;i++)
{
lightLED();
} // end for-loop
beep();
} // end if
if (RA3)
{
for(i=0;i<240;i++)
{
lightLED();
} // end for-loop
for (i=0;i<120;i++)
{
lightLED();
}
beep();
} // end if
if (RA4)
{
for(i=0;i<240;i++)
{
lightLED();
} // end for-loop
for(i=0;i<240;i++)
{
lightLED();
}
beep();
} // end if
if (RB7)
{
for (i=0;i<60;i++)
{
lightLED();
}
beep();
}
} // end while
} //end main
Dette er a work in progress. I kretsen er det en flervalg bryter. som veksler triggerporten som korresponerer med hvilken innstilling den har.
|
|
Sist oppdatert torsdag 20. januar 2011 20:35 |