新手入门
- 积分
- 18
- 金钱
- 18
- 注册时间
- 2019-5-10
- 在线时间
- 5 小时
|
#include"reg52.h"
#define uchar unsigned char
#define uint unsigned int
uchar step_n[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};
uchar step_s[8]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};
uint t=180;
uchar i;
uint j;
void delay(uint a)
{
while(a--);
}
void motor_n()
{
while(j--)
{
for(i=0;i<8;i++)
{
P0=step_n[i];
delay(t);
}
}
while(1);
}
void uart_init() //????????????
{
TMOD=0x20; //???ü????????????2
TH1=0xF3; //????????????????????????4800
TL1=0xF3;
PCON=0x80; //????????
TR1=1; //????????
SCON=0x50; //????????????1
ES=1; //???????ж?
EA=1; //?????ж?
}
void uart() interrupt 4
{
uchar receiveData;
j=SBUF;
//P0=0X00;
while(j--)
{
motor_n();
}
receiveData=SBUF; //??????????????
RI=0; //????????ж???λ
SBUF=receiveData; //????????????????????????
while(!TI); //??????????????
TI=0; //????????????λ
}
void main()
{
uart_init();
while(1);
}
|
|