Realize the countdown board display from 9 to 0 in 8×8 dot matrix based on C language

Publisher:TP9111Latest update time:2020-05-08 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Based on C language, a countdown board display from 9 to 0 is realized in 8×8 dot matrix.


There is a 1 second interval between each number, which is implemented using a timer.


#include


sbit ADDR0 = P1^0;

sbit ADDR1 = P1^1;

sbit ADDR2 = P1^2;

sbit ADDR3 = P1^3;

sbit ENLED = P1^4;


code unsigned char image[10][8]={

{0xFF,0xC3,0xDB,0xDB,0xC3,0xDF,0xDF,0xC3}, //When the number 9 is to be displayed, the value of P0

{0xFF,0xC3,0xDB,0xDB,0xC3,0xDB,0xDB,0xC3},

{0xFF,0xC3,0xDF,0xDF,0xDF,0xDF,0xDF,0xDF}, //When the number 7 is to be displayed, the value of P0

{0xFF,0xFB,0xFB,0xFB,0xC3,0xDB,0xDB,0xC3},

{0xFF,0xC3,0xFB,0xFB,0xC3,0xDF,0xDF,0xC3},

{0xFF,0xDB,0xDB,0xDB,0xC3,0xDF,0xDF,0xDF},

{0xFF,0xC3,0xDF,0xDF,0xC3,0xDF,0xDF,0xC3},

{0xFF,0xC3,0xDF,0xDF,0xC3,0xFB,0xFB,0xC3},

{0xEF,0xE7,0xE3,0xE7,0xE7,0xE7,0xE7,0x81},

{0xFF,0xC3,0xDB,0xDB,0xDB,0xDB,0xC3,0xFF}

};


void main()

{

ENLED = 0; //Enable dot matrix

ADDR3 = 0;  


EA = 1; // Enable interrupt

ET0 = 1;   


TMOD = 0x01; //Timer initialization

TH0 = 0xFC;

TL0 = 0x67;

TR0 = 1;    


while(1);

}


void InterrupTimer0() interrupt 1

{

static unsigned long cnt = 0; //ms count

static unsigned char sec = 0; //s count

static unsigned char i = 0; //dot matrix row number


TH0 = 0xFC; //Reassign the timer to ensure that each time is 1ms

TL0 = 0x67;


cnt++;

if(cnt>=1000)

{

cnt = 0;

sec++;

if(sec>9)

{

sec = 0;

}


}


P0 = 0xFF; //Blanking

switch(i)

{

case 0 : ADDR2 = 0;ADDR1 = 0;ADDR0 = 0;i++;P0 = image[sec][0];break;

case 1 : ADDR2 = 0;ADDR1 = 0;ADDR0 = 1;i++;P0 = image[sec][1];break;

case 2 : ADDR2 = 0;ADDR1 = 1;ADDR0 = 0;i++;P0 = image[sec][2];break;

case 3 : ADDR2 = 0;ADDR1 = 1;ADDR0 = 1;i++;P0 = image[sec][3];break;

case 4 : ADDR2 = 1;ADDR1 = 0;ADDR0 = 0;i++;P0 = image[sec][4];break;

case 5 : ADDR2 = 1;ADDR1 = 0;ADDR0 = 1;i++;P0 = image[sec][5];break;

case 6 : ADDR2 = 1;ADDR1 = 1;ADDR0 = 0;i++;P0 = image[sec][6];break;

case 7 : ADDR2 = 1;ADDR1 = 1;ADDR0 = 1;i=0;P0 = image[sec][7];break;

default : break;

}

}

Reference address:Realize the countdown board display from 9 to 0 in 8×8 dot matrix based on C language

Previous article:51 single chip microcomputer course design - LED dot matrix billboard program design
Next article:MCU Example---Timer Control Dot Matrix Display 0~9

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号