Code:
#include <16f886.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#Device ADC = 10
#use Delay(clock=20000000)
long Const Table_sin[400] =
{
500,507,515,523,531,539,547,554,562,570,578,585,593,601,609,616,624,631,639,647
,654,661,669,676,684,691,698,705,712,719,726,733,740,747,754,761,767,774,781,787
,793,800,806,812,818,824,830,836,842,847,853,859,864,869,875,880,885,890,895,899,
904,909,913,917,922,926,930,934,938,941,945,949,952,955,958,961,964,967,970,973,975,977
,980,982,984,986,987,989,991,992,993,995,996,996,997,998,999,999,999,999,100,999,
999,999,999,998,997,996,996,995,993,992,991,989,987,986,984,982,980,977,975,973,970
,967,964,961,958,955,952,949,945,941,938,934,930
,926,922,917,913,909,904,899,895,890,885,880,875,869,864,859,853,847,842,836,830,824,
818,812,806,800,793,787,781,774,767,761,754,747,740,733,726,719,712,705,698,691,684,
676,669,661,654,647,639,631,624,616,609,601,593,585
,578,570,562,554,547,539,531,523,515,507,500,492,484,476,468,460,452,445,437,429,421,
414,406,398,390,383,375,368,360,352,345,338,330,323,315,308,301,294,287,280,273,266,
259,252,245,238,232,225,218,212,206,199,193
,187,181,175,169,163,157,152,146,140,135,130,124,119,114,109,104,100,95,90,86,82,77,
73,69,65,61,58,54,50,47,44,41,38,35,32,29,26,24,22,19,17,15,13,12,10,8,7,6,4,3,3
,2,1,0,0,0,0,0,0,0,0,0,1,2,3,3,4,6,7,8,10,12,13,15,17,19,22,24,26,29,32,35,38,41,
44,47,50,54,58,61,65,69,73,77,82,86,90,95,100,104,109,114,119,124,130
,135,140,146,152,157,163,169,175,181,187,193,199,206,212,218,225,232,238,245,252
,259,266,273,280,287,294,301,308,315,323,330,338,345,352
,360,368,375,383,390,398,406,414,421,429,437,445,452,460,468,476,484,492};
Unsigned Int16 Index;
Void Main()
{
Set_Tris_A(0x0F);
Set_Tris_B(0x00);
Set_Tris_C(0X02);
Setup_Timer_2(T2_DIV_BY_1, 249, 1);
Setup_ccp1(CCP_PWM);
Index = 0;
While(1)
{
Set_pwm1_duty(Table_sin[index]);
Index++;
if (index > 399 )
{
Index=0;
}
}
}