<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

        240128液晶單片機驅動

        作者:浪子   來源:浪子   點擊數:  更新時間:2014年06月10日   【字體:

        方波;

         

        鋸齒波正弦波

         

        #include<AT89X52.H>
        #include <INTRINS.H>
        #include<math.h>
        #define uchar unsigned char
        #define uint  unsigned int
        // 繪圖坐標限制
        #define glcd_XMAX 240
        #define glcd_XMIN 0
        #define glcd_YMAX 128
        #define glcd_YMIN 0
        #define uchar unsigned char
        #define uint  unsigned int
        #define L240DAT P1
        sbit L240CD=P3^3;
        sbit L240RD=P3^4;
        sbit L240WR=P3^5;
        sbit L240BC=P1^0;
        sbit L240BD=P1^1;
        sbit RST=P3^2;
        sbit    CLK=P3^0;
        sbit    DAT= P3^1;
        sbit    CS= P3^7;
         void   L_Delay()
        {
           uchar i;
           for ( i=0; i<48; i++ ) ;
        }
         void  S_Delay()                      //在傳送指令或字節時,CLK要持續8μs的高電平.
        {
            char i;
                for ( i=0; i<8; i++ ) ;
        
        }
        
        /
        void line(int x1, int y1, int x2, int y2, unsigned char show)
        {
         int dy ;
         int dx ;
         int stepx, stepy, fraction;
         dy = y2 - y1;         //Y長度
         dx = x2 - x1;         //X長度
         if (dy < 0)           //Y2<Y1:
         {
          dy = -dy;
          stepy = -1;   //Y負向
         }
         else
         {
          stepy = 1;    //Y正向
         }
         if (dx < 0)
         {
          dx = -dx;     //X負向
          stepx = -1;
         }
         else
         {
          stepx = 1;    //X正向
         }
         dy <<= 1;             //DY左移一位*2
         dx <<= 1;
                if((x2<240&x1>0)|(x1<240&x2>0))
         {writepoint(x1,y1,show);}
         if (dx > dy)
         {
          fraction = dy - (dx >> 1);
          while (x1 != x2)
          {
           if (fraction >= 0)
           {
            y1 += stepy;
            fraction -= dx;
           }
           x1 += stepx;
           fraction += dy;
           writepoint(x1,y1,show);
          }
         }
         else
         {
          fraction = dx - (dy >> 1);
          while (y1 != y2)
          {
           if (fraction >= 0)
           {
            x1 += stepx;
            fraction -= dy;
           }
           y1 += stepy;
           fraction += dx;
           writepoint(x1,y1,show);
          }
         }
                writepoint(x1,y1,show);
        }
        
        void circle(int x, int y, int radius, unsigned char show)
        {
         int xc = 0;
         int yc ;
         int p ;
                clear_graph();
         yc=radius;
         p = 3 - (radius<<1);
         while (xc <= yc)
         {
          writepoint(x + xc, y + yc, show);//在X+XC(圓點附近值最大)上下畫兩個點
          writepoint(x + xc, y - yc, show);
          writepoint(x - xc, y + yc, show);//在X-XC上下畫兩個點
          writepoint(x - xc, y - yc, show);
          writepoint(x + yc, y + xc, show);//在X+YC(最右側數值最小)上下畫兩個點
          writepoint(x + yc, y - xc, show);
          writepoint(x - yc, y + xc, show);//在X-YC(最右側數值最。┥舷庐媰蓚點
          writepoint(x - yc, y - xc, show);
          if (p < 0)
          p += (xc++ << 2) + 6;
          else
          p += ((xc++ - yc--)<<2) + 10;
         }
               Delay(500) ;
        }
        void fangbo (uchar F,int A)                   //周期為T,振幅為A,能顯示240/T個周期
              {  uchar T0;
                 int j=0;
                 clear_graph();
                 l240wc(0x9C);//98開圖,9c開文本和圖,94開文本
                af(A,F);
                T0=1000/F;
                line(00,64,240,64,1);
                for(j=0;j<240/T0;j++)
                { line(j*T0,64-A,(2*j+1)*T0/2,64-A,1);
                  line((2*j+1)*T0/2,64+A,(j+1)*T0,64+A,1);
                  }
                   }
        void juchibo(uchar F,int A)
           {  int i=0;
              float T0;
              clear_graph();
              l240wc(0x9c);
               T0=1000/F;
                af(A,F);
              line(00,64,240,64,1);
              for(i=0;i<240/T0;i++)
                 { line(i*T0,64,(i+1)*T0,64-A,1);
                   line((i+1)*T0,64-A,(i+1)*T0,64,1);
                  }
                  }
        //********正弦函數顯示**************************
        //四個參數分別為:x,y為原點坐標(精確位置);t為周期;f為振幅。
        void zhengxian (uchar x,uchar y,uchar t,uchar A)
        {  uchar i=0,j=0,m=0,p=0,q=0;
           m=x;
           clear_graph();
            l240wc(0x9c);
           af(A,t);
               A=45;
               t=30;
            line(00,64,240,64,1);//x軸,從x到y+f+10
         writepoint(x,y-(uchar)A*sin(0),1); //坐標原點(x,y)
         {
          for(i=0;i<=230-m;i++)  // m=x,230-x個點
         {
          if(i!=0)  //i!=0時畫點(),x為原點橫坐標,p=0????
           {
           p=q ;
           writepoint(x,p,1);
           }
           else p=y;  //開始i=0時,
           j++;   x++;  //橫坐標加一,每個周期內第j個采樣值,指針遞增
           q=y-(unsigned char)A*sin(6.28*j/t);//q=y-f*sin(jw);振幅;2πj/t=jw
           line(x,p,x,q,1);//橫坐標為0,縱坐標從0到振幅的直線
           if(j==t)  //如果采樣個數達到周期,重新開始下一周期
            j=0;
          }
         }
        }
        
        uchar kbscan(void)
        {uchar sccode,j,k=0;
         P1=0xf0;
        if((P1&0xf0)!=0xf0)
        {Delay(30);
         if((P1&0xf0)!=0xf0)
          {sccode=0xfe;
           for(j=0;j<4;j++)
             {P1=sccode;
              if((P1&0xf0)!=0xf0)
           {k=~P1;
           while((P1&0XF0)!=0XF0);
            return (k);
           }
              else sccode=(sccode<<1)|0x01;
             }
           }
        }
        return(0);
        }
        uchar bian(uchar key)
        {switch(key)
        {case 0x81: return   0;break;
         case 0x82: return   1;break;
         case 0x84: return   2;break;
         case 0x88: return   3;break;
         case 0x41: return   4;break;
         case 0x42: return   5;break;
         case 0x44: return   6;break;
         case 0x48: return   7;break;
         case 0x21: return   8;break;
         case 0x22: return   9;break;
         case 0x24: return   10;break;
         case 0x28: return   11;break;
         case 0x11: return   12;break;
         case 0x12: return   13;break;
         case 0x14: return   14;break;
         case 0x18: return   15;
         default:
         break;
        }
        }
        main()
        {
         uchar key;
                int fb=1,sjb=0,zxb=0;
                uchar f1=40,f2=200,f3=100;
         RST=0;
          Delay(10);
         RST=1;
         Delay(100);
          intl240();  ///初始化必有
                clear_c();
         while(1)
         {
          key=bian(kbscan());
                        Write7279(0xC8,key);
               switch (key)
                  {      case 1:if(fb==1)               //1鍵頻率加100
                                {f1=jiaf(f1);
                                 P2=f1;
                                 fangbo(f1,35);
                                 }
                                 else if(sjb==1)
                                 {f2=jiaf(f2);
                                 P2=f2;
                                 juchibo(f2,40);
                                 }
                                 else {f3=jiaf(f3);
                                 P2=f3;
                                 zhengxian(00,64,f3,45);
                                 }
                                 break;
                          case 2:if(fb==1)              //2鍵頻率減100
                                {f1=jianf(f1);
                                P2=f1;
                                fangbo(f1,35);
                                }
                                else if(sjb==1)
                               {f2=jianf(f2);
                                P2=f2;
                                juchibo(f2,40);
                               }
                                else if(zxb==1)
                               {f3=jianf(f3);
                                P2=f3;
                               zhengxian(00,64,f3,45);
                                }
                                break;
                         case 4:fb=1;
                                sjb=0;
                                zxb=0;
                                P0=0x01;        //201方波
                                fangbo(f1,35);
                                break;
                         case 5:fb=0;
                                sjb=1;
                                zxb=0;
                                P0=0x02;        //202鋸齒波
        
                                juchibo(f2,40);
                                break;
                         case 6:fb=0;
                                sjb=0;
                                zxb=1;
                                P0=0x03;       //203正弦波
                                zhengxian(00,64,f3,45);
                                break;
                         case 15:clear_c();
                                 clear_graph();
                                 l240wc(0x9c);
                                 default:
                                  break;
                }
                     }
        }
        關閉窗口

        相關文章

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