这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » max3100,xiexie 那位兄台为下面max3100加注释,xiexie

共2条 1/1 1 跳转至

max3100,xiexie 那位兄台为下面max3100加注释,xiexie

院士
2006-09-17 18:14:16     打赏
max3100,xiexie 那位兄台为下面max3100加注释,xiexie



关键词: max3100     xiexie     那位     兄台     下面         

院士
2006-12-22 22:43:00     打赏
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;

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 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]