Digital tube display program based on AD conversion of single chip microcomputer

Publisher:创意旋律Latest update time:2012-09-25 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

*This example uses the AD0804 chip, hardware circuit: cs chip select terminal connected to P2.3, WR write data terminal write to P3.6, RD read data terminal connected to P3.7, latch terminal connected to P2.6 pin, digital tube bit select terminal connected to P3.2, P3.3, P3.4 respectively, segment select terminal connected to P1 port*/
#include//header file
#define uint unsigned int//macro file
#define uchar unsigned char//macro file
uchar num;//variable
void delay3(uint z);//delay definition
void dissy();//delay function definition
sbit ge=P3^2;//ones digit definition
sbit shi=P3^3;//tens digit definition
sbit bai=P3^4;//hundreds digit definition
sbit ad_cs=P2^3;//chip select terminal
sbit ad_wr=P3^6;//write data terminal
sbit ad_rd=P3^7;//read data end
sbit pian=P2^6;//latch chip select
void add();//ad conversion sub-function
void delay(uint i);//delay sub-function declaration
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,
0x8e
};//array

/************Main function**********/
void main()
{
while(1)
{
add();//Call AD conversion sub-function
dissy();//Digital tube display sub-function
}
}

/************AD conversion sub-function**********/
void add()//AD conversion sub-function
{
uchar i;
ad_cs=1;//turn off the chip selectad_cs
=0;//turn on the chip selectad_wr
=1;//write the rising
edgead_wr=0;//write the falling
edgead_wr=1;//write the rising edge

P1=0xff;//Send number to P0
portad_rd=1;//Read rising
edgedelay(25);//Delay for a whilead_rd
=0;//Read falling edge
//////**************Because the AD conversion time cycle is long, my current digital tube does not use latches, and the AD conversion time is greater than the display time, so it will flicker when displayed. The solution to this problem is to call the display subroutine seven times in succession, so that the display time is consistent with the AD conversion time, and the displayed number will not flicker********************//////
for(i=0;i<7;i++) //Call 7 times, equivalent to delay(255)
void dissy();
//////**************************************//////
num=P1;//Give the number to the counter num
}

/************Display sub-function**********/
void dissy()//Display sub-function
{
P0=table[num/100];//Hundreds display data
bai=0;//Hundreds open
delay(14);//Delay for a while
bai=1;//Close hundreds
P0=table[num%100/10];//Tens display data
shi=0;//Tens open
delay(14);//Delay for a while
shi=1;//Close tens
P0=table[num%10];//Hundreds display data
ge=0;//Close tens
delay(14);//Delay for a while
ge=1;//Close tens
}

/**************Delay sub-function*************/

void delay(uint i) //delay function
{
uint j,k; //define variables
for(j=i;j>0;j--) //outer loop
for(k=30;k>0;k--); //inner loop
}

Reference address:Digital tube display program based on AD conversion of single chip microcomputer

Previous article:Introduction to MB89163 MCU and its application in remote control
Next article:Introduction to programmable active filter circuit based on single chip microcomputer

Recommended ReadingLatest update time:2024-11-17 02:55

C51 dynamic display method of digital tube
Code: #include reg52.h #define uchar unsigned char #define uint unsigned int sbit dula=P2^6; sbit wela=P2^7; uchar num,dunum,wenum; uchar code table_du ={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d, 0x7d,0x07,0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71}; //Digital tube segment selection code uchar code table_we ={ 0xfe,0xfd,0xfb
[Microcontroller]
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号