⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo.c

📁 嵌入式下实验的新的驱动设计源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "/usr/src/arm/linux/include/asm/unistd.h"#include "/arm_linux_root/ll/new/lcd.h"#include <stdio.h>#include <stdlib.h>extern int errno;vline_t   m_vline;textout_t  m_textout;chinese_t m_chinese;int value=0;int color=2;int fd;int rt;unsigned char *s[16]={ "1--new",                       "2--draw a line",                       "3--draw a rectangle",                       "4--draw a circle",                       "5--display keyvalue",                       "6--display a moving",                       "7--clean",                       "8--display chinese",                       "9--draw random",                       "10--up",                       "11--change color",                       "12--enter",                       "13--left",                       "14--down",                       "15--right",                       "16--return"};int clean(){        if ((fd = open("/dev/LCD", 0)) < 0) {             printf("cannot open /dev/LCD\n");             exit(0);        }        rt = ioctl(fd, 2);        close(fd);}lcd_fillrect ( int x, int y, int x1, int y1,int c){        int xt, xf;        int tmp, w, h;               if (x1 < x)        {                tmp = x;                x = x1;                x1 = tmp;        }        if (y1 < y)        {                tmp = y;                y = y1;                y1 = tmp;        }        w = x1 - x + 1;        h = y1 - y + 1;        xf = x * 12 / 8;        xt = (x + w - 1) * 12 / 8;        if ((fd = open ("/dev/LCD", 0)) < 0)        {                printf ("cannot open /dev/LCD\n");                exit (0);        }        for (w += x; x < w; x++)        {           m_vline.x = x;           m_vline.y1 = y;           m_vline.y2 =y1;           m_vline.c = c;           m_vline.xorm = 1;           rt = ioctl (fd, 5, &m_vline);        }        close(fd);        return 0;}lcd_bigpixel (short x, short y){    lcd_fillrect (x - 1, y - 1, x + 1, y + 1,color);    return 0;}int rudder(int x,int y,int c,int i){          int conx;        int cony;        if(i==0)             {               conx=x-10;            cony=y-20;            lcd_fillrect(x, y, conx, cony,c);       }       else        {            lcd_bigpixel(x, y);       }	    return 0;}    /* 定位光标*/int line(double x1,double y1,double x2,double y2){        int i;        double j;        double a,b,a1,b1,tmp;        a=x2-x1;        b=y2-y1;        if (a<0)  a1=-a;        else      a1=a;        if (b<0)  b1=-b;        else      b1=b;        if (a1==0)        {                 for (i=0;i<b1;i++)             {                  lcd_bigpixel(x1, y1);                 if (b>=0) y1++;                 else      y1--;             }         }        else if (b1==0)        {                 for (i=0;i<a1;i++)             {                 lcd_bigpixel(x1, y1);                 if (a>=0) x1++;                 else      x1--;             }        }         else         {              if (a1>b1)           {                j=b1/a1;                for (i=0;i<a1;i++)               {                 lcd_bigpixel(x1, y1);                 if (a>0 && b>0)        { x1++; y1=y1+j; }                 else if (a<0 && b<0)   { x1--; y1=y1-j; }                 else if (a<0 && b>0)   { x1--; y1=y1+j; }                 else if (a>0 && b<0)   { x1++; y1=y1-j; }               }           }           else           {              j=a1/b1;              for (i=0;i<b1;i++)              {                 lcd_bigpixel(x1, y1);                 if (a>0 && b>0)       { x1=x1+j; y1++; }                 else if (a<0 && b<0)  { x1=x1-j; y1--; }                 else if (a<0 && b>0)  { x1=x1-j; y1++; }                 else if (a>0 && b<0)  { x1=x1+j; y1--; }              }           }         }              /*画斜线*/} float sq(float a){   float x,x1;   int i=0;   x=a/4;   do {         i++;         x1=x;         x=(x1+a/x1)/2;      }   while(i<30 && ((x-x1)>=(1.e-5) || (x-x1)<=(-1.e-5)));   return x;}lcd_ellipse (int x, int y, int a, int b){        int wx, wy;        if (y<a || y>(240-a) || x<a || x>(320-a))           return 0;        lcd_bigpixel(x, y+a);        lcd_bigpixel(x, y-a);        lcd_bigpixel(x+a, y);        lcd_bigpixel(x-a, y);        for(wx=0,wy=0;wy<=sq(2)*a/2;wy++)          {                 wx=sq(a*a-wy*wy);                 lcd_bigpixel(x-wx, y+wy);                 lcd_bigpixel(x-wx, y-wy);                 lcd_bigpixel(x+wx, y+wy);                 lcd_bigpixel(x+wx, y-wy);          }        for(wx=0,wy=0;wx<=sq(2)*a/2;wx++)          {                 wy=sq(a*a-wx*wx);                 lcd_bigpixel(x-wx, y+wy);                 lcd_bigpixel(x-wx, y-wy);                 lcd_bigpixel(x+wx, y+wy);                 lcd_bigpixel(x+wx, y-wy);          }        return 0;}int circle(double x1,double y1,double x2,double y2)  //draw a circle.{               float x,y,d;        d=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);        x=(x1+x2)/2;        y=(y1+y2)/2; 	lcd_ellipse(x,y,sq(d)*0.5,sq(d)*0.5);}        int english(unsigned char *s,int x,int y){    if ((fd=open("/dev/LCD",0)) <0)        {printf("cannot open /dev/LCD\n");         exit(0);        };    m_textout.x=x;    m_textout.y=y;    m_textout.buf=s;    ioctl(fd,3, &m_textout);    close(fd);}int menu()                               {     clean();     color=2;     value=0;     lcd_fillrect(0, 180, 320, 240,color);     english("file", 50,40);     english("direction",120,40);     english("function",240,40);     english("Compute Science",100,140);     english("Beijing Institute of Technology",50,180);     english("ARM-0201",120,100);}int lcdlin(int n){    if ((fd=open("/dev/LCD",0)) <0)        {printf("cannot open /dev/LCD\n");         exit(0);        };    rt=ioctl(fd,2);    if(n>0 && n<=9)    {        n=n+48;        m_textout.x=100;        m_textout.y=100;        m_textout.buf="keyValue=";        *(m_textout.buf+9)=n;     }     else if(n>9 && n<17)     {        n=n+38;        m_textout.x=100;        m_textout.y=100;        m_textout.buf="keyValue=1";        *(m_textout.buf+10)=n;      }     ioctl(fd,3, &m_textout);     close(fd);}      /*  在lcd上打印出KeyValue=n   */int moving(int ss){   int a,b;   int x=200;   int y=100;   unsigned char *s="Welcome to BIT !";   value =0;   for(;;)   {        if(x<1)  x+=320;         english(s,x,y);         for(a=0;a<200;a++)            for(b=0;b<200;b++){}         x--;         value = ioctl(ss,0,0);        if(value == 6) break;   }}int chinese1(){        FILE *fp;        char buffer[32], bufconvert[32];        char src[32];        char dst[32];        unsigned char *s = "北京理工大学信息工程学院";        int i;        unsigned char qh, wh;        int rt;        int fd;        unsigned long offset;        int MoveByte;        unsigned char temp;        if ((fd = open ("/dev/LCD", 0)) < 0)        {                printf ("cannot open /dev/LCD\n");                exit (0);        }        rt=ioctl(fd,2);        if ((fp = fopen ("/var/nfs/hzk", "rb")) == NULL)        {                printf ("Can't open hzk16,Please add it");                return 0;        }        m_chinese.x0 = 250;        m_chinese.y0 = 120;        m_chinese.width = 16;        m_chinese.height = 16;        m_chinese.xorm = 1;        while (*s)        {                qh = *(s) - 0xa0;                wh = *(s + 1) - 0xa0;                offset = (94 * (qh - 1) + (wh - 1)) * 32L;                fseek (fp, offset, SEEK_SET);                fread (buffer, 32, 1, fp);                for (i = 0; i < 32; i = i + 2)                {                        src[i] = buffer[i + 1];                }                for (i = 1; i < 32; i = i + 2)                {                        src[i] = buffer[i - 1];                }                for (i = 0; i < 32; i++)                {                        for (MoveByte = 0; MoveByte < 8; MoveByte++)                        {                                if (src[i] & (0x01 << MoveByte))                                {                                        temp = 0x01 << (7 - MoveByte);                                }                                else                                {                                        temp = 0x00;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -