怎么把下面的51程序(关于电子血压计设计的)改为MSP430

2019-07-15 16:50发布


  1. <div align="left">#include<reg51.h></div><div align="left">#define uchar unsigned char</div><div align="left">#define uint unsigned int</div><div align="left">sbit DQ=P1^0;//ASDX001与单片机连接口</div><div align="left">sbit RS=P3^5;</div><div align="left">sbit RW=P3^6;</div><div align="left">sbit EN=P3^7;</div><div align="left">unsigned char code str1[]={"blood pressure:  "};</div><div align="left">unsigned char code str2[]={"              "};</div><div align="left">uchar data disdata[5];</div><div align="left">uint tvalue;//压力值</div><div align="left">uchar tflag;//压力正负标志</div><div align="left">/*************************lcd1602程序**************************/</div><div align="left">void delay1ms(unsigned int ms)//延时1毫秒(不够精确的)</div><div align="left">{unsigned int i,j;</div><div align="left">   for(i=0;i<ms;i++)</div><div align="left">    for(j=0;j<100;j++);</div><div align="left">}</div><div align="left">void wr_com(unsigned char com)//写指令//</div><div align="left">{ </div><div align="left">delay1ms(1);</div><div align="left">RS=0;</div><div align="left">RW=0;</div><div align="left">EN=0;</div><div align="left">P0=com;</div><div align="left">delay1ms(1);</div><div align="left">EN=1;</div><div align="left">delay1ms(1);</div><div align="left">EN=0;</div><div align="left">}</div><div align="left">void wr_dat(unsigned char dat)//写数据//</div><div align="left">{ </div><div align="left">delay1ms(1);;</div><div align="left">RS=1;</div><div align="left">RW=0;</div><div align="left">EN=0;</div><div align="left">P0=dat;</div><div align="left">delay1ms(1);</div><div align="left">EN=1;</div><div align="left">delay1ms(1);</div><div align="left">EN=0;</div><div align="left">}</div><div align="left">void lcd_init()//初始化设置//</div><div align="left">{</div><div align="left">delay1ms(15);</div><div align="left">wr_com(0x38);</div><div align="left">delay1ms(5);</div><div align="left">wr_com(0x08);</div><div align="left">delay1ms(5);</div><div align="left">wr_com(0x01);</div><div align="left">delay1ms(5);</div><div align="left">wr_com(0x06);</div><div align="left">delay1ms(5);</div><div align="left">wr_com(0x0c);</div><div align="left">delay1ms(5);</div><div align="left">}</div><div align="left">void display(unsigned char *p)//显示//</div><div align="left">{</div><div align="left">while(*p!='')</div><div align="left">{</div><div align="left">wr_dat(*p);</div><div align="left">p++;</div><div align="left">delay1ms(1);</div><div align="left">}</div><div align="left">}</div><div align="left">init_play()//初始化显示</div><div align="left">{ lcd_init();</div><div align="left">wr_com(0x80);</div><div align="left">display(str1);</div><div align="left">wr_com(0xc0);</div><div align="left">display(str2);</div><div align="left">   }</div><div align="left">void delay_asdx001(unsigned int i)//延时1微秒</div><div align="left">{</div><div align="left">   while(i--);</div><div align="left">}</div><div align="left">void asdx001rst()/*ds1820复位*/</div><div align="left">{ unsigned char x=0;</div><div align="left">DQ = 1;          //DQ复位</div><div align="left">delay_asdx001(4); //延时</div><div align="left">DQ = 0;          //DQ拉低</div><div align="left">delay_asdx001(100); //精确延时大于480us</div><div align="left">DQ = 1;          //拉高</div><div align="left">delay_asdx001(40); </div><div align="left">} </div><div align="left">uchar asdx001rd()/*读数据*/</div><div align="left">{ unsigned char i=0;</div><div align="left">unsigned char dat = 0;</div><div align="left">for (i=8;i>0;i--)</div><div align="left">{   DQ = 0; //给脉冲信号</div><div align="left">    dat>>=1;</div><div align="left">    DQ = 1; //给脉冲信号</div><div align="left">    if(DQ)</div><div align="left">    dat|=0x80;</div><div align="left">    delay_asdx001(10);</div><div align="left">}</div><div align="left">   return(dat);</div><div align="left">}</div><div align="left">void asdx001wr(uchar wdata)/*写数据*/</div><div align="left">{unsigned char i=0;</div><div align="left">    for (i=8; i>0; i--)</div><div align="left">   { DQ = 0;</div><div align="left">     DQ = wdata&0x01;</div><div align="left">     delay_asdx001(10);</div><div align="left">     DQ = 1;</div><div align="left">     wdata>>=1;</div><div align="left">   }</div><div align="left">}</div><div align="left">read_pressure1()/*读取压力值并转换*/</div><div align="left">{</div><div align="left">asdx001rst();    </div><div align="left">asdx001wr(0xcc);//*跳过读序列号*/</div><div align="left">asdx001wr(0x44);//*启动压力转换*/</div><div align="left">asdx001rst();    </div><div align="left">}</div><div align="left">read_pressure2()</div><div align="left">{uchar a,b;</div><div align="left">asdx001wr(0xcc);//*跳过读序列号*/ </div><div align="left">asdx001wr(0xbe);//*读取压力*/ </div><div align="left">a=asdx001rd();</div><div align="left">b=asdx001rd();</div><div align="left">tvalue=b;</div><div align="left">tvalue<<=8;</div><div align="left">tvalue=tvalue|a;</div><div align="left">    if(tvalue<0x0fff)</div><div align="left">   tflag=0;</div><div align="left">    else</div><div align="left">   {tvalue=~tvalue+1;</div><div align="left">   tflag=1;</div><div align="left">   }</div><div align="left">return(tvalue);</div><div align="left">}</div><div align="left">/*******************************************************************/</div><div align="left">   void asdx001disp1()//压力值显示</div><div align="left">{   uchar flagdat;</div><div align="left">    disdata[0]=tvalue/1000+0x30;//百位数</div><div align="left">     disdata[1]=tvalue%1000/100+0x30;//十位数</div><div align="left">     disdata[2]=tvalue%100/10+0x30;//个位数</div><div align="left">     disdata[3]=tvalue%10+0x30;//小数位</div><div align="left">    </div><div align="left">     if(tflag==0)</div><div align="left">     flagdat=0x20;//正压力不显示符号</div><div align="left">     else</div><div align="left">       flagdat=0x2d;//负压力显示负号</div><div align="left">     if(disdata[0]==0x30)</div><div align="left">    {disdata[0]=0x20;//如果百位为0,不显示</div><div align="left">   if(disdata[1]==0x30)</div><div align="left">    {disdata[1]=0x20;//如果百位为0,十位为0也不显示</div><div align="left">    }</div><div align="left">   }}</div><div align="left">void asdx001disp2()</div><div align="left">  {uchar flagdat;</div><div align="left">    wr_com(0xc3);</div><div align="left">    wr_dat(flagdat);//显示符号位</div><div align="left">    wr_dat(disdata[0]);//显示百位</div><div align="left">    wr_dat(disdata[1]);//显示十位 </div><div align="left">    wr_dat(disdata[2]);//显示个位 </div><div align="left">    wr_dat(0x2e);//显示小数点 </div><div align="left">    wr_dat(disdata[3]);//显示小数位</div><div align="left">    wr_com(0xca);</div><div align="left">    wr_dat(0xdf);</div><div align="left">    wr_dat(0x43);</div><div align="left">   }</div><div align="left">/********************主程序***********************************/</div><div align="left">void main()</div><div align="left">{ </div><div align="left">init_play();//初始化显示</div><div align="left">   while(1)</div><div align="left">{   read_pressure1();//读取压力</div><div align="left">    read_pressure2();//读取压力</div><div align="left">    asdx001disp1();//显示</div><div align="left">    asdx001disp2();//显示</div><div align="left">}</div><div align="left">}</div>
复制代码


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。