AT89C2051驅動步進電機的電路和源碼:AT89C2051驅動步進電機的電路和源碼 程序:stepper.c stepper.hex/* * STEPPER.C * sweeping stepper's rotor cw and cww 400 steps * Copyright (c) 1999 by W.Sirichote */#i nclude c:\mc5151io.h /* include i/o header file */ #i nclude c:\mc5151reg.hregister unsigned char j,flag1,temp; register unsigned int cw_n,ccw_n;unsigned char step[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90} #define n 400/* flag1 mask byte 0x01 run cw() 0x02 run ccw() */main(){ flag1=0; serinit(9600); disable(); /* no need timer interrupt */ cw_n = n; /* initial step number for cw */ flag1 |=0x01; /* initial enable cw() */while(1){ { tick_wait(); /* wait for 10ms elapsed */energize(); /* round-robin execution the following tasks every 10ms */ cw(); ccw(); } }}cw(){ if((flag1&0x01)!=0) { cw_n--; /* decrement cw step number */ if (cw_n !=0) j++; /* if not zero increment index j */ else {flag1&=~0x01; /* disable cw() execution */ ccw_n = n; /* RELOAD step number to ccw counter */ flag1 |=0x02; /* enable cww() execution */ } }
標簽:
C2051
2051
89C
AT
上傳時間:
2013-11-21
上傳用戶:boyaboy
PC與單片機雙向通訊智能溫控程序
#include <AT89X51.H>
#include <intrins.h>
#define Key_UP P1_0
#define Key_DOWN P1_1
#define Key_SET P1_2
#define RelayOutPort P2_0
#define LEDPort P0
#define DELPort P2_1
#define LEDTwoC P3_6
#define LEDThreeC P3_7
#define TMPort P2_7
#define INBUF_LEN 5 //數據長度
unsigned char inbuf1[INBUF_LEN]={ 0 , 0 , 0 , 0 , 0 } //發送緩沖區
unsigned char inbuf2[50] //接收緩沖區
unsigned char count3
void init_serialcomm( void )
{
SCON = 0x50 //SCON: serail mode 1, 8-bit UART, enable ucvr
TMOD |= 0x20 //TMOD: timer 1, mode 2, 8-bit RELOAD
PCON |= 0x80 //SMOD=1
TH1 = 0xFA //Baud:4800 fosc=11.0592MHz
IE |= 0x90 //Enable Serial Interrupt
TR1 = 1 // timer 1 run
}
//向串口發送一個字符
void send_char_com( unsigned char ch)
{
SBUF=ch
while (TI== 0 )
TI= 0
標簽:
include
intrins
define
Key_UP
上傳時間:
2014-11-29
上傳用戶:風之驕子