#include <16F88.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,PUT,CCPB3
#use delay(clock=8000000)
int i, j;
CONST unsigned int SINE_WAVE[30] = {
0b00010000, 0b10010000, 0b01010000, 0b11010000, 0b00110000, 0b10110000,
0b01110000, 0b11110000, 0b01110000, 0b10110000, 0b00110000, 0b11010000,
0b01010000, 0b10010000, 0b00010000, 0b11100000, 0b01100000, 0b10100000,
0b00100000, 0b11000000, 0b01000000, 0b10000000, 0b00000000, 0b10000000,
0b01000000, 0b11000000, 0b00100000, 0b10100000, 0b01100000, 0b11100000};
#INT_RTCC
void main_wave() {
if (i++ == 29)
i = 0;
output_b(SINE_WAVE[i]);
}
#INT_TIMER2
void TIMER2_isr() {
if (j++ == 29)
j = 0;
output_a(SINE_WAVE[j]>>4);
}
void main(void) {
i = 0;
j = 0;
setup_adc_ports(NO_ANALOGS); // Turn off analogue inputs
setup_oscillator(OSC_8MHZ | OSC_INTRC); // Use internal 8MHz osc
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT);
// about 258.7Hz
setup_timer_2( T2_DIV_BY_4, 65, 1 );
// 65 gives 250.8Hz
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
while(TRUE)
{
delay_ms(1);
}
disable_interrupts(INT_RTCC);
}