I need Help explaining a C program

Intel / Centrino
January 23, 2009 at 02:04:54
Specs: Windows XP, Centrino Duo
Hey.
Would anyone please help me explain this C code? I found it in the internet and im using it on a project, but it seems too complicated for me because i studied C++, and not C.
Thank you all :)

This is the C code:

#include <reg52.h>
#include <stdio.h>

void timer0int(void);
char *Puts(char* str);

float read_temp1(void);
float read_temp1_filter(void);


char cputick;
char buffer[24];
char pulseE;

char timer3;
char temp;
char vout;
int x1,x2,x3,x4,x5;

sbit RS=P1^6;
sbit E =P1^4;
sbit RW=P1^5;

sbit CLK=P1^2;
sbit Data=P1^1;
sbit CS=P1^3;

sbit CHG=P3^0;

int readADC(char n)
{
int k;
char i,channel;
k=0;

CS=0;

if(n==0) channel= 0x0d;
else channel=0x0f;

for (i=0;i<4;i++)
{
CLK = 0;

if(channel&8) Data =1;
else Data = 0;
CLK =1;
channel <<=1;
}

Data = 1;
CLK =0;

for(i=0; i<12;i++)
{
k<<=1;
CLK =1;
CLK=0;
if(Data) k|=1;
else k &=~1;
}
CS =1;

return k&=0xfff;
}


void timer0int(void) interrupt 1 using 1

{
TH0 |=0xdc;
cputick++;
}


pause(int j)
{ int i;
for (i=0;i<j;i++)
continue;
}


pulesE()
{
E =1;
;
E =0;
}


void delay(int m)
{
int j;
for(j=0;j<=m;j++)
continue;
}

LCDWI (char n)
{
RW =0;
RS=0;
E =0;
P0=n;
E =1;
E =0;
pause(50);
}


LCDWD(char n)
{
RW=0;
RS=1;
E=0;
P0=n;
E=1;
E=0;
pause(50);
}

print_LCD(char a,char *s)
{
LCDWI(a);
while(*s != 0)
LCDWD(*s++);
}


i_LCD()
{
RS=0;
E=0;
P0=0x30;pulesE();delay(10);pulesE();delay(1);pulesE();delay(1);
P0=0x20;pulesE();pulesE();pulesE();
LCDWI(0x38);
LCDWI(0x0c);
LCDWI(0x06);
LCDWI(1);
delay(50);
}

print_ADC()
{
char buffer[20];
if(++timer3<50)
{
timer3=0;
sprintf(buffer,"%0.1fC %0.1fF",read_temp1_filter(),read_temp1_filter()*9/5+32);
print_LCD(0xc0,buffer);
}
}

int low_pass_filter1(void)
{
x5=x4;
x4=x3;
x3=x2;
x2=x1;
x1=readADC(0);
return(x1+x2+x3+x4+x5)/5;
}

float read_temp1_filter(void)
{
return(0.0323*low_pass_filter1()-15.615);
}


void main()
{
i_LCD();
print_LCD(0x80,"LCD Thermometer");
TMOD |= 0x01;
TR0 = 1;
cputick = 0;
EA = 1;
ET0 = 1;

for(;;)
{
while(!TF0)
continue;
TF0=0;
print_ADC();
}
}


See More: I need Help explaining a C program

Report •


#1
January 23, 2009 at 13:34:49
I don't do C either, but here's a link that may help you.

http://www.le.ac.uk/cc/tutorials/c/

Here's another that deals with C and C++

http://www.cprogramming.com/tutoria...

Good luck


Report •

#2
January 25, 2009 at 00:27:26
Without any sort of context, I'd say this code displays a temperature in both Celsius and Fahrenheit on some LCD screen whenever TFO (which I assume is some sort of registrar) is not 0.

What exactly do you need help with?


Report •

#3
January 25, 2009 at 09:19:58
I need help explaining this program, its functions and declarations.
I took C++ but we never actually learned anything like this, and I need this program :S:S
I would be more than grateful if you could help me. Thanks

Report •

Related Solutions

#4
January 26, 2009 at 03:35:50
If you knew C++ thoroughly, you would already know C.

The code you posted includes a header that is not part of standard C. It is part of some real-time system or third-party library. You will need to read this library's/system's user manual in order to understand what its functions do.

If you know C++ you should already fully understand what the bitwise arithmetic operators &, &= and ^ do.


Report •


Ask Question