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

📄 dio.c

📁 老外开发的机器人的底层单片机代码。比较有参考价值哦!
💻 C
字号:
//Discrete I/O handler   DIO.c					// Rev 9/1/05

//Copyright (C) 2005 Alex Brown	rbirac@cox.net
//This program is free software; See license at the end of this file for details.

/*												
  	  DIO.c initializes the DIO ports for input or output as specific by config
	  download.  It also reads or writes data from/to the DIO ports. 
	  
	  DIO0 = PORTM bits 0-3, DIO1 = PORTM 4-7, DIO2 = PORTK 0-3 
*/

 #include <hcs12dp256.h>		    //for registers

 int DIOcfg;	  //bits 0-11 define whether DIO pins are input (0) or output (1)
 	 			  // 0-3 = DIO0, 4-7 = DIO1, 8-11 = DIO2
 int DIOdata;	  //read of DIO ports
 				  
 void DIOinit(void)
 {
  	DDRM  =   DIOcfg & 0xFF;    //set DIO0 & DIO1 directions
	DDRK  =   (DDRK & 0xF0)|(DIOcfg>>8 & 0x0F);
 }
 
 void DIOset(int DIOcmd)			   //set bits as input or output
 {
 	  PTM  =   DIOcmd & 0xFF;
	  PORTK = (PORTK & 0xF0) | (DIOcmd>>8 & 0x0F);
 }
 
 void DIOread(void)	   		   		   //read port status
 {
 	  DIOdata = (PORTK & 0x0F)<<8 | (PTM & 0xFF);
 }
 
//  OPEN SOURCE SOFTWARE LICENSE
/* Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to use, 
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 
Software, and to permit persons to whom the Software is furnished to do so, 
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all 
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ 

⌨️ 快捷键说明

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