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

📄 16c554.txt

📁 并口扩4串口的程序
💻 TXT
📖 第 1 页 / 共 2 页
字号:

    con_port = con_leisure;   

       

    con_port |= MCR;               //MCR    

    con_port &= ~CSC;   

    con_port ^= WRITE_EN;   

    data_out_port = 0x0b;          //DTR~ = 0, RTS~ = 0    

    con_port = con_leisure;   

    low_power();   

}   

   

/************************************************************  

*  

* 名称:     send_data_554  

* 功能:     发送多个字节  

* 调用:     none  

* 输入:     Txdata[] 为要发送的数组;data_len为发送的字节数;  

*           select_IO为端口选择:0~3对应A口~D口  

* 返回值:   none  

*  

************************************************************/   

   

void send_data_554(unsigned char Txdata[],unsigned char data_len,unsigned char select_IO)   

{   

    unsigned char i,j;   

       

    data_port_dir = 0x0ff;                      //数据信号为输出    

    con_port |= THR;                            //选中发送寄存器    

       

    if(select_IO == 0 )                         //判断选中的端口    

        con_port &= ~CSA;                       //选中A口    

    else if(select_IO == 1)   

             con_port &= ~CSB;   

         else if(select_IO == 2)   

                  con_port &=~CSC;   

              else if(select_IO == 3)   

                       con_port &= ~CSD;   

                   else return;   

   

    for(i = 0; i < data_len; i++)   

    {   

        con_port ^= WRITE_EN;                   //写操作使能    

        data_out_port = Txdata[i];              //发送数据    

        con_port |= WRITE_EN;                   //关闭写功能    

        for(j = 0; j < 110; j++);               //发送数据延时    

    }   

       

    con_port = con_leisure;                     //控制端口设置为空闲    

}   

   

void send_data_554byte(unsigned char Txdat,unsigned char select_IO)   

{   

    unsigned char j;   

       

    data_port_dir = 0x0ff;                      //数据信号为输出    

    con_port |= THR;                            //选中发送寄存器    

       

    if(select_IO == 0 )                         //判断选中的端口    

        con_port &= ~CSA;                       //选中A口    

    else if(select_IO == 1)   

             con_port &= ~CSB;   

         else if(select_IO == 2)   

                  con_port &=~CSC;   

              else if(select_IO == 3)   

                       con_port &= ~CSD;   

                   else return;   

   

   

        con_port ^= WRITE_EN;                   //写操作使能    

        data_out_port = Txdat;              //发送数据    

        con_port |= WRITE_EN;                   //关闭写功能    

        for(j = 0; j < 110; j++);               //发送数据延时    

   

       

    con_port = con_leisure;                     //控制端口设置为空闲    

}   

   

/****************************************************  

*  

*    函数名称:init_modem()  

*    功能:modem初始化  

*    入口:无  

*  

****************************************************/   

   

void init_modem(void)   

{   

   

    send_data_554(M_com_initf,num1,2);          //at b0 p e1 q1 s0=1 &y1 &w1    

   

    delays(1);                              //延时    

   

}   

   

/****************************************************  

*  

* 名称:     init_parameter  

* 功能:     初始化各参数  

* 调用:     none  

* 输入:     none  

* 返回值:   none  

*  

****************************************************/   

   

void init_parameter(void)   

{       

    unsigned char i;   

    /*初始化A口各参数*/   

    Rx_in_554a = 0;   

    Rx_554a_start = 0;   

    data_num_554a = 0;   

    Rx_full_554a = 0;   

    checksuma = 0;   

    rx_temp1_554a = 0;   

    rx_temp2_554a = 0;   

   

       

    /*初始化B口各参数*/   

    Rx_in_554b = 0;   

    Rx_554b_start = 0;   

    data_num_554b = 0;   

    Rx_full_554b = 0;   

    checksumb = 0;   

    rx_temp1_554b = 0;   

    rx_temp2_554b = 0;   

   

       

    /*初始化C口各参数*/   

    Rx_in_554c = 0;   

    Rx_554c_start = 0;   

    data_num_554c = 0;   

    Rx_full_554c = 0;   

    checksumc = 0;   

    rx_temp1_554c = 0;   

    rx_temp2_554c = 0;   

    rx_temp3_554c = 0;   


/*初始化D口各参数*/   

    Rx_in_554d = 0;   

    Rx_554d_start = 0;   

    data_num_554d = 0;   

    Rx_full_554d = 0;   

    checksumd = 0;   

    rx_temp1_554d = 0;   

    rx_temp2_554d = 0;   

   

       

    for(i = 0; i < 4; i++)   

    {   

        Rx_flag_554[i] = 0;   

        Rx_out_554[i] = 0;   

    }   

       

    interrupt_edge &= 0xf0;                  //上升沿触发中断    

    interrupt_en |= 0x0f;                   //中断允许位    

    interrupt_flag &=0x00;   

       

//    _EINT();    

}   

   

