12864 (st7920 controller) drawing points and lines subroutine

Publisher:mb5362443Latest update time:2016-10-30 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
/*------------------ Draw point subroutine-----------------------------*/
//XY is the expected coordinate system (X:0-127, Y:0-63 in grids), Color 0 is off, 1 is on, 2 is flipped
void DrawPoint(unsigned char X,unsigned char Y,unsigned char Color)
{
    unsigned char Row,Tier,Tier_bit ;
    unsigned char ReadOldH,ReadOldL ;
    wr_comm(0x34); // Select extended instructions and turn off display
    wr_comm(0x36); // Select extended instructions, turn on display
    Tier=X>>4 ; // Shift right 4 bits, that is, divide by 16 and round to the integer, to get the horizontal coordinate DX corresponding to the 12864 to be written
    Tier_bit=X&0x0f ; // Get the number of the x in the DX (0-15), the high 4 bits of 0x0f are all 0,
                       // Bitwise AND eliminates the high 4 bits of X, which is equivalent to X%16, and obtains the number of bits in DX.
    if(Y<32)
    {
        Row=Y ;
    }
    else //y coordinate is greater than 31, to display on the screen, DX also adds 8 accordingly
    {
        Row=Y-32 ;
        Tier+=8 ;
    }
    wr_comm(Row+0x80); //Write (on the LCD) vertical coordinate (page coordinate)
    wr_comm(Tier+0x80); //Write (on the LCD) horizontal coordinate (column coordinate)
    ReadByte(); // Pre-
    readReadOldH=ReadByte(); //Read the data in the GDRAM at this location, the upper 8
    bitsReadOldL=ReadByte(); //low 8
    bitswr_comm(Row+0x80);
    wr_comm(Tier+0x80);
    if(Tier_bit<8) //x is in the lower 8 bits in DX (according to the expected coordinates), but belongs to the upper 8 bits in the LCD internal coordinate system, corresponding to ReadOldH
    {
        switch(Color)
        {
            case 0 : ReadOldH&=(~(0x01<<(7-Tier_bit))); break ; //bit conversion LCD corresponding bit
            case 1 : ReadOldH|=(0x01<<(7-Tier_bit)); break ; //set the specific position to 1 and light up
            case 2 : ReadOldH^=(0x01<<(7-Tier_bit)); break ; //bitwise XOR flip specific bit
            default : break ;
        }
        wr_data(ReadOldH); //write the upper 8 bits first
        wr_data(ReadOldL);
    }
    else
    {
        switch(Color)
        {
            case 0 : ReadOldL&=(~(0x01<<(15-Tier_bit))); break ;
            case 1 : ReadOldL|=(0x01<<(15-Tier_bit)); break ;
            case 2 : ReadOldL^=(0x01<<(15-Tier_bit)); break ;
            default : break ;
        }
        wr_data(ReadOldH);
        wr_data(ReadOldL);
    }
    wr_comm(0x30); //Set the basic instruction set to turn off drawing display
}
//Draw horizontal line:
void DrawLineX( unsigned char X0, unsigned char X1, unsigned char Y, unsigned char Color )
{ unsigned char Temp ;
    if( X0 > X1 )
    {
        Temp = X1 ;
        X1 = X0 ;
        X0 = Temp ;
    }
    for( ; X0 <= X1 ; X0++ )
    DrawPoint( X0, Y, Color ) ;
}
//Draw vertical line:
void DrawLineY( unsigned char X, unsigned char Y0, unsigned char Y1, unsigned char Color )
{
    unsigned char Temp ;
    if( Y0 > Y1 )
    {
        Temp = Y1 ;
        Y1 = Y0 ;
        Y0 = Temp ;
    }
    for(; Y0 <= Y1 ; Y0++)
    DrawPoint( X, Y0, Color) ;
}
//Use Bresenham line drawing algorithm
void DrawLine_any( unsigned char StartX, unsigned char StartY, unsigned char EndX, unsigned char EndY, unsigned char Color )
{
    int t, distance; /*Change variable type according to screen size (such as int type)*/
    int x = 0 , y = 0 , delta_x, delta_y ;
    char incx, incy ;
    delta_x = EndX - StartX ;
    delta_y = EndY - StartY ;
    if( delta_x > 0 )
    {
        incx = 1;
    }
    else if( delta_x == 0 )
    {
        DrawLineY ( StartX, Start delta_x > delta_y ) {     distance = delta_x ; } else     {         distance     = delta_y     ;     }     DrawPoint     (
        StartX         ,     StartY         ,     Color         ) ; /* Draw Line*/     for     (     t     =     0     ;     t     <     =         distance     +     1 ; t++ )     {     DrawPoint( StartX, StartY         , Color ) ;     x     +     =         delta_x ;         y         +         = delta_y ;         if( x > distance )         {             x -= distance ;             StartX += incx ;         }         if( y > distance )         {             y -= distance ;             StartY += incy ;         }     } }














































Reference address:12864 (st7920 controller) drawing points and lines subroutine

Previous article:Design of cable joint temperature monitoring system terminal based on wireless technology
Next article:51 MCU drives PS2 keyboard complete program

Recommended ReadingLatest update time:2024-11-17 00:54

Single chip microcomputer controls 12864 to display multiple lines of Chinese characters
PROTEUS simulation circuit diagram: Simulation experiment results show: Chinese character modeling process (software download link is at the end of the article): Step 1: Open the LCD simulation layout software Set relevant parameters: Input Chinese characters: Save the image somewhere: Step 2: Open the
[Microcontroller]
Single chip microcomputer controls 12864 to display multiple lines of Chinese characters
C0851F410 and 12864 LCD display
#include "C8051F410.h" #define uchar unsigned char #define LCMdata P2 #define Busy 0x80 sbit RS = P1^3; sbit RW = P1^4; sbit E = P1^5; sbit PSB = P1^6; sbit REST= P0^7; //sfr16 TMR2RL = 0xCA; // Timer2 Reload Register //sfr16 TMR2 = 0xCC; void Display_String(uchar line,uchar *string); void Wr_Data(uchar wrda
[Microcontroller]
51 single chip electronic calendar (adjustable with temperature) DS1302 clock + 12864 LCD display
The 51 MCU display time (adjustable) (DS1302 clock + 12864 LCD display) can be connected according to the program. The simulation schematic diagram is as follows: The MCU source program is as follows: /********************************************/ /* Electronic calendar with temperature display */ /***************
[Microcontroller]
51 single chip electronic calendar (adjustable with temperature) DS1302 clock + 12864 LCD display
Nuvoton M051 drives LCD12864 LCD screen program
Share a C language program for the Xintang M051 microcontroller to drive the LCD12864 LCD screen with font library:  #include "SmartM_M0.h"   #define LCD12864_RS_PIN   0 #define LCD12864_RW_PIN   1 #define LCD12864_EN_PIN   2 #define LCD12864_MD_PIN   3   #define LCD12864_RS(x)     {if((x))P0_DOUT|=  1
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号