Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me with C code for 8051

Status
Not open for further replies.

dbju

Newbie level 3
Joined
Aug 29, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,308
#include<stdio.h>
#include<conio.h>



main()
{
int n,a,p,q,r;
float l,b,a1,tri[1600],sum[1600],d,c,f,g1[1600],g2[1600],g3[1600],g4[1600];

c=(5*3.142)/180;
for(a1=0;a1<=180;)
{
a=2*a1;
b=(a1*3.142)/180;
d=b;
p=1;
q=1;
sum[a]=b;
for(p=1;p<21; )
{
d=(-1)*b*b*d;
p=p+2;
q=p*(p-1)*q;
sum[a]=sum[a]+d/q;
}


a1=a1+0.5;
}
for(n=0;n<=8;n++)
{
l=n*20;
for(a1=(l);a1<(l+5)
{
a=2*(a1);
r=((a1-l)*3.142)/180;

tri[a]=r/c;

a1=a1+0.5;
}
for(a1= (l+5);a1<(l+15)
{
a=2*(a1);
r=((a1-l)*3.142)/180;

tri[a]=(2-r/c);

a1=a1+0.5;
}
for(a1=(l+15);a1<(l+20)
{
a=2*(a1);
r=((a1-l)*3.142)/180;

tri[a]=(r/c-4);

a1=a1+0.5;
}
}
for(a1=0;a1<=180;)
{
a=2*a1;

if((sum[a]>tri[a]))

{g1[a]=1;

}
else
{
g1[a]=0;

}
a1=a1+0.5;
}
printf("\n");
for(a1=0;a1<=180;)
{
a=2*a1;
g2[a]=-sum[a];
if((g2[a]>tri[a]))

{g3[a]=1;

}
else
{
g3[a]=0;

}
a1=a1+0.5;
}
printf("\n");
for(a1=0;a1<=180;)
{
a=2*a1;
g4[a]=g1[a]-g3[a];
if(g4[a]>0)
P0=high;
else
po=low;
a1=a1+0.5;
}

getch();

}
 

Re: 8051 + c programming

what you want reply? what is your question?
 

Re: 8051 + c programming

i want to generate a sine wave and a triangular wave in micro controller without using look up table since both these signals will be compared by logical program at each degree by which a pulse width modulated signal will be generated .i have already written a c program for the purpose now i want compiler of 8051 to do the remaining things. So i want this program to be converted into a 8051 based c programming with output pwm at output port P0 of 8051.
 

thanks but that link is showing the same link again and its a blank page
 

Using indenting, spacing and commenting may vastly help maintain and debug your code:

Code:
#include<stdio.h>
#include<conio.h>


int main()
{
	int n, a, p, q, r;
	float l, b, a1, tri[1600], sum[1600], d, c, f, g1[1600], g2[1600], g3[1600], g4[1600];


	c= (5* 3.142)/ 180;

	for(a1= 0; a1<= 180; a1+= 0.5) {
		a= 2* a1;
		b= (a1* 3.142)/ 180;
		d= b;
		p= 1;
		q= 1;
		sum[a]= b;

		for(p= 1; p< 21;) {
			d= (-1)* b* b* d;
			p+= 2;
			q= p* (p- 1)* q;
			sum[a]= sum[a]+ d/ q;
		}// for
	}// for

	for(n= 0; n<= 8; n++) {
		l= n* 20;

		for(a1= l; a1< (l+ 5); al+= 0.5) {
			a= 2* a1;
			r= ((a1- l)* 3.142)/ 180;
			tri[a]= r/ c;
		}// for

		for(a1= (l+ 5); a1< (l+ 15); a1+= 0.5) {
			a= 2* a1;
			r= ((a1- l)* 3.142)/ 180;
			tri[a]= (2- r/ c);
		}// for

		for(a1= (l+ 15); a1< (l+ 20); a1+= 0.5) {
			a= 2* a1;
			r= ((a1- l)* 3.142)/ 180;
			tri[a]= (r/ c- 4);
		}// for
	}// for

	for(a1= 0; a1<= 180; a1+= 0.5) {
		a= 2* a1;

		if(sum[a]> tri[a]) {
			g1[a]= 1;
		}// if
		else {
			g1[a]= 0;
		}// else
	}// for

	printf("\n");

	for(a1= 0; a1<= 180; a1+= 0.5) {
		a= 2* a1;
		g2[a]= -sum[a];

		if(g2[a]> tri[a]) {
			g3[a]= 1;
		}// if
		else {
			g3[a]= 0;
		}// else
	}// for

	printf("\n");

	for(a1= 0; a1<= 180; a1+= 0.5) {
		a= 2* a1;
		g4[a]= g1[a]- g3[a];

		if(g4[a]> 0)
			P0= high;
		else
			po= low;
	}// for

	getch();
}// main

Also be aware that to compile this code you'll need more than 9600*4= 38400 bytes of RAM. You might take that into consideration.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top