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

📄 x9241.h

📁 数控电位器x9241在软核处理器nios上的底层驱动程序
💻 H
字号:
#include "excalibur.h"

#define	ADDRTC	0x50	
typedef  unsigned char	uchar;

np_pio *x9241_scl=na_x9241_scl;
np_pio *x9241_sda=na_x9241_sda;

void delayx9241()
{
	unsigned int i;
    for(i=0;i<1;i++);

}
void initialx9241()
{
	x9241_sda->np_piodirection=1;
	}
void start()
{
//x9241_scl->np_piodata=0;
//delayx9241();
x9241_sda->np_piodata=1;
x9241_scl->np_piodata=1;
//delayx9241();
x9241_sda->np_piodata=0;
//delayx9241();
//x9241_scl->np_piodata=0;
}
void stop()
{
//x9241_scl->np_piodata=0;
//delayx9241();
x9241_sda->np_piodata=0;
x9241_scl->np_piodata=1;
//delayx9241();
x9241_sda->np_piodata=1;
}
void send(unsigned char dat)
{
unsigned int i;
   for(i=0;i<8;i++)
   {
   delayx9241();
   x9241_scl->np_piodata=0;
   x9241_sda->np_piodata=(dat&0x80)>>7;
   dat=dat<<1;
   delayx9241();
   x9241_scl->np_piodata=1;
   }
    ack();
}
void ack()
{
x9241_scl->np_piodata=0;
//delayx9241();
x9241_sda->np_piodata=0;
x9241_scl->np_piodata=1;
delayx9241();
x9241_scl->np_piodata=0;
}
void wrWCR(unsigned char Rx,unsigned char Vw)//Rx为0,1,2,3,Vw最大为0x3f
{
start();
send(0x50);
send(0xa0|((Rx*4)&0x0c));
send(0x3f&Vw);//Vw<=00111111
stop();
}
void wrDR(unsigned char Rx,unsigned char Vw)
{
start();
send(0x50);
send(0xc0|((Rx*4)&0x0c));
send(0x3f&Vw);
stop();
nr_delay(3);
}

⌨️ 快捷键说明

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