Yl236 digital tube adc0809c Language

Source: Internet
Author: User

/////////////////////////////////////
//
// At89s52 adc0809 Digital Display
// Author: Yan Jianhua QQ: 10772919
// Jiangsu Nantong Technician College
// 2014.5.28
//
////////////////////////////////////
Sfr P0 = 0x80; // digital segment code, adc0809 data end
Sfr P2 = 0xa0; // control Foot
// Digital control pin definition, wr, cs changed from 0 to 1 valid
Sbit cs1 = P2 ^ 0; // field code
Sbit cs2 = P2 ^ 1; // bit code
Sbit wr = P2 ^ 2; // clock
// Adc0809 control pin Definition
Sbit adc_eoc = P2 ^ 3; // conversion completed = 1, unfinished = 0
Sbit adc_cs = P2 ^ 4; // can be directly grounded = 0
Sbit adc_rd = P2 ^ 5; // oe = ~ (Rd | cs)
Sbit adc_wr = P2 ^ 6; // start = ale = ~ (Wr | cs)
// Variable definition
Unsigned long int v; // voltage value
Unsigned char v2; // Save the adc result
// Latency Function
Void ys (unsigned x)
{
Unsigned char I;
While (x --) for (I = 0; I <120; I ++ );
}
// Adc Conversion Function
Adc ()
{
// Prepare
Adc_eoc = 1; // set the conversion end flag.
Adc_rd = 1; // disable the bus to prevent digital tube interference
Adc_wr = 1; // write prohibited
Adc_cs = 0; // cs simultaneously controls wr and rd and can be directly grounded.
// Start the conversion
Adc_wr = 0; // set the channel number, the ale High-Level Lock channel address, and the start rising edge is reset.
Adc_wr = 1; // start Conversion
While (adc_eoc = 0); // The conversion ends at a high level.
Adc_rd = 0; // oe high level allow output
// Read the result
P0 = 0xff; // P0 serves as the input end
V2 = P0; // read the Conversion Result
Adc_rd = 1; // disable the bus to prevent digital tube interference
}
// 8-bit common Yang digital display function
Xianshi ()
{
Unsigned char code DSY_CODE [] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99,0x92,0x82, 0xf8, 0x80, 0x90, 0xff, 0xbf}; // segment code
Unsigned char I;
V = (unsigned long int) v2 * 5000/255; // The row must be forcibly converted
// Scan from right to left and from the second bit
For (I = 0; I <8; I ++)
{
// Bit Elimination
P0 = 0xff; // close
Cs2 = 0; // bit valid
Wr = 0; wr = 1; // clock
Cs2 = 1; // The bit is invalid.
// Send the field code
P0 = DSY_CODE [v % 10]; // send a field code
Cs1 = 0; // valid segment
Wr = 0; wr = 1; // clock
Cs1 = 1; // The segment is invalid.
// Send location code
P0 = ~ (1 < Cs2 = 0; // bit valid
Wr = 0; wr = 1; // clock
Cs2 = 1; // The bit is invalid.
V/= 10; // scale down v by 10 times for a long time
Ys (1 );
}
}
// Main Function
Main ()
{
While (1)
{
Adc (); // adc Conversion
Xianshi (); // Digital Display
}
}

The following figure shows the simulation principle.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.