zoukankan      html  css  js  c++  java
  • 嵌入式LCD12232点阵研究

    简述:

    这两天在学嵌入式的开发与设计,一切从新开始,从头开始。今天在我的那块实验板上,搞了那个LCD12232点阵的显示

    可是在网上一搜,却没有相关的软件进行简易的计算。每次为了显示一个字,各种算,各种纠结。随想到了自己开发一款小软件

    实验平台:

     1.UP-Magic2410

     2.模块:LCD12232

    LCD12232点阵字库计算器

    1.使用说明:

    只需要在软件上画出欲显示的图形,下面就将计算出相应的十六进制。挂载进开发板,便可以显示。

    2.代码(C#):

    using System;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace 点阵生成12232
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                initFrame();
            }
    
            int pX = 0; //控件的XY坐标
            int pY = 0;
            Control pOld = null;    //记录控件的老状态
            GroupBox groupBoxControl = new GroupBox();
            int[,] allData = new int[16,16];
    
            /// <summary>
            /// 初始化
            /// </summary>
            private void initFrame()
            {
                pX = 15;
                pY = 18;
                pOld = null;
                //this.Size = new System.Drawing.Size(350,500);
                createButton();
            }
    
            /// <summary>
            /// 创建16*16按钮
            /// </summary>
            private void createButton()
            {
                groupBoxControl.AutoSize = true;
                groupBoxControl.Text = "操作框";
                groupBoxControl.Location = new Point(12, 10);
                for (int i = 0; i < 16; i++)
                {
                    for (int j = 0; j < 16; j++)
                    {
                        allData[i, j] = 0;
                        Button btnCreate = new Button();
                        btnCreate.FlatStyle = FlatStyle.Flat;
                        btnCreate.Text = "0";
                        btnCreate.Name = i.ToString() + j.ToString(); ;
                        btnCreate.BackColor = Color.White;
                        btnCreate.Width = 20;
                        btnCreate.Height = 20;
                        btnCreate.Location = new Point(pX, pY);
                        btnCreate.MouseMove += new MouseEventHandler(mouseMove);
                        btnCreate.MouseEnter += new EventHandler(mouseEnter);
                        btnCreate.MouseLeave += new EventHandler(mouseLeave);
                        pX += 20;
                        btnCreate.Parent = groupBoxControl;
                    }
                    pX = 15;
                    pY += 20;
                }
                Controls.Add(groupBoxControl);
            }
            /// <summary>
            /// 切换按钮状态
            /// </summary>
            private void changeBtnState(Control pControl)
            {
                if (int.Parse(pControl.Text) == 0)
                {
                    pControl.Text = "1";
                    pControl.BackColor = Color.Black;
                    pControl.ForeColor = Color.Red;
                }
                else
                {
                    pControl.Text = "0";
                    pControl.BackColor = Color.White;
                    pControl.ForeColor = SystemColors.ControlText;
    
                }
            }
            /// <summary>
            /// 清除现有状态
            /// </summary>
            private void clearState()
            {
                foreach (Control c in groupBoxControl.Controls)
                {
                    if (c.Name != "btnCalc" && c.Name != "btnClear")
                    {
                        c.Text = "0";
                        c.BackColor = Color.White;
                        c.ForeColor = SystemColors.ControlText;
                        allData = null;
                        allData = new int[16,16];
                        tbxResult.Text = "请重新选择计算";
                    }
                }
            }
            //计算4个数之间的数
            private int getBetweenFour(int i)
            {
                if(i>=0&&i<4)
                    return 0;
                else if(i>=4&&i<8)
                    return 1;
                else if(i>=8&i<12)
                    return 2;
                else
                    return 3;
            }
            //计算最终结果
            private string calcResult()
            {
                string strResult = "" ;
                int[,] sum = new int[4,16];
                for (int i = 0; i < 16; i++)
                {
                    for (int j = 0; j < 16; j++)
                    {
                        foreach (Control c in groupBoxControl.Controls)
                        {
                            if (c.Name != "btnCalc" && c.Name != "btnClear")
                            {
                                if (c.Name.Equals(i.ToString() + j.ToString()))
                                {
                                    allData[i, j] = int.Parse(c.Text);
                                   // Console.Write(allData[i, j].ToString());
                                }
                            }
                        }
                    }
                }
                for (int i = 0; i < 16; i++)
                {
                    for (int j = 0; j < 16; j++)
                    {  
                        int x=getBetweenFour(i);
                        switch (i%4)
                        {
                            case 0:
                                sum[x,j] += allData[i,j];
                                break;
                            case 1:
                                sum[x,j] += allData[i, j] * 2;
                                break;
                            case 2:
                                sum[x,j] += allData[i, j] * 4;
                                break;
                            case 3:
                                sum[x,j] += allData[i, j] * 8;
                                break;
                        }
                    }                
                }
                string[,] tem = new string[4,16];
                string[] a = new string[16];
                string[] b = new string[16];
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 16; j++)
                    {
                        tem[i,j] = sum[i, j].ToString("X");
                        Console.Write(tem[i, j]);
                    }
                    Console.WriteLine();
                }
                for (int i = 3;i >= 0; i--)
                {
                    for (int j = 0; j < 16; j++)
                    {
                        if (i > 1)
                            a[j] += tem[i, j];
                        else
                            b[j] += tem[i, j];
                    }
                }
                for (int i = 0; i < 16; i++)
                {
                    strResult += "0x" + b[i] + ",";
                }
                strResult += "\r\n";
                for(int i=0;i<16;i++)
                {
                    strResult += "0x"+a[i]+",";
                }         
                return strResult;             
                        
            }
    
            void mouseEnter(object sender, EventArgs e)
            {
                this.Capture = true;
            }
            void mouseLeave(object sender, EventArgs e)
            {
                this.Capture = false;
            }        
            void mouseMove(object sender, MouseEventArgs e)
            {
                Control pControl = sender as Control;            
                if (pOld!=pControl&&e.Button==MouseButtons.Left)
                {
                    pOld = pControl;
                    changeBtnState(pControl);
                }
            }
    
            private void btnCalc_Click(object sender, EventArgs e)
            {
                tbxResult.Text=calcResult();
            }
    
            private void btnClear_Click(object sender, EventArgs e)
            {
                clearState();
            }
    
            private void btnCopy_Click(object sender, EventArgs e)
            {
                if (!string.IsNullOrEmpty(tbxResult.Text))
                {
                    Clipboard.SetText(tbxResult.Text);
                    MessageBox.Show("数据复制成功");
                }
                else
                {
                    MessageBox.Show("文本框数据为空");
                }
            }
        }
    }
    


     

    3.功能截图:

    4.下载地址:

    汗,就在CSDN的资源里,现在估计还在审核。名称:“LCD12232点阵计算器”

    点阵显示:

     

    开发板部分相关程序:

    #include <stdio.h>
    #include <stdlib.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include "lcd.h"
    
    unsigned char uptech_logo_for_Gray_LCD_1[]=
    {
    /*------------------------------------------------------------------------------
    每两行一个字符
    ------------------------------------------------------------------------------*/
    0xF0,0x18,0x0C,0xC4,0x76,0x12,0x1A,0xC3,0xC1,0x09,0x33,0x62,0xC6,0x0C,0x18,0xF0,
    0x0F,0x18,0x30,0x60,0xC0,0x80,0x80,0x89,0x88,0x80,0x80,0xC0,0x40,0x60,0x38,0x0F,
    0x10,0x10,0xF0,0xFF,0xF0,0x90,0x50,0x50,0x60,0x10,0x1C,0x97,0x30,0x60,0xC0,0x80,
    0x18,0x0C,0x03,0x7F,0x00,0x03,0x26,0x38,0x2C,0x26,0x23,0x31,0x10,0x1C,0x38,0x20,
    0x00,0x80,0xC0,0x60,0xF8,0x0E,0x00,0x08,0x08,0xC8,0xE8,0x28,0x38,0x10,0x00,0x00,
    0x00,0x01,0x00,0x00,0x7F,0x01,0x01,0x01,0x01,0x61,0x7F,0x01,0x01,0x01,0x01,0x00,
    0x00,0x00,0x00,0xE0,0xA0,0xA0,0xBF,0xA4,0xA4,0xA4,0xA4,0xE0,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x13,0x12,0x12,0x12,0xFE,0x12,0x12,0x12,0x03,0x00,0x00,0x00,0x00,
    
    };
    
    unsigned char uptech_logo_for_Gray_LCD_2[]=
    {
    /*------------------------------------------------------------------------------
    
    ------------------------------------------------------------------------------*/
    0x00,0x00,0x00,0x00,0x20,0x21,0x36,0x1C,0xC8,0x18,0x3C,0x64,0xC0,0x00,0x00,0x00,
    0x00,0x00,0x00,0x42,0x42,0x62,0x3A,0x02,0xFF,0x02,0x0A,0x12,0x62,0x40,0x00,0x00,
    0x00,0x00,0x00,0x00,0xFC,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,
    0x00,0x00,0x20,0x30,0x1F,0x00,0x00,0x00,0x0F,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,
    0x00,0x80,0x81,0x85,0x9D,0x95,0x95,0x95,0x9D,0x81,0xC1,0xFF,0x81,0x81,0x80,0x00,
    0x00,0x00,0x00,0x1E,0x12,0x12,0x12,0x12,0x12,0x5E,0x40,0xFF,0x00,0x00,0x00,0x00,
    0xE0,0x38,0x0C,0xC6,0x62,0x22,0x43,0x01,0x03,0xE2,0x22,0x6E,0x58,0x30,0xE0,0x80,
    0x0F,0x38,0xE0,0xC0,0xC0,0xCC,0xC8,0xC8,0xC8,0xCC,0xC4,0xC0,0xC0,0x60,0x38,0x0F,
    };
    int main(void)
    {
    	int fd;
    	int i,j,k;
    	i=8;
    
    	fd=open("/dev/S3C2410_SPI0",O_RDWR);
    	if(fd < 0){
    		printf("####spi  device open fail####\n");
    		return (-1);
    	}
    	Gray_LCD_Init(fd);
               Gray_LCD_Clear(fd);
                   for(i=8,j=0;i<123;i=i+30,j=j+32)
                   {
    
    		Gray_LCD_Standard_Signal_Word(fd,i,Gary_LCD_Page0 ,uptech_logo_for_Gray_LCD_1+j);
        Gray_LCD_Standard_Signal_Word(fd,i,Gary_LCD_Page2 ,uptech_logo_for_Gray_LCD_2+j);
                 
                   
                    }
    	close(fd);
    	return 0;
    
    }
    
    
    
    


    最后总结:

    呃,本人亦属初学,代码凌乱的地方也请多多见谅。

  • 文章声明
  • 作者:Owen
  • 出处: http://www.cnblogs.com/owenyang
  • 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。该博客同步发在 HEXO-博客
查看全文
  • 相关阅读:
    【已解决】github中git push origin master出错:error: failed to push some refs to
    好记心不如烂笔头,ssh登录 The authenticity of host 192.168.0.xxx can't be established. 的问题
    THINKPHP 5.0目录结构
    thinkphp5.0入口文件
    thinkphp5.0 生命周期
    thinkphp5.0 架构
    Django template
    Django queryset
    Django model
    Python unittest
  • 原文地址:https://www.cnblogs.com/owenyang/p/3579078.html
  • Copyright © 2011-2022 走看看