Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include <16F1825.h>
#fuses NOFCMEN ,NOIESO, NOCLKOUT, BROWNOUT, NOCPD, NOPROTECT, NOMCLR, NOPUT, NOWDT, INTRC_IO
#fuses NOLVP, NODEBUG, BORV19, NOSTVREN, PLL, NOWRT
#use delay(clock=32M)
#use I2C(MASTER, scl=PIN_C0, sda=PIN_C1, FORCE_HW, FAST=1900000)
CONST unsigned long SINE_WAVE[85] = { 0, 15, 30, 45, 60, 76, 91, 106, 121, 136, 150, 165, 180, 195, 210, 224, 239, 253, 267, 282, 296, 310, 324, 338, 351, 365, 379, 392, 405, 418, 431, 444, 457, 469, 481, 494, 506, 517, 529, 540, 552, 563, 574, 584, 595, 605, 615, 625, 635, 644, 654, 663, 671, 680, 688, 696, 704, 712, 719, 726, 733, 740, 746, 752, 758, 764, 769, 774, 779, 783, 788, 792, 795, 799, 802, 805, 808, 810, 812, 814, 816, 817, 818, 818, 819 };
void dac_i2c(unsigned int16 sample){
i2c_start(); // Start
i2c_write(0b11001000); // Device address
i2c_write(0b1000000); // Internal Device address
i2c_write((sample & 0xFF0) >> 4); // Upper data bits (D11.D10.D9.D8.D7.D6.D5.D4)
i2c_write((sample & 0xF) << 4); // Lower data bits (D3.D2.D1.D0)
i2c_stop(); // Stop
}
void main() {
setup_adc(ADC_OFF);
unsigned long int i=0;
disable_interrupts(GLOBAL);
while(TRUE){
while (i< 84){
i++;
delay_cycles (33);
dac_i2c(SINE_WAVE[i]);
}
while (i>0){
i--;
delay_cycles (33);
dac_i2c(SINE_WAVE[i]);
}
}
}