欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: stc89c51單片機和lcd12864顯示sin函數圖像 源程序 [打印本頁]

作者: 像雪一樣的羊    時間: 2020-11-26 16:33
標題: stc89c51單片機和lcd12864顯示sin函數圖像 源程序
這是我花了幾天時間做的讓stc89c51和lcd12864(帶字庫)的顯示波形,
附件里面包含了原理圖和單片機源代碼。
做出來的圖像坐標都很好。
源代碼有注釋,這是部分代碼,具體的大家去下載吧;

制作出來的實物圖如下:


單片機源程序如下:
  1. #include <reg51.h>
  2. #include <intrins.h>
  3. #include <math.h>

  4. #define uint unsigned int
  5. #define uchar unsigned char

  6. #define pi 3.1419526
  7. uchar f=16;
  8. uchar u=8;

  9. sbit RS=P2^6;
  10. sbit RW=P2^5;
  11. sbit PSB=P3^2;     //lcd串行還是并行選擇端
  12. sbit RST=P3^4;     //lcd的復位端口
  13. sbit EN=P2^7;


  14. /*延時*/
  15. void delay(uint x)
  16. {
  17.     uint y;
  18.     for(;x>0;x--)
  19.       for(y=110;y>0;y--);
  20. }


  21. /*寫入指令*/
  22. void write_com(uchar com)
  23. {

  24.   RS=0;
  25.   RW=0;
  26.   EN=0;
  27.   P0=com;
  28.   delay(1);
  29.   EN=1;
  30.   delay(3);
  31.   EN=0;
  32. }

  33. /*寫入數據*/
  34. void write_data(uchar num)
  35. {

  36.   RS=1;
  37.   RW=0;
  38.   EN=0;
  39.   P0=num;
  40.   delay(1);
  41.   EN=1;
  42.   delay(3);
  43.   EN=0;
  44. }

  45. /*讀取數據*/
  46. uchar Read_data()
  47. {
  48.    uchar read;
  49.    
  50.    RS=1;
  51.    RW=1;
  52.    EN=0;
  53.    delay(1);
  54.       EN=1;
  55.     delay(2);
  56.     read=P0;
  57.     EN=0;
  58.     delay(5);
  59.     return read;
  60. }

  61. /*畫圖清屏*/
  62. void clear_lcd()
  63. {
  64.   uchar i,j;
  65. write_com(0x34);      //擴充指令集動作
  66. for(i=0;i<32;i++)
  67. {
  68.     write_com(0x80+i);
  69.     write_com(0x80);
  70.     for(j=0;j<32;j++)
  71.     {
  72.         write_data(0x00);
  73.     }
  74. }
  75.      write_com(0x36);    //擴充指令集動作
  76.     write_com(0x30);    //基本指令集動作

  77. }

  78. /***********畫點函數**************/
  79. void DrawPoint( unsigned char X, unsigned char Y, unsigned char Color )
  80. {
  81.     unsigned char Row , Tier , Tier_bit    ;
  82.     unsigned char  ReadOldH , ReadOldL  ;
  83.     write_com( 0x34 ) ; //寫入擴充指令命令
  84.     write_com( 0x36 ) ;//顯示圖象
  85.     Tier = X >> 4 ;   
  86.     Tier_bit = X & 0x0f ;
  87.     if( Y < 32 )
  88.     {
  89.         Row = Y ;
  90.     }
  91.     else
  92.     {
  93.         Row = Y - 32 ;
  94.         Tier += 8 ;
  95.     }
  96.     write_com( Row + 0x80 ) ;
  97.    write_com( Tier + 0x80 ) ;
  98.     Read_data() ;
  99.     ReadOldH = Read_data() ;
  100.     ReadOldL = Read_data() ;
  101.     write_com( Row + 0x80 )  ;
  102.     write_com( Tier + 0x80 ) ;
  103.     if( Tier_bit < 8 )
  104.     {
  105.         switch( Color)
  106.         {
  107.             case 0 : ReadOldH &=( ~( 0x01 << ( 7 - Tier_bit ))) ; break ;
  108.             case 1 : ReadOldH |= ( 0x01 << ( 7 - Tier_bit ))  ;  break ;
  109.             case 2 : ReadOldH ^= ( 0x01 << ( 7 - Tier_bit ))    ; break ;
  110.             default : break ;   
  111.         }
  112.        write_data( ReadOldH ) ;
  113.        write_data( ReadOldL ) ;
  114.     }
  115.     else
  116.     {
  117.         switch(Color)
  118.         {
  119.             case 0 : ReadOldL &= (~( 0x01 << ( 15 - Tier_bit ))) ;  break ;
  120.             case 1 : ReadOldL |= ( 0x01 << ( 15 - Tier_bit ))    ;  break ;
  121.             case 2 : ReadOldL ^= ( 0x01 << ( 15 - Tier_bit ))  ;  break ;
  122.             default : break ;
  123.         }
  124.         write_data( ReadOldH ) ;
  125.         write_data( ReadOldL ) ;
  126.     }
  127.    write_com( 0x30 )    ;
  128. }

  129. /*液晶初始化*/
  130. void lcd_init()
  131. {
  132.        PSB=1;
  133.        RST=1;
  134.        write_com(0x30);
  135.        delay(1);
  136.        write_com(0x3e);
  137.        delay(1);
  138.        write_com(0x0c);
  139.        delay(1);
  140.        write_com(0x01);
  141.        delay(1);
  142. }

  143. //畫水平直線
  144. void Draw_xlabel_line(uchar x0,uchar x1,uchar y,uchar color)
  145. {
  146.       uchar temp;
  147.       if(x0>x1)
  148.       {
  149.        temp=x1;
  150.        x1=x0;
  151.        x0=temp;
  152.       }
  153.       for(;x0<=x1;x0++)
  154.       DrawPoint(x0,y,color);
  155. }

  156.   //畫垂直直線
  157. void Draw_row_line(uchar x,uchar y0,uchar y1,uchar color)
  158. {
  159.       uchar temp;
  160.       if(y0>y1)
  161.       {
  162.        temp=y1;
  163.        y1=y0;
  164.        y0=temp;
  165.       }
  166.       for(;y0<=y1;y0++)
  167.       DrawPoint(x,y0,color);
  168. }

  169. void sin_display()
  170. {
  171.        uchar i,j;
  172.     lcd_init();     
  173.      clear_lcd();
  174.     //畫y軸箭頭
  175.     DrawPoint(1,1,1);
  176.     DrawPoint(3,1,1);
  177.     DrawPoint(0,2,1);
  178.     DrawPoint(4,2,1);
  179.     Draw_row_line(2,0,60,1);  //畫Y軸直線

  180.     DrawPoint(126,60,1);
  181.     DrawPoint(126,62,1);
  182.     DrawPoint(125,59,1);
  183.     DrawPoint(125,63,1);
  184.     Draw_xlabel_line(2,127,61,1);  //畫X軸直線

  185.     for(i=3;i<127;i++)//畫sin函數,
  186.     {
  187.         j=u*sin(pi*i/f)+30;
  188.        DrawPoint(i,j,1);
  189.     }
  190. }

  191. void main()
  192. {

  193.    sin_display();
  194.    
  195. }
復制代碼

都是自己原創的,請大家多多指教。

以上程序51hei下載地址:
完整sin函數.zip (45.44 KB, 下載次數: 27)

作者: 蛋進涼絕    時間: 2020-11-28 15:35
51有你黑精彩




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1