0832ADC 51 test program

Publisher:Xiaoxue666Latest update time:2016-08-23 Source: eefocusKeywords:0832ADC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include"reg52.h"

#include
#include"intrins.h"

//==========================================================
sbit CS=P3^0; //Enable chip select
sbit CLK=P3^1; //Clock
sbit Do=P3^2; //Data output
sbit Di=P3^2; //Data input
sbit Do2=P3^3; //Data output
sbit Di2=P3^3; //Data input
sbit Do3=P3^4; //Data output
sbit Di3=P3^4; //Data input
sbit Do4=P3^5; //Data output
sbit Di4=P3^5; //Data input
sbit Do5=P3^6; //Data output
sbit Di5=P3^6; //Data input

unsigned char data_f=0,data_c=0,data_f2=0,data_c2=0,data_f3=0,data_c3=0,data_f4=0,data_c4=0,data_f5=0,data_c5=0;  //data_f正确顺序  data_c逆序

unsigned char last[5]; //Record the value obtained by each AD conversion at the last moment
unsigned char current[5]; //Record the value obtained by this AD conversion

int left = 0; //Record the number of steps the motor takes to the left within 0.1 seconds
int right = 0; //Record the number of steps the motor takes to the right within 0.1 seconds

sbit RS = P2^4;//Pin4
sbit RW = P2^5; //Pin5
sbit E = P2^6;//Pin6

#define Data P0 //Data port

char data TimeNum[]="                ";
char data Test1[]="                  ";


/******************************************************************/
/*                    函数声明                                    */
/******************************************************************//***************************************************************/
void DelayUs(unsigned char us)//delay us
{
 unsigned char uscnt;
 uscnt=us>>1;/* Crystal frequency in 12MHz*/
 while(--uscnt);
}
/******************************************************************/
void DelayMs(unsigned int ms)//delay Ms
{
 while(--ms)
   {
     DelayUs(250);
     DelayUs(250);
  DelayUs(250);
  DelayUs(250);
   }
}
void WriteCommand(unsigned char c)
{
 DelayMs(5);//short delay before operation
 E=0;
 RS=0;
 RW=0;
 _nop_();
 E=1;
 Data=c;
 E=0;
}
/****************************************************************/
void WriteData(unsigned char c)
{
 DelayMs(5);   //short delay before operation
 E=0;
 RS=1;
 RW=0;
 _nop_();
 E=1;
 Data=c;
 E=0;
 RS=0;
}
/*********************************************************************/
void ShowChar(unsigned char pos,unsigned char c)
{
 unsigned char p;
 if (pos>=0x10)
    p=pos+0xb0; //是第二行则命令代码高4位为0xc
 else 
    p=pos+0x80; //是第二行则命令代码高4位为0x8
 WriteCommand (p);//write command
 WriteData (c);   //write data
}
/*************************************************************************/
void ShowString (unsigned char line,char *ptr)
{
 unsigned char l,i;
 l=line<<4;
 for (i=0;i<16;i++)
  ShowChar (l++,*(ptr+i));//循环显示16个字符
}
/*********************************************************************/
void InitLcd()
{
 DelayMs(15);
 WriteCommand(0x38); //display mode
 WriteCommand(0x38); //display mode
 WriteCommand(0x38); //display mode
 WriteCommand(0x06); //显示光标移动位置
 WriteCommand(0x0c); //显示开及光标设置
 WriteCommand(0x01); //显示清屏

}


///
...


  ​



  //   Pre   -   initialization   =
  ...



  CS=1;
  _nop_();
  CS=0;
  Di=1;
  Di2=1;
  Di3=1;
  Di4=1;
  Di5=1;
  //=================================================================

  //The first falling edge======================================================   CLK
  =1;   _nop_
  ();   _nop_   (   )
  ;   CLK   =   0
  ;
  //   =   ...   _nop_();   CLK=0;   //======================================================================   //The third falling edge==========================================================   _nop_();   _nop_();   CLK=1;   Di=0;   Di2=1;   Di3=1;   Di4=1;   Di5=1;   _nop_();   _nop_();   CLK=0;   //   AD initialization        completed   //     ======================================================================   //   Read   data   =   ...   ​
  













  













  









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

  CLK=1;
  //Get a normal sorted 8-bit data
  for(i=8;i>0;i--)
  {
 data_f<<=1;
 data_f2<<=1;
 data_f3<<=1;
 data_f4<<=1;
 data_f5<<=1;

    data_f|=Do;
    data_f2|=Do2; 
    data_f3|=Do3;
    data_f4|=Do4; 
    data_f5|=Do5;

 

 CLK=1;
    _nop_();
    _nop_();
    CLK=0;
    _nop_();  
  }
  //==============================
  //Get an 8-bit data in reverse order  
  for(i=8;i>0;i--)
  {
 data_c<<=1;
 data_c2<<=1;
 data_c3<<=1;
 data_c4<<=1;
 data_c5<<=1;

    data_c|=Do;
    data_c2|=Do2;
    data_c3|=Do3;
    data_c4|=Do4;
    data_c5|=Do5;

    _nop_();
 CLK=1;
    _nop_();
    _nop_();
    CLK=0;
    _nop_();  
  }
  //==============================
  CLK=0;
  _nop_();
  _nop_();
  CLK=1;
  _nop_();
  _nop_();
  CLK=0; 
  _nop_();
  _nop_();
  CLK=1;
  _nop_();
  CS=1;
  _nop_();
  _nop_();


}
//===================================================================

//Display conversion==============================================================
char huanhuan(unsigned char benben)
{
  switch(benben)
  {
    case 0:
 return '0';
 break;

 case 1:
 return '1';
 break;

 case 2:
 return '2';
 break;  
  
 case 3:
 return '3';
 break;

 case 4:
 return '4';
 break;

 case 5:
 return '5';
 break;

 case 6:
 return '6';
 break;

 case 7:
 return '7';
 break;

 case 8:
 return '8';
 break;

 case 9:
 return '9';
 break;

 default:
 break;
  }
}
//===================================================================

void main()
{
  unsigned xianshi=0;
  InitLcd();
  DelayMs(15);
  sprintf(Test1," wo shi tiancai ");//the first line
  ShowString(0,Test1);
  sprintf(TimeNum,"AD value is     ");//the first line
  ShowString(1,TimeNum);
  while(1)
  {  
    DelayMs(800);
    xianshi=data_f;     
    ADconv();
 TimeNum[12]=huanhuan(xianshi/100);
 TimeNum[13]=huanhuan(xianshi/10%10);
 TimeNum[14]=huanhuan(xianshi%10);
    ShowString(1,TimeNum);
  }
}

Keywords:0832ADC Reference address:0832ADC 51 test program

Previous article:Summary of AT89C51ED2 EEPROM read and write operations
Next article:The use of 51 single chip microcomputer 24c02

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号