在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 51單片機(jī)+315M無(wú)線射頻模塊發(fā)射程序

            51單片機(jī)+315M無(wú)線射頻模塊發(fā)射程序

            作者: 時(shí)間:2016-11-30 來(lái)源:網(wǎng)絡(luò) 收藏

            void clock_init(void){
            jiffies = 0;
            TMOD=0x02;
            TH0=TL0=0x0ce;//12M,50us
            //TH0=TL0=0x7a;//16M
            //TH0=TL0=0x75;//16.59M
            //TH0=TL0=0x72;//17M
            //TH0=TL0=0x37;//24M
            //TH0=TL0=0x47;//22.1844M, 100us
            //TH0=TL0=0xa3;//22.1844M, 50us
            EA=1;
            ET0=1;

            TR0=1;
            }


            void clock_init_again(void){

            TMOD=0x02;
            TH0=0x0ce;//12M,50us
            TL0=T0_last;
            //TH0=TL0=0x7a;//16M
            //TH0=TL0=0x75;//16.59M
            //TH0=TL0=0x72;//17M
            //TH0=TL0=0x37;//24M
            //TH0=TL0=0x47;//22.1844M, 100us
            //TH0=TL0=0xa3;//22.1844M, 50us
            EA=1;
            ET0=1;
            jiffies=0;
            TR0=1;
            }


            void init_serialcomm(void)
            {
            SCON = 0x50; //SCON: serail mode 1, 8-bit UART, enable ucvr
            TMOD |= 0x20; //TMOD: timer 1, mode 2, 8-bit reload
            PCON |= 0x80; //SMOD=1;
            TH1 = 0x0e6; //Baud:2400 fosc=11.0592MHz :f4
            TL1 = 0x0e6;
            //IE |= 0x90; //Enable Serial Interrupt
            TR1 = 1; // timer 1 run
            RI=0;
            TI=1;
            }

            void serial_out(char d){
            while(!TI);
            TI=0;
            SBUF=(d);
            }

            void send_string_com(char *str,int strlen)//串口程序
            { char sum;

            int k=0;
            serial_out(02);
            do
            { sum^=*(str+k);
            serial_out(*(str + k));
            k++;
            } while(k < strlen);
            serial_out(sum);
            serial_out(03);
            }

            //等待指定長(zhǎng)度的串行數(shù)據(jù)到達(dá),超時(shí)值為每?jī)蓚€(gè)字節(jié)之間的間隔時(shí)間而非等待整個(gè)串的時(shí)間.
            //超時(shí)單位為time_out * 100uS
            bit wait_serial(unsigned char *p, unsigned char len, unsigned char time_out){
            unsigned int time=jiffies;
            unsigned char n=0;
            do{
            if (RI){
            p[n++]=SBUF;
            RI=0;
            if(n==len)
            return 0;
            time=jiffies;
            }
            }while(jiffies-time < time_out);
            return 1;
            }

            sys_init(){
            clock_init();
            init_serialcomm();
            }


            //=============================================================
            //發(fā)送程序 開(kāi)始
            //=============================================================

            #define PULS_0_WIDTH 8//低電平脈寬
            #define PULS_1_WIDTH 16//高電平脈寬
            #define PULS_HEAD_WIDTH 8//前導(dǎo)信號(hào)脈寬
            #define PULS_START_WIDTH 24//引導(dǎo)信號(hào)脈寬
            #define PULS_STOP_WIDTH 8//結(jié)束碼脈寬

            #define PULS_HEAD_COUNTS 16//前導(dǎo)信號(hào)長(zhǎng)度


            unsigned char send_buf[16];
            #define send_byts send_buf[0]//剩余字節(jié)數(shù),發(fā)送完后為0
            unsigned char sending_byte;//當(dāng)前正在發(fā)送的字節(jié)
            unsigned char send_byte_p;//已發(fā)送字節(jié)數(shù)(含正在發(fā)送的字節(jié))
            unsigned char send_bit_p;//當(dāng)前正在發(fā)送的字節(jié)已發(fā)送位數(shù)(含正在發(fā)送的位)

            #define SEND_PROGRESSING 0x41
            #define SEND_FAILED 0x21
            #define SEND_SUCCESS 0x31
            unsigned char send_stat = 0;//發(fā)送程序當(dāng)前狀態(tài),為0時(shí)正常
            unsigned char head_counts;//前導(dǎo)信號(hào)計(jì)數(shù)器(包括引導(dǎo)信號(hào))

            void start_send(){
            send_byte_p = 0;
            send_bit_p = 0;
            send_stat = SEND_PROGRESSING;
            head_counts = 16;
            }

            #define START_SEND(byts) send_buf[0]=byts;send_byts=byts;start_send()

            //發(fā)送前應(yīng)清除send_byte_p,send_bit_p,send_stat,并設(shè)置send_byts
            //發(fā)送過(guò)程中可根據(jù)send_byts的值得到剩余字節(jié)數(shù),根據(jù)send_byte_p的值得到已發(fā)送字節(jié)數(shù).注意,將正在發(fā)送的字節(jié)當(dāng)作已發(fā)送完畢.
            //發(fā)送過(guò)程中可根據(jù)send_stat的值得到發(fā)送狀態(tài).
            //發(fā)送完成后,send_byts和send_bit_p的值都為0.
            #define SEND_PULS(x) w_data=send_busy=(x>>1)
            void send(){
            //下面兩行在wirless()中已經(jīng)執(zhí)行過(guò)了,所以無(wú)需寫上
            //if (send_stat != SEND_PROGRESSING)
            //return;

            if (!send_busy){
            if(send_byts || send_bit_p){
            if (head_counts){
            head_counts--;
            if(head_counts)
            SEND_PULS(PULS_HEAD_WIDTH);
            else
            SEND_PULS(PULS_START_WIDTH);
            }else{
            if (send_bit_p == 0){
            sending_byte = send_buf[send_byte_p];
            send_byte_p++;
            send_byts--;
            send_bit_p = 8;
            }

            if(sending_byte & 0x80){
            SEND_PULS(PULS_1_WIDTH);
            }else{
            SEND_PULS(PULS_0_WIDTH);
            }

            sending_byte <<= 1;
            send_bit_p--;
            }
            }else{
            SEND_PULS(PULS_STOP_WIDTH);
            send_stat = SEND_SUCCESS;
            }
            }
            return;
            }
            //=============================================================
            //發(fā)送程序 結(jié)束
            //=============================================================

            //=============================================================
            //接收程序 開(kāi)始
            //=============================================================

            unsigned char recv_buf[16];
            #define recv_byts recv_buf[0]//應(yīng)收到字節(jié)數(shù),由每個(gè)包的第一個(gè)字節(jié)指定
            unsigned char recving_byte;//當(dāng)前正在接收的字節(jié)
            unsigned char recv_byte_p;//已收到字節(jié)數(shù)(不含正在接收的字節(jié))
            unsigned char recv_bit_p;//當(dāng)前正在接收的字節(jié)等待接收位數(shù)(不含正在接收的位)

            #define RECV_FAILED 0x31
            #define RECV_SUCCESS 0x41

            unsigned char recv_stat = 0; //接收程序當(dāng)前狀態(tài),為0時(shí)正常
            unsigned char recv_step = 0;//引導(dǎo)脈沖標(biāo)志,為0時(shí)等待引導(dǎo),為1時(shí)等待數(shù)據(jù)

            #define TEST_PULS(puls_in, puls_type) (puls_in > puls_type - PULS_0_WIDTH / 2 && puls_in < puls_type + PULS_0_WIDTH / 2)

            #define HEAD_NEED_RECIVED 8
            void recv(){
            unsigned puls_width;

            if ((recv_stat == RECV_SUCCESS) || !w_data)
            return;

            puls_width = w_data;
            w_data = 0;

            #if 0//輸出脈寬
            serial_out(puls_width);
            //printhex(puls_width);
            #endif

            if (recv_step < HEAD_NEED_RECIVED){
            if(TEST_PULS(puls_width, PULS_HEAD_WIDTH)){
            recv_step++;
            }else{
            recv_step = 0;
            }
            }else if (recv_step == HEAD_NEED_RECIVED){
            if(TEST_PULS(puls_width, PULS_START_WIDTH)){
            serial_out(0xbb);
            recv_byte_p = 0;
            recv_bit_p = 8;
            recv_stat = 0;
            recv_step++;
            }else{
            if(!TEST_PULS(puls_width, PULS_HEAD_WIDTH)){
            recv_step = 0;
            }
            }
            }else{
            //serial_out(puls_width);
            recving_byte <<= 1;
            if(TEST_PULS(puls_width, PULS_0_WIDTH)){
            recving_byte &= 0xfe;
            }else if(TEST_PULS(puls_width, PULS_1_WIDTH)){
            recving_byte |= 1;
            }else{
            serial_out(puls_width);
            recv_step = 0;
            serial_out(0xaa);
            return;
            }



            評(píng)論


            技術(shù)專區(qū)

            關(guān)閉