ADC0831 analog-to-digital conversion program

Publisher:数据旅人Latest update time:2012-11-10 Source: 21ic Keywords:ADC0831 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*
Program effect: The digital tube displays one byte of data converted from AD, displayed in decimal
Adjust the corresponding potentiometer to change the displayed data accordingly
Program development: http://www.51hei.com
Principle: 0831 is a serial AD chip. Adjusting the positioner is to adjust the size of the analog voltage input to 0831, and then display it through the digital tube
Operating environment: 51hei single-chip learning board
*/
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,//digital tube display value
0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit scl1=P1^3; //chip communication pulse pin
sbit sda1=P1^4; //data transmission pin
sbit px1=P1^5; //Chip select pin, i.e. select ADC0831 and DS1302
sbit cs1=P1^6; //Chip select pin
uchar tmpdata[]={0,0,0};
uchar readad0831();//Define this function to read the data of ADC0831
void display(uchar *lp,uchar lc); //Display sub-function
void delay(); //Delay sub-function
void main() //Main function
{
uchar i=0,tmp;
px1=0; //Select ADC0831 chip
while(1)
{
i++;
if(i==255) //Here is a loop of 255 cycles to read 0831 once,
{ //Because the CPU runs very fast, there is no need to read it every time
tmp=readad0831(); //Read data, so that the CPU resources can be fully utilized
i=0;
tmpdata[0]=tmp/100;//Separate the hundreds digit
tmp=tmp%100;
tmpdata[1]=tmp/10; //separate the tens digit
tmpdata[2]=tmp%10; //separate the ones digit
}
display(tmpdata,3); //output display
}
}
void display(uchar *lp,uchar lc) //display subfunction
{
uchar i; //define local variable
P2=0; //Port P2 is the output port
P1=P1&0xf8; //The first three digits of port P1 are used to control which digital tube is lit.
//If it is changed to P1=0xf8, the digital tube may appear
//non-stop display, making it difficult to distinguish the displayed value
for(i=0;i {
P2=table[lp[i]]; //loop display
delay(); //delay five empty instructions
if(i==7) //check whether all 8 digits have been displayed, and exit directly if completed
//Do not let port P1 add one more, otherwise it will affect port P1^4
break;
P2=0; //clear the port and prepare to display the next digit
P1++; //light up the next digital tube
}
}
void delay() //delay sub-function
{
_nop_();_nop_();_nop_();_nop_();_nop_();
}
uchar readad0831() //This function is written according to the protocol of ADC0831
{
uchar i=0,tmp=0;
sda1=1;
cs1=0; _nop_ (
);
_nop_();
scl1=0; _nop_(); _nop_ (); scl1=1; _nop_ (); _nop_ (); scl1=0; _nop_(); _nop_(); scl1=1; _nop_(); _nop_(); scl1=0; _nop_(); _nop_(); for(i=0;i<8;i++) { tmp<<=1; if(sda1) tmp++; scl1=1;




















_nop_();
_nop_();
scl1=0;
_nop_();
_nop_();
}
cs1=1;
return tmp;
}
If the program does not compile, remove all leading spaces.

Keywords:ADC0831 Reference address:ADC0831 analog-to-digital conversion program

Previous article:ADC0831 voltmeter program with digital tube display
Next article:Keyboard scanning-digital tube incremental display program

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号