#pragma chip PIC16F873 #define CP_off |= 0x3F30 // 16C62X and similar #pragma config CP_off, WDTE=off, FOSC=HS, BODEN=off #pragma config |= 0x800 // set bit 11 This turns off Background debugging /* global variables */ char a; char t; bit b1, b2; /* assign names to port pins */ #pragma bit led @ PORTB.0 #pragma bit led2 @ PORTB.1 #pragma origin 4 interrupt serverX(void) { } void delay(char x) { char i; do { i = 255; do i = i -1; while (i > 0); } while (--x > 0); /* 3 is */ } #include "picuart.c" #include "encoder.c" void main( void) { char i, j, c, err; // if (TO == 1 && PD == 1 /* power up */) { // WARM_RESET: clearRAM(); // clear all RAM // } /* first decide the initial output level on the output port pins, and then define the input/output configuration. This avoids spikes at the output pins. */ PORTA = 0b.1111; /* out = 1 */ TRISA = 0b.0000.0000; /* xxxx 0001 */ PORTB = 0b.1111.1111; /* out = 1 */ TRISB = 0b.0011.1100; /* xxxx 0001 */ PORTC = 0b.1111.1111; /* out = 1 */ TRISC = 0b.0000.0000; /* xxxx 0001 */ delay(250); led = 1; delay(250); led = 0; delay(250); led = 1; delay(250); led = 0; uart_init(B9600); j = 0; for (i=0;;i++) { poll_encoders(); /* if (uart_byte_ready()) { err = uart_error(); c = RCREG; if (err) { c = 0; do { led = !led; delay(100); } while (--err); CREN = 0; nop(); SPEN = 0; nop(); TXEN = 0; nop(); uart_init(B2400); } else { led = !led; } switch (c) { case 'e': case 'E': delay(20); uart_putb(enc1count); uart_putb(enc2count); break; case 'r': case 'R': delay(20); uart_putb(enc1count); uart_putb(enc2count); enc1count = 0; enc2count = 0; break; default: break; } } */ if (i == 0) { j++; if (j == 12) { j = 0; uart_putb(13); uart_puthex(enc1count2); uart_puthex(enc1count); uart_putb(32); uart_puthex(enc2count2); uart_puthex(enc2count); led2 = !led2; } } } for (;;) ; // end of main - loop forever }