Summary of C51 digital tube display related issues

Publisher:GoldenSunriseLatest update time:2021-11-25 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Static display of a single digital tube


/*--------------------------

Function: Static display of a digital tube

Author: Zhang Kaizhou

Date: 2019-5-16 21:18:17

--------------------------*/

#include


sbit duan_address = P2^6; // Define segment address as a bit addressable variable

sbit wei_address = P2^7; // Define the bit address as a bit addressing type variable


void main()

{

wei_address = 1; // Open the bit latch

P0 = 0xfe; // Output the position of the digital tube

wei_address = 0; // Turn off the bit latch

duan_address = 1; // Open the segment latch

P0 = 0x7d; // Output the segment code of the common cathode digital tube (6)

duan_address = 0; // Close the segment latch

while(1);

}


2. Dynamic cycle display of digital tube


/*-----------------------------------

Function: Cycle display of 16 characters from 0 to F on the digital tube

Author: Zhang Kaizhou

Date: 2019-5-16 21:41:50

-----------------------------------*/

#include

#define uchar unsigned char

#define uint unsigned int


sbit wei_address = P2^7; // Define a bit-addressable variable wei_address

sbit duan_address = P2^6; // define bit-addressable variable daun_address

uchar num; // define unsigned character variable num

uchar code table[] = {0x3f, 0x06, 0x5b, 0x4f,

  0x66, 0x6d, 0x7d, 0x07,

  0x7f, 0x6f, 0x77, 0x7c,

  0x39, 0x5e, 0x79, 0x71}; // Define an unsigned character array table[] to store the segment code of the common cathode digital tube (0~F characters), which is stored in the ROM or Flash inside the microcontroller


void delay(uint xms);

void main()

{

wei_address = 1; // open latch

P0 = 0x00; // Select the digital tube to be displayed

wei_address = 0; // Close the latch

while(1)

{

for(num = 0; num < 16; num++) // Cycle through the digital tube to display characters 0 to F

{

duan_address = 1; // Open the segment latch of the digital tube

P0 = table[num]; // Output segment code

duan_address = 0; // Close segment latch

delay(1000); // Delay 1000ms = 1s

}

}

}


void delay(uint xms)

{

uint i, j;

for(i = xms; i > 0; i--)

for(j = 110; j > 0; j--);

}


3. Dynamic scanning display of multiple digital tubes


/*-----------------------------------

Function: Dynamically display character information on 4 digital tubes

Author: Zhang Kaizhou

Date: 2019-5-16 21:41:50

-----------------------------------*/

#include

#define uchar unsigned char

#define uint unsigned int


sbit wei_address = P2^7; // Define a bit-addressable variable wei_address

sbit duan_address = P2^6; // define bit-addressable variable daun_address

uchar num; // define unsigned character variable num

uchar code table[] = {0x3f, 0x06, 0x5b, 0x4f,

  0x66, 0x6d, 0x7d, 0x07,

  0x7f, 0x6f, 0x77, 0x7c,

  0x39, 0x5e, 0x79, 0x71}; // Define an unsigned character array table[] and store it in the ROM or Flash inside the microcontroller


void delay(uint xms);

void main()

{

while(1)

{

// Display 0

duan_address = 1;

P0 = table[0];

duan_address = 0;

wei_address = 1;

P0 = 0xfe;

wei_address = 0;

delay(5);

// Display 1

duan_address = 1;

P0 = table[1];

duan_address = 0;

P0 = 0xff; // erase

wei_address = 1;

P0 = 0xfd;

wei_address = 0;

delay(5);

// Display 2

duan_address = 1;

P0 = table[2];

duan_address = 0;

P0 = 0xff; // erase

wei_address = 1;

P0 = 0xfb;

wei_address = 0;

delay(5);

// Display 3

duan_address = 1;

P0 = table[3];

duan_address = 0;

P0 = 0xff; // erase

wei_address = 1;

P0 = 0xf7;

wei_address = 0;

delay(5);

}

}


void delay(uint xms)

{

uint i, j;

for(i = xms; i > 0; i--)

for(j = 110; j > 0; j--);

}

Keywords:C51 Reference address:Summary of C51 digital tube display related issues

Previous article:51 MCU internal timer usage
Next article:LCD1602 dynamic display

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号