標(biāo)題: 新手請(qǐng)教 利用中斷定時(shí)器來加速步進(jìn)電機(jī) [打印本頁]

作者: cisforcer    時(shí)間: 2012-11-9 23:17
標(biāo)題: 新手請(qǐng)教 利用中斷定時(shí)器來加速步進(jìn)電機(jī)

對(duì)中斷定時(shí)器一知半解, 抄襲了下面的程序, 怎么修改成能夠修改成加速步進(jìn)電機(jī)

 

#include <reg52.h>

 unsigned char code F_Rotation[]={0x01,0x05,0x04,0x06,0x02,0x0a,0x08,0x09}; 

 main()

   TMOD |=0x01;   //定時(shí)器設(shè)置 1ms in 12M crystal
   IE= 0x82;        //打開中斷     
   ET0 = 1;
   TR0=1;
   while(1)
   {  
      
   }
}
 void Timer0(void) interrupt 1 using 1
{
   static unsigned char Cnt;

   TH0=(65536-55000)/256;
   TL0=(65536-55000)%256;
  
   if(Cnt<8)   Cnt++;
   else      Cnt=0;
   P3=F_Rotation[Cnt];  
 }


作者: 青蘋果    時(shí)間: 2012-11-10 10:14

1、修改定時(shí)器的時(shí)間

 

 void Timer0(void) interrupt 1 using 1
{
   static unsigned char Cnt;

   TH0=(65536-55000)/256;
   TL0=(65536-55000)%256;
  
   if(Cnt<8)   Cnt++;
   else      Cnt=0;
   P3=F_Rotation[Cnt];  
 }


作者: 青蘋果    時(shí)間: 2012-11-10 10:16

2、修改那個(gè)8

 

 void Timer0(void) interrupt 1 using 1
{
   static unsigned char Cnt;

   TH0=(65536-55000)/256;
   TL0=(65536-55000)%256;
  
   if(Cnt<8)   Cnt++;
   else      Cnt=0;
   P3=F_Rotation[Cnt];  
 }


作者: 青蘋果    時(shí)間: 2012-11-10 10:18

你上你可以測(cè)試一下如果可以那最好

 

我個(gè)人不用C

 

不過感覺下面這個(gè)地方是不是要加上大括號(hào)?

 

  if(Cnt<8)   Cnt++;
   else   

  

 Cnt=0;
   P3=F_Rotation[Cnt];  


作者: cisforcer    時(shí)間: 2012-11-16 18:43
  這個(gè)是取步進(jìn)電機(jī) 4根信號(hào)線的數(shù)組的   不能修改的
以下是引用青蘋果在2012-11-10 10:16:05的發(fā)言:

2、修改那個(gè)8

 

 void Timer0(void) interrupt 1 using 1
{
   static unsigned char Cnt;

   TH0=(65536-55000)/256;
   TL0=(65536-55000)%256;
  
   if(Cnt<8)   Cnt++;
   else      Cnt=0;
   P3=F_Rotation[Cnt];  
 }


作者: cisforcer    時(shí)間: 2012-11-16 18:44
不加大括號(hào)的 如果CNT 小于8 則 cnt++ ,P0取數(shù)組CNT 否則 CNT等于0
以下是引用青蘋果在2012-11-10 10:18:41的發(fā)言:

你上你可以測(cè)試一下如果可以那最好

 

我個(gè)人不用C

 

不過感覺下面這個(gè)地方是不是要加上大括號(hào)?

 

  if(Cnt<8)   Cnt++;
   else   

  

 Cnt=0;
   P3=F_Rotation[Cnt];  


作者: cisforcer    時(shí)間: 2012-11-16 18:46
修改這個(gè)數(shù)值諾 感覺應(yīng)該是對(duì)的
以下是引用青蘋果在2012-11-10 10:14:24的發(fā)言:

1、修改定時(shí)器的時(shí)間

 

 void Timer0(void) interrupt 1 using 1
{
   static unsigned char Cnt;

   TH0=(65536-55000)/256;
   TL0=(65536-55000)%256;
  
   if(Cnt<8)   Cnt++;
   else      Cnt=0;
   P3=F_Rotation[Cnt];  
 }


作者: ahshmj    時(shí)間: 2012-11-16 22:19
以下是引用cisforcer在2012-11-16 18:44:59的發(fā)言:
以下是引用青蘋果在2012-11-10 10:18:41的發(fā)言:

你上你可以測(cè)試一下如果可以那最好

 

我個(gè)人不用C

 

不過感覺下面這個(gè)地方是不是要加上大括號(hào)?

 

  if(Cnt<8)   Cnt++;
   else   

  

 Cnt=0;
   P3=F_Rotation[Cnt];  

不用C?用什么?匯編?






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1