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.

Embedded c program for micro controller

Status
Not open for further replies.

pbkyew

Newbie level 4
Joined
Feb 1, 2011
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,318
HI Plz help me how to write a program for ADC0808 with 89s52
 

#include<reg51.h>
#include<intrins.h>
#include<stdio.h>

sbit rs=P3^6;
sbit en=P3^7;

sbit eoc=P2^1;
sbit soc=P2^0;

sbit cha=P2^2;
sbit chb=P2^3;
sbit chc=P2^4;

void cmdwrt();
void delay();
void datawrt();
void asc();
void valconv();

unsigned char dis[6]={0x30,0x38,0x08,0x0c,0x06,0x80};
unsigned char a,b,c,d;

main()
{
int i;
for( i=0;i<6;i++)
{
a=dis;
cmdwrt();
delay();
}
//select channel
cha=0;
chb=0;
chc=0;
while(1)
{
a=0x80;
cmdwrt();
delay();

eoc=0x01;
soc=0x00;
delay();

soc=0x01;
delay();
soc=0x00;

while(eoc); //wait for conversion
delay();
a=P1;
asc(); //display
delay();
}
}

void asc()
{
d=a;
a=a>>4;
a=a & (0x0f);
valconv(); //conv to ascii
datawrt(); //disp on LCD

a=d;
a=a & (0x0f);
valconv();
datawrt();
}


void valconv()
{
if(a <= (0x09))
{
a=a+ (0x30);
}
else
{
a=a+ (0x37);
}
}


void cmdwrt()
{
rs=0;
P0=a;
en=1;
delay();
en=0;
}

void datawrt()
{
rs=1;
P0=a;
en=1;
delay();
en=0;
}

void delay()
{
int i;
for(i=0;i<1000;i++);
}
 

#include <reg51.h>
#include "io.h"


sbit READ = P3^2; /* Define these according to how you have connected the */
sbit WRITE = P3^3;/* RD, WR, and INTR pins */
sbit INTR = P3^4;


void main( void ) {

unsigned char adVal;
unsigned long volts;
InitIO();

READ = 1;
WRITE = 1;
INTR = 1;
ClearScreen();

while(1) {

/* Make a low-to-high transition on the WR input */

while( INTR == 1 ); /* wait until the INTR signal makes */
/* high-to-low transition indicating */
/* completion of conversion */


/* Read the voltage value from the port */
READ = 0;
adVal = P1;
READ = 1;

/* Compute the digital value of the volatge read */

/* Print the value of the voltage in decimal form */
}
}
 

if you are new then i recommend you to read and understand the complete book and try yourself.... asking for ready code will not help you

refer this for any information

**broken link removed**
 

Hi,

Better to know all the interfacing part of micro controller & learn about the C language after that try to implement.

Regards
Chanchal
 

yes sir that was the mistake should be
#include<reg51.h>
#include<intrins.h>
#include<stdio.h>
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top