The microcontroller drives the dot matrix to flow upward to display the beautiful heart shape of I Love U -Love

Publisher:Blissful444Latest update time:2015-04-30 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The schematic diagram can be downloaded from  http://www.51hei.com/f/ks51.pdf   . The microcontroller model is stc89c51

/**
*Function: The dot matrix flows upward to display I Love U -Love is a beautiful heart shape
*Time: March 10, 2014 16:19:14
*Author: Han Zhuzi
*Remarks: Animation display principle: The animation is formed by 32 pictures, one frame is refreshed every millisecond, and one frame changes every 250ms, for a total of 32 frames.
**/

#include

typedef unsigned int uint;
typedef unsigned char uchar;

//74HC138
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;

//I Love U modulo encoding
uchar code table[] = {/*width 8, height 40*/
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,//Start all black
0xFF,0xC3,0xE7,0xE7,0xE7,0xE7,0xC3,0xFF,//I
0xFF,0x99,0x00,0x00,0x00,0x81,0xC3,0xE7,//heart
0xFF,0x99,0x99,0x99,0x99,0x99,0x81,0xC3,//U
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF//Blanking, remove garbled characters
};

uchar counter = 0, index = 0; //Image refresh index (to refresh 32 images, each with an interval of 250ms)

void timer0_init();
void HC138_init();

void main(void)
{
timer0_init();
HC138_init();

while (1);
}

/********timer0 init**********/
void timer0_init()
{
TMOD |= 0x01; //T1 mode 1
TH0 = 0xFC;
TL0 = 0x67; //Load initial value, timing 1ms
TR0 = 1; //start T0
EA = 1; //Open total interrupt
ET0 = 1; //Open timer T0 interrupt
}

/**********74HC138 init************/
void HC138_init()
{
ADDR3 = 0;
ENLED = 0; // Enable U4
}

/**************timer0 interrupt**************/
void timer0_int() interrupt 1
{
static uchar j = 0; //Used to refresh each frame of the picture, the animation consists of 32 pictures

TH0 = 0xFC;
TL0 = 0x67;//1ms
counter++;//ms++
P0 = 0xFF;//blanking

//Dynamic refresh (refresh each frame)
switch (j)
{
case 0: ADDR2 = 0; ADDR1 = 0; ADDR0 = 0;
break;
case 1: ADDR2 = 0; ADDR1 = 0; ADDR0 = 1;
break;
case 2: ADDR2 = 0; ADDR1 = 1; ADDR0 = 0;
break;
case 3: ADDR2 = 0; ADDR1 = 1; ADDR0 = 1;
break;
case 4: ADDR2 = 1; ADDR1 = 0; ADDR0 = 0;
break;
case 5: ADDR2 = 1; ADDR1 = 0; ADDR0 = 1;
break;
case 6: ADDR2 = 1; ADDR1 = 1; ADDR0 = 0;
break;
case 7: ADDR2 = 1; ADDR1 = 1; ADDR0 = 1;
break ;
default: break;
}
P0 = table[index + j++]; //Dynamically refresh each frame of the picture

if (j >= 8)
{
j = 0;
}

//Change frame
if (counter >= 250)
{
counter = 0;
index++;//Number of frames++
if (index >= 32)
{
index = 0;//Maximum 32 frames of images
}
}
}

Reference address:The microcontroller drives the dot matrix to flow upward to display the beautiful heart shape of I Love U -Love

Previous article:The digital tube of the single-chip microcomputer displays the number of running lights on.
Next article:MCU write LCD1602 liquid crystal program source code

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号