Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C by erg ( 9 years ago )
1(Buzzer wth timer)
#include "at89c51xd2.h"
#define offTime 20
#define onTime 20
sbit buzz=P0^5;
idata unsigned int i;
void main()
{
 TMOD=0X01;
 TL0=0;
 TH0=0XF8;
 TCON=0X00;
 TF0=0;
 while(1)
 {
  buzz=1;
  for(i=0;i<onTime TL0=0X00; TH0=0XF8; TR0=1; TF0=0; TR0=0; buzz=0; for(i=0;i TL0=0X00; TH0=0XF8; TR0=1; TF0=0; TR0=0; sw=1; led=0; led=1; led=0; SW=P3^0; xss=removed for(i=0;i xss=removed xss=removed buz=0x01; for(i=0;i buz=0x00; for(i=0;i array_dec[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; port_val[6]={0x00,0x10,0x20,0x30,0x40,0x50}; for(i=1;i i++)port_val[i]=port_val[i-1]+16; for(j=0;j P0=port_val[j]; for(i=0;i P1=array_dec[i]; P0=port_val[j]; for(i=0;i arr_dec[10]={0x3F, port_val[6]={0,16,32,48,64,80}; for(i=0;i for(j=0;j input=987654; arr[6]={0}; i=5; while(input!=0) arr[i]=input; input=input/10; for(i=0;i p0=port_val(i); p1=arr_dec(arr[i]); Dir=0; Dir=~Dir;>0;x--);
}
void main()
{
 unsigned char val,i;
 EA=0x04;
 EX1=0x10;
 while(1)
 {
  if(Dir)
  {
    val=0x08;
   for(i=0;i<4 P0=val; val=val>>1;
    delay(1);
   }
  }
  else
  {
    val=0x01;
    for(i=0;i<4 P0=val; val=val led=13; ch=Serial.read(); xss=removed xss=removed xss=removed xss=removed>
#include <SD>

File myFile;

void setup()
{
Serial.begin(9600);

Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);

if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
  }
Serial.println("initialization done.");


}

void loop()
{
charch;
ch=Serial.read();
if(ch=='w' || ch=='W')
    {
myFile = SD.open("test.txt",FILE_WRITE);

        if (myFile) 
       {
Serial.print("Writing to test.txt...");
myFile.println("India is our Country");
myFile.println("VIT is a Place to Learn");
myFile.println("VIT is a Place to Grow");
             // close the file:
myFile.close();
Serial.println("done.");
       }
else {
       // if the file didn't open, print an error:
Serial.println("error opening test.txt");
            }
    }
else if(ch=='r' || ch=='R')
  {
       // re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) 
       {
Serial.println("test.txt:");

       // read from the file until there's nothing else in it:
while (myFile.available()) 
       {
Serial.write(myFile.read());
        }
       // close the file:
myFile.close();
      } 
else {
  // if the file didn't open, print an error:
Serial.println("error opening test.txt");
     }
  }
}

9)LM35 sensor
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly: 
  int a =analogRead(0);
  Serial.print("Value:");
  Serial.println(a);
  delay(1000);
}

const int sensor=A1;
float tempc;
float tempf;
float vout;
void setup()
{
 pinMode(sensor,INPUT);
 Serial.begin(9600);
}
void loop()
{
 vout=analogRead(sensor);
 vout=(vout*1.8)/1023;
 tempc=vout;
 Serial.print("in DegreeC=");
 Serial.print("\t");
 Serial.print(tempc);
 Serial.println();
 delay(1000);
}


10)data logging
#include <SPI>
#include <SD>

File myFile;
int i=1;
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);

if (!SD.begin(4)) 
  {
Serial.println("initialization failed!");
return;
   }
Serial.println("initialization done.");
}

void loop()
{
    
char ch='w';
ch=Serial.read();
int val;
    val=analogRead(0);
if((ch=='w' || ch=='W'))
    {
myFile = SD.open("test1.txt",FILE_WRITE);
val=analogRead(0);
if (myFile) 
       {
Serial.print("Writing to test.txt...");
myFile.print(i);
myFile.print("                      ");
myFile.println(val);
myFile.close();
i++;
Serial.println("done.");
       }
else {
Serial.println("error opening test.txt");
            }
    }
else if(ch=='r' || ch=='R')
  {
myFile = SD.open("test1.txt");
if (myFile) 
       {
Serial.println("test1.txt:");
while (myFile.available()) 
       {
Serial.write(myFile.read());
        }
myFile.close();
      } 
else {
Serial.println("error opening test.txt");
     }
  }
}

 

Revise this Paste

Your Name: Code Language: