3d新彩网字谜汇总

  |     |     |  
一个自己写的UART双数据缓冲(buffer)乒乓中断读取程序(原创)
HXW718059156 | 2012-02-23 10:17:48    阅读:10862  
本文参与参与“相伴ADI,相随UDC——博客征文比赛”获投票:40
 

yigezijixiedeuartshuangshujuhuanchong(buffer)pingpangzhongduanduquchengxu(yuanchuang)

shouxianjieshaoyixia,beijing:zaibenciudcdasaizhong,womenduidezuopinxuyaojiangxianchangcaiyangdeshishihuanjingshujuhezhinengxiaocheyunxingzhuangtaitongguowuxianfangshichuanshuzhipcshangweijiruanjian(c++bianxie)xianshihehuitu,lingyifangmian,womenhaiyaoshixianshangweijiduixianchangzhinengbizhangxiaochedekongzhi。youyushujuliangda,bingqieyaobaozhengshishikekaodejieshoushujuhefasongkongzhimingling,duipcjiyiduanuarttongxinjiwuxiantongxindekekaoxingheshishixingtichuleyangedeyaoqiu,wuxianyouyucaiyongdeshinrf24l01mokuai,qijuyouzidongyingda,pianshangwanzhengdecrcxiaoyangongneng,zaijiashangwomenjingxinshejide(shujuhemingling)tongxinzhen,yijiliangduandezhongduanjieshou,baozhenglewuxianshuchuandekekaoxingheshishixing。

zheilizhuyaotanyixiauartyupczhijiandetongxin,zhiqiancaiyongguanyongdeyigeshujuhuancun,jiazhongduanbiaozhikongzhidefangshishixian,zaishujuliangbudadeqingkuangxia,keyizhengchangwuwudetongxin,danshidangzengdashoufadeshujuliangshi,chuxiancuowushujuheshujudiushixianxiang。

womenpeizhideuartshezhiwei:

    botelv:9600bitps;8biteshuju;1weitingzhiwei,wuqiouxiaoyanwei,jieshouduanrx bufferwei32 bytes;jieshourxzhongduanshineng;

dangran,tigaotongxinbotelvkeyizengdaanquanshujutongxinsulv,danshizongshizhibiaobuzhiben。jingguoyifansikao,womenbianxieleruxiadeuartshuangshujuhuanchong(buffer)pingpangzhongduanduquchengxu,baozhengrenhebotelvxiadekekaoshishitongxin。shicejieguolingrenmanyi(zaidanpianjixunhuanfasongdaliangshujuzhipcjideqingkuangxia,shangweijiruanjianmeijiange1msxiangxiafasong100zijieshuju,ceshiwushujudiushihecuowu)。

zuihou,fushangyuandaimabingjiandanjieshiyixiayuanli:

suoweishuangshujuhuancunji:rx_buffer1[rx_buffer_size]herx_buffer2[rx_buffer_size],bufferused,zuoweiquanjubianliang,yongyujilubingchuandilianggebuffercaozuoshunxu;suoweipingpangzhongduanduqu,jizaiuartzhongduanfuwuchengxuzhonglunliujiaotishiyongshangshulianggeshujuhuancunjieshoupcfalaideshuju。

qizhongmain.cdeyujuif(bufferused!=lastbuffer){….lastbuffer = bufferused;….}yongyuwanchenglianggebufferpingpangcaozuodejianceyuqiehuan,jutidaimaruxia:

  • 中断服务程序代码:

#define rx_buffer_size128

3d新彩网字谜汇总uint8bufferused = 0;//

3d新彩网字谜汇总uint8rx_buffer1[rx_buffer_size]={0};

uint8rx_buffer2[rx_buffer_size]={0};

3d新彩网字谜汇总cy_isr(isr_uartrx_interrupt)

