⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpub.h

📁 scara机器人的一种简单的实现方法
💻 H
字号:
#include  "mpu_def.h"

extern void   RS_PORT_INIT(void);
extern int    RS_SEND(int byte_data);
extern struct read_data RS_RECEIVE(void);

/*  initialize serial port */
void RS_PORT_INIT(void)
{
   outportb(0x02FB, 0x80);
   outportb(0x02F8, 0x0C);
   outportb(0x02F9, 0x00);
   outportb(0x02FB, 0x07);
   outportb(0x02FC, 0x03);
   outportb(0x02F9, 0x00);

   return;
}

/* send 1 byte and verify RS-232C */
int RS_SEND(int byte_data)
{
   int data, time = 1;
   int RS_ERR;
   char ch;

   RS_ERR = TRUE;
   outport(0x02F8, byte_data);   // output 'byte_data'
   for(;;) {
     ch = inportb(0x02fd);       // check read port ready
     ch &= (0x01);
     if (ch!=0) {
       data = inport(0x02F8);    // read and verify
       if (data!=byte_data) {
	 outport(0x02F8, byte_data);
	 time++;
	 if (time>=5) { RS_ERR = FALSE; break; }
       }
       else break;
   }}

   return RS_ERR;
}

/* receive 1 byte and send back */
struct read_data RS_RECEIVE(void)
{
   struct read_data data;
   char ch, time = 0;

   for(;;) {
     ch = inportb(0x02fd);       // check read port ready
     ch &= (0x01);
     if (ch!=0) {
       data.d = inport(0x02F8);    // read port
       outport(0x02F8, data.d);
       time++;
//       delay(10);
     }
     else if (time>=5) {
       data.flag = FALSE;
       break;
     }
     else if (time>0 && time<5) {
       data.flag = TRUE;
       break;
     }
   }

   return data;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -