共2条
1/1 1 跳转至页
max3100,xiexie 那位兄台为下面max3100加注释,xiexie
问
define uchar unsigned char
#define uint unsigned int
#define FOSC 11059200ul
#define BAUD 9600
#define SMODX 0
#define TH1_VAL (256 - (uchar)(FOSC * (1<<SMODX) * 1.0 / 384 / BAUD))
#define TL1_VAL TH1_VAL
sbit DIN =P1^3;
sbit DOUT =P1^2;
sbit SCLK =P1^1;
sbit CS =P1^0;
void Delayus(uchar t)
{
for(; t>0; t--)
;
}
uchar Byte3100(uchar dat) reentrant
{
uchar i;
DOUT = 1;
DIN = 1;
for(i=0; i<8; i++)
{
if(dat & 0x80)
DIN = 1;
else
DIN = 0;
SCLK = 1;
dat <<= 1;
dat |= DOUT;
SCLK = 0;
}
return dat;
}
uchar Send3100(uchar tx1,uchar tx2) reentrant
{
CS = 0;
Byte3100(tx1);
tx1 = Byte3100(tx2);
CS = 1;
return tx1;
}
void Init3100(void)
{
uchar dat,i=0;
do
{
Send3100(0xc4,0x0a); //0b:4800,0a:9600
Delayus(200);
dat = Send3100(0x40,0x00);
}while((dat!= 0x01)&&(++i<5));
Send3100(0x84,0x00);
Delayus(200);
}
答 1: REdefine uchar unsigned char
#define uint unsigned int
///////#define FOSC 11059200ul
///////#define BAUD 9600
///////#define SMODX 0
///////#define TH1_VAL (256 - (uchar)(FOSC * (1<<SMODX) * 1.0 / 384 / BAUD))
///////#define TL1_VAL TH1_VAL
sbit DIN =P1^3; //
sbit DOUT =P1^2;
sbit SCLK =P1^1;
sbit CS =P1^0;
//IRQ----接P3.2(INT0)
//非精确延时
void Delayus(uchar t)
{
for(; t>0; t--)
;
}
//发送字节子程序
uchar Byte3100(uchar dat) reentrant //中断里调用,可重入函数
{
uchar i;
DOUT = 1;
DIN = 1;
for(i=0; i<8; i++)
{
if(dat & 0x80) //在写命令/数据的时候
DIN = 1; //
else //
DIN = 0; //
SCLK = 1; //
dat <<= 1; //
dat |= DOUT; //读数据
SCLK = 0;
}
return dat;
}
//发送程序,分2个字节,你也可用uint型的,DIN写命令/数据的同时,DOUT输出数据
uchar Send3100(uchar tx1,uchar tx2) reentrant
{
CS = 0;
Byte3100(tx1);
tx1 = Byte3100(tx2);
CS = 1;
return tx1;
}
//3100初始化
void Init3100(void)
{
uchar dat,i=0;
do
{
Send3100(0xc4,0x0a); //写配置字0xc40a, fifo使能,/IRO使能 ,9600bps
Delayus(200); //必须有延时
dat = Send3100(0x40,0x00); //读配置字
}while((dat!= 0x01)&&(++i<5)); //不成功则配置5次,确保可靠配置,dat!=0x01(57.6kbps)是错误的,是测试时用的,能跑到576000,
//应该是0x0a(9600bps)
Send3100(0x84,0x00); //写数据,配置端口方等
Delayus(200); //必需有延时
}
////////void ExtInt0() interrupt 0 using 1
////////{//外部中断0
//////// uchar recdata;
////////
//////// recdata = Send3100(0x00,0x00); //IRQ中断,读数据
//////// TF0 = 0;
//////// //...
////////}
////////void InitDevice(void)
////////{
//////// SCON = 0x50; //串口方式1,允许接收
//////// TMOD = 0x22; //T1方式2:波特率发生器,T0方式2
//////// if (SMODX)
//////// PCON|=0x80; //根据预处理信息设置SMOD位)
////////
//////// TH1=TH1_VAL; //波特率设定值由编译预处理信息确定
//////// TL1=TL1_VAL;
//////// TR1 = 1; //启动定时器1
////////
//////// EX0 = 1; //INT0开
//////// ES = 1;// 开串口中断
////////
//////// LED = 0;
////////
//////// Init3100();
////////
//////// EA = 1; //开中断
////////}
////////
////////void main(void)
////////{
//////// uchar i;
////////
//////// InitDevice();
////////
//////// for(;;)
//////// {
//////// for(i=0; i<Rec3100Count; i++)
//////// {
//////// Send3100(0x82,Rec3100Buf[i]);
//////// Delayus(200);
//////// }
//////// Send3100(0x84,0x00);
////////
//////// Rec3100Finish = 0;
//////// Rec3100Count = 0;
//////// LED = 0;
答 2: 路过define uchar unsigned char
#define uint unsigned int
///////#define FOSC 11059200ul
///////#define BAUD 9600
///////#define SMODX 0
///////#define TH1_VAL (256 - (uchar)(FOSC * (1<<SMODX) * 1.0 / 384 / BAUD))
///////#define TL1_VAL TH1_VAL
sbit DIN =P1^3; //
sbit DOUT =P1^2;
sbit SCLK =P1^1;
sbit CS =P1^0;
//IRQ----接P3.2(INT0)
//非精确延时
void Delayus(uchar t)
{
for(; t>0; t--)
;
}
//发送字节子程序
uchar Byte3100(uchar dat) reentrant //中断里调用,可重入函数
{
uchar i;
DOUT = 1;
DIN = 1;
for(i=0; i<8; i++)
{
if(dat & 0x80) /*判断最高位是否为1*/
DIN = 1; /*如果最高位为1,DIN置1*/
else /*否则DIN置0
DIN = 0; */
SCLK = 1; /*时钟上升沿有效*/
dat <<= 1; /*将数据左移一位*/
dat |= DOUT; //读数据
SCLK = 0;
}
return dat;
}
//发送程序,分2个字节,你也可用uint型的,DIN写命令/数据的同时,DOUT输出数据
uchar Send3100(uchar tx1,uchar tx2) reentrant
{
CS = 0;
Byte3100(tx1);
tx1 = Byte3100(tx2);
CS = 1;
return tx1;
}
//3100初始化
void Init3100(void)
{
uchar dat,i=0;
do
{
Send3100(0xc4,0x0a); //写配置字0xc40a, fifo使能,/IRO使能 ,9600bps
Delayus(200); //必须有延时
dat = Send3100(0x40,0x00); //读配置字
}while((dat!= 0x01)&&(++i<5)); //不成功则配置5次,确保可靠配置,dat!=0x01(57.6kbps)是错误的,是测试时用的,能跑到576000,
//应该是0x0a(9600bps)
Send3100(0x84,0x00); //写数据,配置端口方等
Delayus(200); //必需有延时
}
////////void ExtInt0() interrupt 0 using 1
////////{//外部中断0
//////// uchar recdata;
////////
//////// recdata = Send3100(0x00,0x00); //IRQ中断,读数据
//////// TF0 = 0;
//////// //...
////////}
////////void InitDevice(void)
////////{
//////// SCON = 0x50; //串口方式1,允许接收
//////// TMOD = 0x22; //T1方式2:波特率发生器,T0方式2
//////// if (SMODX)
//////// PCON|=0x80; //根据预处理信息设置SMOD位)
////////
//////// TH1=TH1_VAL; //波特率设定值由编译预处理信息确定
//////// TL1=TL1_VAL;
//////// TR1 = 1; //启动定时器1
////////
//////// EX0 = 1; //INT0开
//////// ES = 1;// 开串口中断
////////
//////// LED = 0;
////////
//////// Init3100();
////////
//////// EA = 1; //开中断
////////}
////////
////////void main(void)
////////{
//////// uchar i;
////////
//////// InitDevice();
////////
//////// for(;;)
//////// {
//////// for(i=0; i<Rec3100Count; i++)
//////// {
//////// Send3100(0x82,Rec3100Buf[i]);
//////// Delayus(200);
//////// }
//////// Send3100(0x84,0x00);
////////
//////// Rec3100Finish = 0;
//////// Rec3100Count = 0;
//////// LED = 0;
#define uint unsigned int
#define FOSC 11059200ul
#define BAUD 9600
#define SMODX 0
#define TH1_VAL (256 - (uchar)(FOSC * (1<<SMODX) * 1.0 / 384 / BAUD))
#define TL1_VAL TH1_VAL
sbit DIN =P1^3;
sbit DOUT =P1^2;
sbit SCLK =P1^1;
sbit CS =P1^0;
void Delayus(uchar t)
{
for(; t>0; t--)
;
}
uchar Byte3100(uchar dat) reentrant
{
uchar i;
DOUT = 1;
DIN = 1;
for(i=0; i<8; i++)
{
if(dat & 0x80)
DIN = 1;
else
DIN = 0;
SCLK = 1;
dat <<= 1;
dat |= DOUT;
SCLK = 0;
}
return dat;
}
uchar Send3100(uchar tx1,uchar tx2) reentrant
{
CS = 0;
Byte3100(tx1);
tx1 = Byte3100(tx2);
CS = 1;
return tx1;
}
void Init3100(void)
{
uchar dat,i=0;
do
{
Send3100(0xc4,0x0a); //0b:4800,0a:9600
Delayus(200);
dat = Send3100(0x40,0x00);
}while((dat!= 0x01)&&(++i<5));
Send3100(0x84,0x00);
Delayus(200);
}
答 1: REdefine uchar unsigned char
#define uint unsigned int
///////#define FOSC 11059200ul
///////#define BAUD 9600
///////#define SMODX 0
///////#define TH1_VAL (256 - (uchar)(FOSC * (1<<SMODX) * 1.0 / 384 / BAUD))
///////#define TL1_VAL TH1_VAL
sbit DIN =P1^3; //
sbit DOUT =P1^2;
sbit SCLK =P1^1;
sbit CS =P1^0;
//IRQ----接P3.2(INT0)
//非精确延时
void Delayus(uchar t)
{
for(; t>0; t--)
;
}
//发送字节子程序
uchar Byte3100(uchar dat) reentrant //中断里调用,可重入函数
{
uchar i;
DOUT = 1;
DIN = 1;
for(i=0; i<8; i++)
{
if(dat & 0x80) //在写命令/数据的时候
DIN = 1; //
else //
DIN = 0; //
SCLK = 1; //
dat <<= 1; //
dat |= DOUT; //读数据
SCLK = 0;
}
return dat;
}
//发送程序,分2个字节,你也可用uint型的,DIN写命令/数据的同时,DOUT输出数据
uchar Send3100(uchar tx1,uchar tx2) reentrant
{
CS = 0;
Byte3100(tx1);
tx1 = Byte3100(tx2);
CS = 1;
return tx1;
}
//3100初始化
void Init3100(void)
{
uchar dat,i=0;
do
{
Send3100(0xc4,0x0a); //写配置字0xc40a, fifo使能,/IRO使能 ,9600bps
Delayus(200); //必须有延时
dat = Send3100(0x40,0x00); //读配置字
}while((dat!= 0x01)&&(++i<5)); //不成功则配置5次,确保可靠配置,dat!=0x01(57.6kbps)是错误的,是测试时用的,能跑到576000,
//应该是0x0a(9600bps)
Send3100(0x84,0x00); //写数据,配置端口方等
Delayus(200); //必需有延时
}
////////void ExtInt0() interrupt 0 using 1
////////{//外部中断0
//////// uchar recdata;
////////
//////// recdata = Send3100(0x00,0x00); //IRQ中断,读数据
//////// TF0 = 0;
//////// //...
////////}
////////void InitDevice(void)
////////{
//////// SCON = 0x50; //串口方式1,允许接收
//////// TMOD = 0x22; //T1方式2:波特率发生器,T0方式2
//////// if (SMODX)
//////// PCON|=0x80; //根据预处理信息设置SMOD位)
////////
//////// TH1=TH1_VAL; //波特率设定值由编译预处理信息确定
//////// TL1=TL1_VAL;
//////// TR1 = 1; //启动定时器1
////////
//////// EX0 = 1; //INT0开
//////// ES = 1;// 开串口中断
////////
//////// LED = 0;
////////
//////// Init3100();
////////
//////// EA = 1; //开中断
////////}
////////
////////void main(void)
////////{
//////// uchar i;
////////
//////// InitDevice();
////////
//////// for(;;)
//////// {
//////// for(i=0; i<Rec3100Count; i++)
//////// {
//////// Send3100(0x82,Rec3100Buf[i]);
//////// Delayus(200);
//////// }
//////// Send3100(0x84,0x00);
////////
//////// Rec3100Finish = 0;
//////// Rec3100Count = 0;
//////// LED = 0;
答 2: 路过define uchar unsigned char
#define uint unsigned int
///////#define FOSC 11059200ul
///////#define BAUD 9600
///////#define SMODX 0
///////#define TH1_VAL (256 - (uchar)(FOSC * (1<<SMODX) * 1.0 / 384 / BAUD))
///////#define TL1_VAL TH1_VAL
sbit DIN =P1^3; //
sbit DOUT =P1^2;
sbit SCLK =P1^1;
sbit CS =P1^0;
//IRQ----接P3.2(INT0)
//非精确延时
void Delayus(uchar t)
{
for(; t>0; t--)
;
}
//发送字节子程序
uchar Byte3100(uchar dat) reentrant //中断里调用,可重入函数
{
uchar i;
DOUT = 1;
DIN = 1;
for(i=0; i<8; i++)
{
if(dat & 0x80) /*判断最高位是否为1*/
DIN = 1; /*如果最高位为1,DIN置1*/
else /*否则DIN置0
DIN = 0; */
SCLK = 1; /*时钟上升沿有效*/
dat <<= 1; /*将数据左移一位*/
dat |= DOUT; //读数据
SCLK = 0;
}
return dat;
}
//发送程序,分2个字节,你也可用uint型的,DIN写命令/数据的同时,DOUT输出数据
uchar Send3100(uchar tx1,uchar tx2) reentrant
{
CS = 0;
Byte3100(tx1);
tx1 = Byte3100(tx2);
CS = 1;
return tx1;
}
//3100初始化
void Init3100(void)
{
uchar dat,i=0;
do
{
Send3100(0xc4,0x0a); //写配置字0xc40a, fifo使能,/IRO使能 ,9600bps
Delayus(200); //必须有延时
dat = Send3100(0x40,0x00); //读配置字
}while((dat!= 0x01)&&(++i<5)); //不成功则配置5次,确保可靠配置,dat!=0x01(57.6kbps)是错误的,是测试时用的,能跑到576000,
//应该是0x0a(9600bps)
Send3100(0x84,0x00); //写数据,配置端口方等
Delayus(200); //必需有延时
}
////////void ExtInt0() interrupt 0 using 1
////////{//外部中断0
//////// uchar recdata;
////////
//////// recdata = Send3100(0x00,0x00); //IRQ中断,读数据
//////// TF0 = 0;
//////// //...
////////}
////////void InitDevice(void)
////////{
//////// SCON = 0x50; //串口方式1,允许接收
//////// TMOD = 0x22; //T1方式2:波特率发生器,T0方式2
//////// if (SMODX)
//////// PCON|=0x80; //根据预处理信息设置SMOD位)
////////
//////// TH1=TH1_VAL; //波特率设定值由编译预处理信息确定
//////// TL1=TL1_VAL;
//////// TR1 = 1; //启动定时器1
////////
//////// EX0 = 1; //INT0开
//////// ES = 1;// 开串口中断
////////
//////// LED = 0;
////////
//////// Init3100();
////////
//////// EA = 1; //开中断
////////}
////////
////////void main(void)
////////{
//////// uchar i;
////////
//////// InitDevice();
////////
//////// for(;;)
//////// {
//////// for(i=0; i<Rec3100Count; i++)
//////// {
//////// Send3100(0x82,Rec3100Buf[i]);
//////// Delayus(200);
//////// }
//////// Send3100(0x84,0x00);
////////
//////// Rec3100Finish = 0;
//////// Rec3100Count = 0;
//////// LED = 0;
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 | |
【FRDM-MCXN947评测】核间通信MUTEX被打赏50分 |