โปรแกรมนี้ต่อบนบอร์ด PIC12C508/9 หรือ PIC12C671/2
ส่วนของการกำหนดต่อบนฮาร์ตแวร์
12C508/671 pin | Protoboard |
---|---|
1 | +5V |
2 | LED 5 |
3 | LED 4 |
4 | Push Button |
5 | LED 3 |
6 | LED 2 |
7 | LED 1 |
8 | gnd |
#if defined(__PCB__)
#include <12C508.h>
#fuses INTRC,NOWDT,NOPROTECT, NOMCLR
#use delay(clock=4000000)
#define GP0 PIN_B0
#define GP1 PIN_B1
#define GP2 PIN_B2
#define GP3 PIN_B3
#define GP4 PIN_B4
#define GP5 PIN_B5
#elif defined(__PCM__)
#include <12C671.h>
#fuses INTRC,NOWDT,NOPROTECT, NOMCLR,NOLVP
#use delay(clock=4000000)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5
#endif
void cycle_forward (void)
{
output_low (GP5);
output_high (GP0);
delay_ms (70);
output_low (GP0);
output_high (GP1);
delay_ms (70);
output_low (GP1);
output_high (GP2);
delay_ms (70);
output_low (GP2);
output_high (GP4);
delay_ms (70);
output_low (GP4);
output_high (GP5);
delay_ms (70);
}
void cycle_backward (void)
{
output_low (GP0);
output_high (GP5);
delay_ms (70);
output_low (GP5);
output_high (GP4);
delay_ms (70);
output_low (GP4);
output_high (GP2);
delay_ms (70);
output_low (GP2);
output_high (GP1);
delay_ms (70);
output_low (GP1);
output_high (GP0);
delay_ms (70);
}
void main() {
#if defined(__PCB__)
setup_counters (RTCC_INTERNAL,RTCC_DIV_2);
// See .h file for other special
// options for setup_counters
#else
setup_counters (RTCC_INTERNAL,RTCC_DIV_2);
#endif
while (TRUE) {
if (!input (GP3))
cycle_forward ();
else
cycle_backward ();
}
}