资源简介

这是我自己做的基于单片机的数字气压计,气压传感器用的是MPX4250,proteus软件,keil软件,调试已成功。压缩文件里有说明(先看说明),完善的dsn电路图,c源代码,以及可以直接加载的hex文件,希望能帮上大家。

资源截图

代码片段和文件信息

#include
#include
#include
#define uchar unsigned char
#define uint  unsigned int


sbit RS =P2^0;
sbit RW =P2^1;
sbit EN =P2^2;

sbit CS =P3^4;
sbit CLK=P3^2;
sbit DIO=P3^3;

uchar yq;

uchar dis_yq[5]={“     “};
uchar dis_lcd11[8]={“asdfff“};


 //----------------延时--------------------------------
 void delay(uint x)
 {
  uchar i;
  while(x--)  for(i=0;i<120;i++);
 
 }
 //-------------------------------------------------------
 //-------------------------LCD  控制------------------------------------------
//读lcd 状态
bit lcd_busy_check()
 {
   bit s;
   RS=0; RW=1;EN=1; delaynop(); s=(bit)(P0 & 0x80);EN=0;
   return s;
 
 }

uchar read_lcd_state()
{
  uchar state ;
  RS=0;RW=1;EN=1;delay(1);state=P0;EN=0;delay(1);
  return state;

}                                  
//---------------------------------------------------------
//  忙等待
void lcd_busy_wait()
{
  while((read_lcd_state()&0x80)==0x80);
delay(5);

}
//--------------------------------------------------------
 //向LCD写数据
 void write_lcd_data(uchar dat)
 {
     while(lcd_busy_check());
      lcd_busy_wait();
   RS=1;RW=0;EN=0;P0=dat;EN=1;delaynop();EN=0;
 
 }
 //---------------------------------------------
 //向LCD写指令
 void write_lcd_cmd(uchar cmd)
 {
  while(lcd_busy_check());
 lcd_busy_wait();
   RS=0;RW=0;EN=0;_nop_();_nop_();P0=cmd;delaynop();EN=1;delaynop();EN=0;
 
 }
//-----------------------------------------------------------------------------------------------------
//LCD初始化
void init_lcd()
{
   write_lcd_cmd(0x38);  delay(1);
   write_lcd_cmd(0x0C) ; delay(1);
   write_lcd_cmd(0x06);  delay(1);
   write_lcd_cmd(0x01) ;  delay(1);


 //-----------------------------------------------
 //设置液晶显示位置
 void set_lcd_pos(uchar p)
 {
  write_lcd_cmd(p| 0x80);

 }
  //---------------------------------------
  //在LCD上显示字符串
  void dis_lcd_string(uchar puchar *s)  //位置字符指针
  {
   uchar i;
    set_lcd_pos(p);
for(i=0;i<16;i++)//16*2
{
  write_lcd_data(s[i]) ;
//  delay(1);

}
  }
 //-------------------------------------------------------------------
 
//********************************************************

 //--------------------------------------------
 //获取AD转换结果
 uchar get_AD_result()
 {
   uchar idat1=0dat2=0;
   //其实控制位
   CS=0;
   CLK=0;
   DIO=1; _nop_();_nop_();
   CLK=1; _nop_();_nop_();

   CLK=0;DIO=1; _nop_();_nop_();
   CLK=1;     _nop_();_nop_();

   

   CLK=0;DIO=0; _nop_();_nop_();
   CLK=1;DIO=1; _nop_();_nop_();
   
   CLK=0;DIO=1; _nop_();_nop_();


   for(i=0;i<8;i++)
   {
    CLK=1; _nop_();_nop_();
    CLK=0;  _nop_();_nop_();
dat1=dat1<<1 | DIO;
   }

   for(i=0;i<8;i++)
   {
    dat2=dat2|( (uchar)(DIO)< CLK=1; _nop_();_nop_();
    CLK=0;  _nop_();_nop_();
   }

   CS=1;
   return (dat1==dat2) ? dat1 :0;
}
 //--------------------------------------------------------------

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3440  2010-09-04 22:00  电路图 程序\气压.c

     文件     134055  2011-06-17 20:54  电路图 程序\气压.DSN

     文件       2047  2011-06-10 08:55  电路图 程序\气压.Uv2

     文件       4629  2010-09-04 23:51  电路图 程序\电压表.hex

     文件        848  2011-09-15 14:37  电路图 程序\先看这个-说明.txt

     文件   17969535  2011-04-25 09:35  电路图 程序\基于MPX4115的数字气压计设计论文.pdf

     目录          0  2011-06-25 22:41  电路图 程序

----------- ---------  ---------- -----  ----

             18114554                    7


评论

共有 条评论