/****************************************************  

*  

* 名称:     interrupt_554  

* 功能:     554的中断处理函数  

* 调用:     none  

* 输入:     none  

* 返回值:   none  

*  

****************************************************/   

/* ISR定义:  

值              模式   优先级          定义(中断源)  

01              16c450  x               没有中断  

06              16c450  1               LSR(接收线路状态寄存器)  

04              16c450  2               RXRDY(接收中断)  

0C              16c450  2               RXRDY(接收超时中断)  

02              16c450  3               TXRDY(发送寄存器空)  

00              16c450  4               MSR(Modem状态寄存器)  

  

C1              FIFO    x               没有中断  

C6              FIFO    1               LSR(接收线路状态寄存器)  

C4              FIFO    2               RXRDY(接收中断)FIFO超出预定水平  

CC              FIFO    2               RXRDY(接收超时中断)  

C2              FIFO    3               TXRDY(发送寄存器空)  

C0              FIFO    4               MSR(Modem状态寄存器)  

*/   

void interrupt_554(void)   

{   

    unsigned char status_554aisr;                  //554A口的ISR    

    unsigned char status_554cisr;   

    unsigned char status_554bisr;   

    unsigned char status_554disr;   

    unsigned char status_554cmsr;                  //状态存储器    

    unsigned char push;                            //堆栈,保存控制信号的状态    

    unsigned char i;   

       

    push = con_port;                               //con_port的状态保存    

    data_port_dir = 0x00;                          //数据信号输入    

    con_port = con_leisure;   

       

    con_port |= ISR;   

    con_port &= ~CSA;   

    con_port ^= READ_EN;   

    status_554aisr = data_in_port;                  //A口的ISR寄存器    

    con_port = con_leisure;   

       

    con_port |= ISR;   

    con_port &= ~CSB;   

    con_port ^= READ_EN;   

    status_554bisr = data_in_port;                  //B口    

    con_port = con_leisure;   

       

    con_port |= ISR;   

    con_port &= ~CSC;   

    con_port ^= READ_EN;   

    status_554cisr = data_in_port;                  //C口    

    con_port = con_leisure;   

       

    con_port |= ISR;   

    con_port &= ~CSD;   

    con_port ^= READ_EN;   

    status_554disr = data_in_port;                  //D口    

    con_port = con_leisure;       

       

    /* 判断是哪个口产生的中断 */   

    if((status_554aisr & 0x01) == 0)               //判断是否是A口产生的中断    

    {   

        switch(status_554aisr)                     //中断类型选择    

        {   

            case 0x04:                                            //接收中断    

            case 0x0c:   

                 if(!Rx_full_554a)                                //缓冲区未满    

                 {                     

                     con_port |= LSR;   

                     con_port &= ~CSA;   

                     con_port ^= READ_EN;                         //LSR    

                     while((data_in_port & 0x01) == 0 )           //接收寄存器是否有数据    

                     {   

                         con_port = con_leisure;   

                         con_port |= LSR;   

                         con_port &= ~CSA;   

                         con_port ^= READ_EN;                     //LSR    

                     }   

                     con_port = con_leisure;   

                        

                     con_port |= RHR;   

                     con_port &= ~CSA;   

                     con_port ^= READ_EN;                         //rhr    

                     rx_temp2_554a = data_in_port;    //接收到的数据存入数组    

                     con_port = con_leisure;   

   

                     if(Rx_554a_start)                        //判断是否开始接收数据包    

                     {   

                         rxdata[2+0][Rx_in_554a] = rx_temp2_554a;//数据存入缓冲数组    

                         data_num_554a++;                     //接收到的数据个数    

                         Rx_in_554a++;   

   

                         if(data_num_554a == data_maxa)       //判断是否接收完一个数据包    

                         {   

   

                            checksuma=0;   

                             for (i=2;i<DATA_MAXA-1;I++) 

                                     pre }< con_port parity no bit_stop, 1 bit_data, 8 data_out_port="0x0bf;" ^="READ_EN;" &="~CSA;" LCR |="RHR;" mode sleep EFR { low_power(void) void } C口的modem初始化 init_modem(); init_parameter(); C口的初始化 init_16c554c(pstn_bps); pstn_bps) int pstn_init(unsigned (挂机命令) h0 ,at +++ send_data_554(M_com_end,num6,2); delays(1); send_data_554(M_com_escape,num5,2); 发送数据 send_data_554(txdata1,23,2); 0); while(DCD_flag="=" (拨号) ds="0" z1,at at send_data_554(PSTN_num,num3,2); *txdata1) char pstn_send(unsigned * while send_data_554(txdata1,25,2); while(--j) j="5;" send_data_554(M_com_dial,num3,2); init_16c554c(9600); D口的初始化 init_16c554(3,9600); B口的初始化 init_16c554(1,9600); 16c554初始化A口 init_16c554(0,9600); WDTHOLD; +="rx_temp2_554a;" WDTCTL="WDTPW" i="1;" unsigned j,temp; main(void) data_port_dir="0x0ff;" 清中断标志位 P2IFG 0) 0x01)="=" if((P2IN default:break; break; 接收到的数据存入数组 rx_temp1_554d="=" rhr Rx_in_554d="0;" 没有溢出就把溢出标志清零 Rx_full_554d="0;" 缓冲数组已满 else data_num_554d="0;" 标志位置1 Rx_554d_start="0;" checksumd="0;" Rx_in_554d++; rxdata[2+3][Rx_in_554d]="rx_temp2_554d;//数据存入缓冲数组" 包头数据存入缓冲数组 数据包的包头 ) 0x90) (rx_temp2_554d="=" && 0xEB) ( if( !="1)" if(data_maxd-data_num_554d 数据包个数 Rx_flag_554[3]++; 标志位清零 digit_sensor(5); port554_r="2;" 校验和判断 rxdata[2+3][Rx_in_554d-1]) if(checksumd="=" checksumd+="rxdata[2+3][i];" (i="0;i<data_maxa-1;i++)" for 判断是否接收完一个数据包 data_maxd) if(data_num_554d="=" 接收到的数据个数 data_num_554d++; 判断是否开始接收数据包 if(Rx_554d_start) rx_temp2_554d="data_in_port;" LSR 接收寄存器是否有数据 0 while((data_in_port 缓冲区未满 if(!Rx_full_554d) 0x0c: case 接收中断 0x04: 中断类型选择 switch(status_554disr) 判断是否是D口产生的中断 if((status_554disr 0x04)="=0x04))" rx_temp1_554c="=" Rx_in_554c="0;" Rx_full_554c="0;" data_num_554c="0;" Rx_554c_start="0;" checksumc="0;" Rx_in_554c++; rxdata[2+2][Rx_in_554c]="rx_temp2_554c;//数据存入缓冲数组" (rx_temp2_554c="=" if(data_maxc-data_num_554c Rx_flag_554[2]++; command_oper(4); rxdata[2+2][Rx_in_554c-1]) if(checksumc="=" checksumc+="rxdata[2+2][i];" data_maxc) if(data_num_554c="=" data_num_554c++; if(Rx_554c_start) rx_temp2_554c="data_in_port;" if(!Rx_full_554c) send_data_554(M_com_start,num7,2); if(((status_554cmsr DCD_flag="0;" 发送挂机命令 载波信号检测 0x80)="=" if((status_554cmsr 0x08)="=" 读和清零MSR status_554cmsr="data_in_port;" MSR 0xc0: MODEM中断 0x00: switch(status_554cisr) C口中断 if((status_554cisr rx_temp1_554b="=" Rx_in_554b="0;" Rx_full_554b="0;" data_num_554b="0;" Rx_554b_start="0;" checksumb="0;" Rx_in_554b++; rxdata[2+1][Rx_in_554b]="rx_temp2_554b;//数据存入缓冲数组" (rx_temp2_554b="=" if(data_maxb-data_num_554b Rx_flag_554[1]++; command_oper(3); rxdata[2+1][Rx_in_554b-1]) if(checksumb="=" checksumb+="rxdata[2+1][i];" data_maxb) if(data_num_554b="=" data_num_554b++; if(Rx_554b_start) rx_temp2_554b="data_in_port;" if(!Rx_full_554b) switch(status_554bisr) 判断是否是B口产生的中断 if((status_554bisr rx_temp1_554a="=" Rx_in_554a="0;" Rx_full_554a="0;" data_num_554a="0;" Rx_554a_start="0;" checksuma Rx_in_554a++; rxdata[2+0][Rx_in_554a]="0xeb;" (rx_temp2_554a="=" if(data_maxa-data_num_554a Rx_flag_554[0]++; command_oper(2); rxdata[2+0][i]="0;" rxdata[2+0][Rx_in_554a-1]) if(checksuma="=" checksuma+="rxdata[2+0][i];">  



⌨️ 快捷键说明

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