unsigned char sin_table[32]={0, 10, 19, 29, 38, 47,
55, 63, 70, 77, 82, 87, 91, 95, 97,
99, 99, 99, 97, 95, 91, 87, 82, 77, 70, 63, 55, 47, 38, 29, 19, 10};
unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
unsigned int TBL_temp;
unsigned char DUTY_CYCLE;
//Set LCD Bits for DATA Direction
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
void interrupt(){
if (TMR2IF_bit == 1){
TBL_POINTER_NEW = TBL_POINTER_OLD + SET_FREQ;
if (TBL_POINTER_NEW < TBL_POINTER_OLD){
CCP1CON.P1M1 = ~CCP1CON.P1M1; //Reverse direction of full-bridge
}
//TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 11;
TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 13;//10KHZ
DUTY_CYCLE = TBL_POINTER_SHIFT;
CCPR1L = sin_table[DUTY_CYCLE];
TBL_POINTER_OLD = TBL_POINTER_NEW;
TMR2IF_bit = 0;
}}
void main() {
Lcd_Init();
LCD_Cmd(_LCD_CLEAR);
LCD_Cmd(_LCD_CURSOR_OFF);
SET_FREQ=512;//50HZ at 12MHZ with 20MHZ and 32 values
TBL_POINTER_SHIFT = 0;
TBL_POINTER_NEW = 0;
TBL_POINTER_OLD = 0;
DUTY_CYCLE = 0;
ANSELA = 0x0F; //Enable Analog Reading for RA0-RA3
PR2=99;
TRISC = 0x07; //Only RC2 is output
PORTC=0X07;
TRISD=0;
PORTD=0;
TRISA=0x0F;
PORTA=0x0F;
TRISB=0X01;
PORTB=0x01;
CCP1CON = 0b00001101;
PWM1CON=0X80;
TMR2IF_bit = 0;
T2CON =0X04; //TMR2 on, prescaler and postscaler 1:1
while (TMR2IF_bit == 0);
TMR2IF_bit = 0;
TRISC = 0x00;
TRISD=0X00;
TMR2IE_bit = 1;
GIE_bit = 1;
PEIE_bit = 1;
//ADC Initialization
// ADC_Init();
while(1)
{
}
}