void InitTimer0(){
T0CON = 0xC1;
TMR0L = 0x24;
GIE_bit = 1;
TMR0IE_bit = 1;
}
void Interrupt(){
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0L = 0x24;
if(Sine_wave_step > 354){ Sine_wave_step = 4; } else { Sine_wave_step++; }
VREFCON2 = sin_table[Sine_wave_step];
current = 0;
if(current_time1 == 20) {
current_millis++;
current_time1 = 0;
} else {
current_time1++;
}
}
}
void main() {
ANSELA = 0;
ANSELB = 0;
ANSELC = 0x00;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
ADCON1= 0;
INTCON2.RBPU =0;
LATB4_bit = 1;
LATB5_bit = 1;
LATB3_bit = 1;
LATB2_bit = 1;
osccon2.pllrdy = 1;
while(OSCCON2.PLLRDY != 1);
for (i = 4; i <=180; i++)
{
sin_table[i]=16+floor(15*sin(i * PI /180));
sin_table[i+180]=32-sin_table[i];
}
delay_ms(10);
InitTimer0();
delay_ms(1000);
Lcd_Init();
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,txt1);
Lcd_Out(2,1,txt2);
IntToStr(current_im,curr_im_ch);
IntToStr(current_pa,curr_pa_ch);
Lcd_Out(1,7,curr_im_ch);
Lcd_Out(2,8,curr_pa_ch);
VREFCON1 = 0b11110010;
VREFCON2 = 31;
while(1) {
}
}