共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网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
vscode+cmake搭建雅特力AT32L021开发环境被打赏30分 | |
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 |