microcontroller programs (electronics)




 1)stepper motar using 8051 Microcontroller using "C"-


 #include<reg52.h>

#define phase_a 0x0A

#define phase_b 0x06

#define phase_c 0x05

#define phase_d 0x09


sbit EN=P0^0;

 void delay(int cnt);

 void delay(int cnt)

 {

int i,j;

  for(i=0;i<cnt;i++)

      for(j=0;j<100;j++);

 }

  void clockwise(void);

   void clockwise(void)

{

P1=phase_a;

   delay(1000);

P1=phase_b;

   delay(1000);

  P1=phase_c;

   delay(1000);

P1=phase_d;

   delay(1000);

}

void main(void)

{

EN=1;

while(1)

{

  clockwise();

}

}

2) Sin Waveform generation using DAC interface to microcontroller-

 //sin waveform generation using DAC interface to 8051 Microcontroller

#include<reg51.h>

 main()

  {

static int a[13]={128,192,238,255,238,192,128,64,17,0,17,64,128};

//calculate value of sin wave formula

unsigned char i=0;

P3=0x00;     //initialization port 3

while(1)

{

for(i=0;i<13;i++)

  {

P3=a[i];     //send all value to port 3

}

}

}


3)Interfacing of thumbwheel & seven segment display to 8051 microcontroller-

#include<reg51.h>

 int main ()

 {

unsigned char s[]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67},wheel1,wheel2;

P2=0;

P3=0;

P1=255;

P2=255;

P3=255;

  while(1)

{

wheel1=P1&0x0f;

wheel2=(P1&0xf0)>>4;

P2=~s[wheel1];

P3=~s[wheel2];

}


4) Interfacing LCD to 8051 Microcontroller-

//interfacing lcd to 8051 microcontroller

#include<reg52.h>         

#define display_port P0

 sbit rs=P3^2;

 sbit rw=P3^3;

 sbit e=P3^4;

   void msdelay (unsigned int time)

{

unsigned i,j;

for(i=0;i<time;i++)

  for(j=0;j<1275;j++);

}

void lcd_cmd(unsigned char command)

{

display_port=command;

rs=0;

rw=0;

e=1;

     msdelay(1);

     e=0;

}

  void lcd_data(unsigned char disp_data)

{

     display_port=disp_data;

      rs=1;

      rw=0;

      e=1;

      msdelay(1);

      e=0;

  }

   void lcd_init()  

{

lcd_cmd(0x38);

        msdelay(10);

     lcd_cmd(0x0f);

         msdelay(10); 

    lcd_cmd(0x01);

          msdelay(10);

   lcd_cmd(0x81);

           msdelay(10);

}

  void main ()

{

unsigned char a[6]="VPASC";

int l=0;

lcd_init();

while(a[l]!=0)

{

lcd_data(a[1]);

l++;

msdelay(50);

}

}

   

   



5)Arithmetic ,logical & code conversion problems using assembly language programming-


    ORG 0

CLR A

MOV DPTR,#200H

MOVC A,@A+DPTR

MOV R2,A

INC DPTR

CLR A

MOVC A,@A+DPTR

MOV 05,A

DEC R2

CLR A

CLR C

J3:INC DPTR

  MOVC A,@A+DPTR

  CJNE A,05H,J1

  J1:JNC J2;  LARGEST

  //J1:JC J2;SMALLEST

  SJMP J4

  DJNZ R2,J3

  MOV R1,05H

  HERE:SJMP HERE 

  ORG 200H

  DB 10,43h,21h,88h,35h,98h,67h,18h,50h,19h

  end

Comments

Popular posts from this blog

Practical slips programs : Machine Learning

Full Stack Developement Practical Slips Programs

Android App Developement Practicals Programs