Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

keil code

Status
Not open for further replies.

fvm

Member
Code:
#include <REGX51.H>
 unsigned long ref_speed,read_counter, error, kp, t,dc,Ton;
 sbit outbit=P1^0;
 sbit inbit=P3^4;
 char i;
  main()
 {
  TMOD=0x15;
  IE=0x88;   //Enable timer 1 interrupt
  kp=1;
  t=100;
  ref_speed=800;
  TH1=255;
 TL1=240;
 TR1=1;
 inbit=0; 
while (1)
{
error=0;
TH0=0;
TL0=0;
TR0=1;
for ( i=0;i<10;i++);
TR0=0;
read_counter=TL0;
TR0=1;
error=ref_speed -( read_counter );
read_counter=read_counter*1000/15;
error=kp*error;
dc=50+error;
if (dc>=90)
dc=90;
else if(dc<=10)
dc=10;
else
;
Ton=(dc*100);

}
}

 void t1isr(void) interrupt 3
 {
 TR1=0;
 if (outbit==0)
 {outbit=!outbit;
 TH1=255;
 TL1=255-Ton;
 TR1=1;
 }
 else 
 {outbit=!outbit;
 TH1=255;
 TL1=255-(100-Ton);
 TR1=1;
 }
 }
 
Status
Not open for further replies.

Latest threads

Back
Top