SYBSCIT Embedded System Practical's code.
Practical 1
#include<reg51.h>
void main (void)
{
unsigned char x,y,z;
x=0x34;
y=0xa9;
P1=0x00;
z=x+y;
P1=z;
}
Practical 2a
| #include<reg51.H> | ||
| void Delay(void); | ||
| void main(void) | ||
| { | ||
| while(1) | ||
| { | ||
| P1 = 0xFF; // Make all bits of P1 high | ||
| Delay(); | ||
| P1 = 0x00; // Make all bits of P1 low | ||
| Delay(); | ||
| } | ||
| } | ||
| void Delay(void) | ||
| { | ||
| int j; | ||
| int i; | ||
| for(i = 0; i < 1000; i++) | ||
| { | ||
| } | ||
| for(j = 0; j < 1000; j++) | ||
| { | ||
| } | ||
| } |
Practical 2b
#include<reg51.h>
void main(void)
{
unsigned char x;
P2=0x7F;
P3=0x00;
while(1)
{
x=P2;
P3=x;
}
}
Practical 3a
| #include<reg51.h> | |
| void delay(int time); | |
| void main() | |
| { | |
| P1 = 00000000; | |
| while(1) | |
| { | |
| P1++; | |
| delay(100); | |
| } | |
| } | |
| void delay(int time) | |
| { | |
| int i, j; | |
| for(i = 0; i <= time; i++) | |
| { | |
| for(j = 0; j <= 23; j++) | |
| { | |
| } | |
| } | |
| } |
Practical 3b
| #include<reg51.h> | |
| void delay(); | |
| void main() | |
| { | |
| while(1) | |
| { | |
| P1 = 0xAA; // Pattern to turn on alternate LEDs - 10101010 | |
| delay(); | |
| P1 = 0x55; // Reverse the pattern | |
| delay(); | |
| } | |
| } | |
| void delay() | |
| { | |
| unsigned int i, j; | |
| for(i = 0; i < 24; i++) | |
| { | |
| for(j = 0; j < 1000; j++) | |
| { | |
| } | |
| } | |
| } |
Practical 4a
| #include<reg51.h> | |
| void send(char x); | |
| void main(void) | |
| { | |
| TMOD = 0x20; | |
| TH1 = 0xFD; | |
| SCON = 0x50; | |
| TR1 = 1; | |
| send('E'); | |
| send('M'); | |
| send('B'); | |
| send('E'); | |
| send('D'); | |
| send('D'); | |
| send('E'); | |
| send('D'); | |
| while(1); | |
| } | |
| void send(char x) | |
| { | |
| SBUF = x; | |
| while(TI == 0); | |
| TI = 0; | |
| } |
Practical 4b
| #include<reg51.h> | |
| void delay(unsigned int ms) | |
| { | |
| unsigned int i, j; | |
| for(i = 0; i<ms; i++) | |
| { | |
| for(j = 0; j<=1275; j++) | |
| { | |
| } | |
| } | |
| } | |
| void main(void) | |
| { | |
| char number[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; | |
| int i, j; | |
| P2 = 0x00; | |
| P3 = 0x00; | |
| while(1) | |
| { | |
| for(i = 0; i<=9; i++) | |
| { | |
| P2 = number[i]; | |
| for(j = 0; j<=9; j++) | |
| { | |
| P3 = number[j]; | |
| delay(50); | |
| } | |
| } | |
| } | |
| } |
Practical 4c ( square wave)
| #include<reg51.h> | |
| void delay(); | |
| void main() | |
| { | |
| P2 = 0x00; | |
| while(1) | |
| { | |
| P2 = 0xFF; | |
| delay(); | |
| P2 = 0x00; | |
| delay(); | |
| } | |
| } | |
| void delay() | |
| { | |
| int i; | |
| for(i = 0; i <= 5000; i++) | |
| { | |
| } | |
| } |
Practical 5a ( triangular wave)
| #include<reg51.h> | |
| void main() | |
| { | |
| P2= 0x00; | |
| while(1) | |
| { | |
| do | |
| { | |
| P2 += 0x05; | |
| } | |
| while(P2 < 0xFF); | |
| do | |
| { | |
| P2 -= 0x05; | |
| } | |
| while(P2 > 0x00); | |
| } | |
| } |
Practical 5b
| #include<reg51.h> | |
| #include<stdio.h> | |
| int sine[]={0,0,5,10,5,15,20,25,30,35,40,45,45,40,35,30,25,20,15,10,5,0,0}; | |
| void main() | |
| { | |
| int i; | |
| P1=0x00; | |
| while(1) | |
| { | |
| for(i=0;i<23;i++) | |
| { | |
| P1=sine[i]; | |
| } | |
| } | |
| } |
Practical 6
#include<reg51.h>
#include<stdio.h>
void delay(int);
void main()
{
do
{
P2 = 0x03; //0011
delay(5000);
P2 = 0x06; //0110
delay(5000);
P2 = 0x0C; //1100
delay(5000);
P2 = 0x09; //1001
delay(5000);
P3 = 0x09; //1001
delay(2000);
P3 = 0x0C; //1100
delay(2000);
P3 = 0x06; //0110
delay(2000);
P3 = 0x03; //0011
delay(2000);
}
while(1);
}
void delay(int k)
{
int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<100;j++)
{}
}
}

Comments
Post a Comment