{

3d新彩网字谜汇总    /*  place your interrupt code here. */

3d新彩网字谜汇总    /* `#start isr_uartrx_interrupt` */

    uint8rec_status = 0u;

    staticuint8pointerrx = 0u;

3d新彩网字谜汇总    staticuint8buffer = 0;

    uint8receivechar = 0;

   

    rec_status = uart_readrxstatus();//read the rx state

    while(rec_status & uart_rx_sts_fifo_notempty)//there are data in the fifo

    {

3d新彩网字谜汇总       if(pointerrx<rx_buffer_size)

           if(buffer%2==0)

3d新彩网字谜汇总              rx_buffer1[pointerrx++] = uart_rxdata_reg;

           else

              rx_buffer2[pointerrx++] = uart_rxdata_reg;

       else

       {

           pointerrx = 0;   

3d新彩网字谜汇总           buffer++;

3d新彩网字谜汇总           bufferused = buffer;

       }

       rec_status = uart_readrxstatus();

3d新彩网字谜汇总    }

3d新彩网字谜汇总    /* `#end` */

 

    /* psoc3 es1, es2 rtc isr patch  */

3d新彩网字谜汇总    #if(cydev_chip_family_used == cydev_chip_family_psoc3)

3d新彩网字谜汇总        #if((cydev_chip_revision_used <= cydev_chip_revision_3a_es2) && (isr_uartrx__es2_patch ))     

            isr_uartrx_isr_patch();

        #endif

    #endif

}

  • Main函数处理代码:

//uart to pc communication

3d新彩网字谜汇总externuint8bufferused;

externuint8rx_buffer1[rx_buffer_size];

3d新彩网字谜汇总externuint8rx_buffer2[rx_buffer_size];

voidmain()

{

uint8lastbuffer = 0;

while(1)

{

uart_putarray(mutiinfo,32);//send large information to pc

       if(bufferused!=lastbuffer)//if there is one buffer data ready

       {

3d新彩网字谜汇总           if(bufferused%2)

3d新彩网字谜汇总           {

//just send the buffer back to pc for verify

              uart_putarray(rx_buffer1,rx_buffer_size);

              //clean the buffer for next data receive

               for(i=0;i<rx_buffer_size;i++) rx_buffer1[i] = 0;

           }

3d新彩网字谜汇总           else

           {

//just send the buffer back to pc for verify

3d新彩网字谜汇总              uart_putarray(rx_buffer2,rx_buffer_size);

3d新彩网字谜汇总              //clean the buffer for next data receive

3d新彩网字谜汇总              for(i=0;i<rx_buffer_size;i++) rx_buffer2[i] = 0;

3d新彩网字谜汇总           }

           lastbuffer = bufferused;//record current operate state

          

           lcd_char_1602_position(1,0);

           lcd_char_1602_printstring("uart get data!");

3d新彩网字谜汇总       }

}

}

 

3d新彩网字谜汇总                                            huenwei

                                      2011nian9yue7rixingqisan

3d新彩网字谜汇总                                    yuzhongdaaquzhujiao2601shiyanshi

*bokeneirongweiwangyougerenfabu,jindaibiaobozhugerenguandian,ruyouqinquanqinglianxigongzuorenyuanshanchu。

参与讨论
登录后参与讨论
 2013-04-08 13:14:52 

yongxunhuanhuanchongyinggaiyekeyi

 2012-03-10 16:08:54 

3d新彩网字谜汇总luguo,laixuexixuexi^_^

欢迎大家关注我的微信公众号--汽车电子expert成长之路,阅读更多原创性精彩文章。如果你觉得我的文章对你的学习/工作有所帮助,也请你帮忙转发到你的朋友圈,让更多的人能够看到我的文章,大家一起学习,一起进步!
推荐文章
最近访客
2元中国福利彩票的买法 2元买彩票选几个数字 2元中国福利彩票怎么看 2元就可以打1毛的斗地主棋牌 2元就可以打1毛的炸金花棋牌 2元彩票双色球走势图双色球 2元彩不错 2元彩是值得您信赖的 2元彩票 2元彩票网全国走势图