51 MCU serial communication Bad Apple video playback source program (LCD12864 display)

Publisher:未来感知Latest update time:2020-01-23 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The program originated from a competition project of my team. The project file is a large project with a lot of content written by other team members. It is not easy for me to post it directly, so I had to capture a small module I wrote and put it up for everyone to share.

This program can mainly realize the two functions of "arbitrary image display" and "arbitrary video playback". The data is transmitted through the serial port (baud rate 4800, Bluetooth or USB are OK). Of course, the data sent can only be the processed image modulus data. (LCD driver is st7920)

After power-on, the following image is displayed directly:
Send 53 FF (sent in hexadecimal) to use the preset for displaying a single image. Then send the modulo data through the serial port to display the image in real time.
 

 
After displaying the image, send 01 0E to jump back to the ready state (if you cannot exit, send 01 0E in a timed loop).

If you send 53 53 in the ready state, you can play the video stream. At this time, just send the frame-by-frame modulo code of the video stream through the serial port.


The attached compressed file contains the Bad Apple BIN file I made for your reference.
 
Since my crystal oscillator is 12MHz, the baud rate is set to 4800, and the actual playback speed is 1 frame/second. You can also change the timer parameters to increase the baud rate.


After the video is finished playing, send 01 0E in the same loop to return to the ready state.

The main function code is shown below, and the other codes are in the attachment.
#include
typedef unsigned int u16; //declare and define data types
typedef unsigned char u8;
#define tbuf 25
u8 RX_buffer[tbuf]={0}; //global string array, serial port receive buffer, used to record information sent by Bluetooth serial port
u8 RX_num=0; //number of characters received by Bluetooth
u8 RX_value=0; //value returned after Bluetooth function processing
#include "delay service.h"
#include "driver of LCD12864.h"        
#include "bluetooth.h"
#include "resource.h"

void init()
{
        SCON=0X50; //set to working mode 1
        TMOD=0X20; //set counter working mode 2
        PCON=0X80; //double the baud rate
        TH1=0XF3; //set the initial value of the counter, note that the baud rate is 4800
        TL1=0XF3;
        ES=1; //Open receive interrupt
        EA=1; //Open total interrupt
        TR1=1; //Open counter



void main()
{
   init(); //Infrared, Bluetooth initialization
   Initialization(); //LCD initialization
   Screen_Clear();

        while(1)
        {
    unsigned char j=0,k=0,l=0,m_flag=0;
        RX_buffer[1]=0;
        Write_Instruction(0x01);
        Display_Text(0x80,text16);
        Display_Text(0x98,text15);
        while(RX_buffer[1]==0);//Condition to jump out of this mode
        Write_Instruction(0x01);
        if(RX_buffer[1]==0xFF) //Send 0x53 0xXX (XX means any, except 01, FF) for default video playback mode, send 0x53 0xFF for picture display mode
        {
           m_flag=1;
        }
        RX_num=1;
        while((RX_buffer[1] != 0x01) || (RX_buffer[2] != 0x0E))//Send 0x01 0x0E Exit
        {
        while((j != 32) || (l != 1))
        {
           Write_Instruction(0x36);
           while(RX_num != 17);
           if((RX_buffer[1]==0x01) && (RX_buffer[2])==0x0E) break;
           if((l==0) && (j==32))
           {
              l=1;
                  j=0;
           }
           Write_Instruction(0x80+j);
           if(l==0)
           {
              Write_Instruction(0x80);
           }
           else
           {
              Write_Instruction(0x88);
           }
           for(k=1;k<17;k++)
           {
              Write_Data(RX_buffer[k]);
           }
           j++;
           RX_num=1;
        }
        if(m_flag==1)
        {
           RX_buffer[1]=0x01;
           RX_buffer[2]=0x0E;
        }
        j=0;
        l=0;
        }

        RX_num=0;//Receive array index points to instruction bit

        RX_buffer[0]=0;
        while(RX_buffer[0]==0);
        Screen_Clear(); 
}
}

Reference address:51 MCU serial communication Bad Apple video playback source program (LCD12864 display)

Previous article:STC15 serial port 1\serial port 2\serial port 3 and serial port 4 source code
Next article:ds1302 driver + lcd12864 serial display, using structure writing, more readable

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号