极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 23395|回复: 7

NOKIA 5110 LCD画图程序

[复制链接]
发表于 2012-4-28 15:00:13 | 显示全部楼层 |阅读模式
//找了几天画图的代码,不得要领。今天上午终于花时间移植了一段代码,实现了在LCD上画正弦曲线的功能,其中很多子函数可能有点怪异,无赖我等没有做过程序,不知如何处理,依葫芦画瓢做了,有谁能够把这个做成5110的库么?

  1. unsigned char LcdBuffer[6][84];
  2. unsigned char LcdX,LcdY;
  3. int LCD_CE=2;
  4. int LCD_RST=3;
  5. int SCLK=4;
  6. int SDIN=5;
  7. int LCD_DC=6;
  8. int inputPin=8;  // 定义超声波信号接收接口
  9. int outputPin=9; // 定义超声波信号发出接口
  10. int pot=0;
  11. void setup()
  12. {
  13.   pinMode(inputPin, INPUT);
  14.   pinMode(outputPin, OUTPUT);
  15.   pinMode(SCLK,OUTPUT);
  16.   pinMode(SDIN,OUTPUT);
  17.   pinMode(LCD_DC,OUTPUT);
  18.   pinMode(LCD_CE,OUTPUT);
  19.   pinMode(LCD_RST,OUTPUT);
  20. }
  21. const unsigned char Font6x8[][6]=
  22. {
  23.   {
  24.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00   }
  25.   ,   // sp
  26.   {
  27.     0x00, 0x00, 0x00, 0x2f, 0x00, 0x00   }
  28.   ,   // !
  29.   {
  30.     0x00, 0x00, 0x07, 0x00, 0x07, 0x00   }
  31.   ,   // "
  32.   {
  33.     0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14   }
  34.   ,   // #
  35.   {
  36.     0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12   }
  37.   ,   // $
  38.   {
  39.     0x00, 0x62, 0x64, 0x08, 0x13, 0x23   }
  40.   ,   // %
  41.   {
  42.     0x00, 0x36, 0x49, 0x55, 0x22, 0x50   }
  43.   ,   // &
  44.   {
  45.     0x00, 0x00, 0x05, 0x03, 0x00, 0x00   }
  46.   ,   // '
  47.   {
  48.     0x00, 0x00, 0x1c, 0x22, 0x41, 0x00   }
  49.   ,   // (
  50.   {
  51.     0x00, 0x00, 0x41, 0x22, 0x1c, 0x00   }
  52.   ,   // )
  53.   {
  54.     0x00, 0x14, 0x08, 0x3E, 0x08, 0x14   }
  55.   ,   // *
  56.   {
  57.     0x00, 0x08, 0x08, 0x3E, 0x08, 0x08   }
  58.   ,   // +
  59.   {
  60.     0x00, 0x00, 0x00, 0xA0, 0x60, 0x00   }
  61.   ,   // ,
  62.   {
  63.     0x00, 0x08, 0x08, 0x08, 0x08, 0x08   }
  64.   ,   // -
  65.   {
  66.     0x00, 0x00, 0x60, 0x60, 0x00, 0x00   }
  67.   ,   // .
  68.   {
  69.     0x00, 0x20, 0x10, 0x08, 0x04, 0x02   }
  70.   ,   // /
  71.   {
  72.     0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E   }
  73.   ,   // 0
  74.   {
  75.     0x00, 0x00, 0x42, 0x7F, 0x40, 0x00   }
  76.   ,   // 1
  77.   {
  78.     0x00, 0x42, 0x61, 0x51, 0x49, 0x46   }
  79.   ,   // 2
  80.   {
  81.     0x00, 0x21, 0x41, 0x45, 0x4B, 0x31   }
  82.   ,   // 3
  83.   {
  84.     0x00, 0x18, 0x14, 0x12, 0x7F, 0x10   }
  85.   ,   // 4
  86.   {
  87.     0x00, 0x27, 0x45, 0x45, 0x45, 0x39   }
  88.   ,   // 5
  89.   {
  90.     0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30   }
  91.   ,   // 6
  92.   {
  93.     0x00, 0x01, 0x71, 0x09, 0x05, 0x03   }
  94.   ,   // 7
  95.   {
  96.     0x00, 0x36, 0x49, 0x49, 0x49, 0x36   }
  97.   ,   // 8
  98.   {
  99.     0x00, 0x06, 0x49, 0x49, 0x29, 0x1E   }
  100.   ,   // 9
  101.   {
  102.     0x00, 0x00, 0x36, 0x36, 0x00, 0x00   }
  103.   ,   // :
  104.   {
  105.     0x00, 0x00, 0x56, 0x36, 0x00, 0x00   }
  106.   ,   // ;
  107.   {
  108.     0x00, 0x08, 0x14, 0x22, 0x41, 0x00   }
  109.   ,   // <
  110.   {
  111.     0x00, 0x14, 0x14, 0x14, 0x14, 0x14   }
  112.   ,   // =
  113.   {
  114.     0x00, 0x00, 0x41, 0x22, 0x14, 0x08   }
  115.   ,   // >
  116.   {
  117.     0x00, 0x02, 0x01, 0x51, 0x09, 0x06   }
  118.   ,   // ?
  119.   {
  120.     0x00, 0x32, 0x49, 0x59, 0x51, 0x3E   }
  121.   ,   // @
  122.   {
  123.     0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C   }
  124.   ,   // A
  125.   {
  126.     0x00, 0x7F, 0x49, 0x49, 0x49, 0x36   }
  127.   ,   // B
  128.   {
  129.     0x00, 0x3E, 0x41, 0x41, 0x41, 0x22   }
  130.   ,   // C
  131.   {
  132.     0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C   }
  133.   ,   // D
  134.   {
  135.     0x00, 0x7F, 0x49, 0x49, 0x49, 0x41   }
  136.   ,   // E
  137.   {
  138.     0x00, 0x7F, 0x09, 0x09, 0x09, 0x01   }
  139.   ,   // F
  140.   {
  141.     0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A   }
  142.   ,   // G
  143.   {
  144.     0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F   }
  145.   ,   // H
  146.   {
  147.     0x00, 0x00, 0x41, 0x7F, 0x41, 0x00   }
  148.   ,   // I
  149.   {
  150.     0x00, 0x20, 0x40, 0x41, 0x3F, 0x01   }
  151.   ,   // J
  152.   {
  153.     0x00, 0x7F, 0x08, 0x14, 0x22, 0x41   }
  154.   ,   // K
  155.   {
  156.     0x00, 0x7F, 0x40, 0x40, 0x40, 0x40   }
  157.   ,   // L
  158.   {
  159.     0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F   }
  160.   ,   // M
  161.   {
  162.     0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F   }
  163.   ,   // N
  164.   {
  165.     0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E   }
  166.   ,   // O
  167.   {
  168.     0x00, 0x7F, 0x09, 0x09, 0x09, 0x06   }
  169.   ,   // P
  170.   {
  171.     0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E   }
  172.   ,   // Q
  173.   {
  174.     0x00, 0x7F, 0x09, 0x19, 0x29, 0x46   }
  175.   ,   // R
  176.   {
  177.     0x00, 0x46, 0x49, 0x49, 0x49, 0x31   }
  178.   ,   // S
  179.   {
  180.     0x00, 0x01, 0x01, 0x7F, 0x01, 0x01   }
  181.   ,   // T
  182.   {
  183.     0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F   }
  184.   ,   // U
  185.   {
  186.     0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F   }
  187.   ,   // V
  188.   {
  189.     0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F   }
  190.   ,   // W
  191.   {
  192.     0x00, 0x63, 0x14, 0x08, 0x14, 0x63   }
  193.   ,   // X
  194.   {
  195.     0x00, 0x07, 0x08, 0x70, 0x08, 0x07   }
  196.   ,   // Y
  197.   {
  198.     0x00, 0x61, 0x51, 0x49, 0x45, 0x43   }
  199.   ,   // Z
  200.   {
  201.     0x00, 0x00, 0x7F, 0x41, 0x41, 0x00   }
  202.   ,   // [
  203.   {
  204.     0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55   }
  205.   ,   // 55
  206.   {
  207.     0x00, 0x00, 0x41, 0x41, 0x7F, 0x00   }
  208.   ,   // ]
  209.   {
  210.     0x00, 0x04, 0x02, 0x01, 0x02, 0x04   }
  211.   ,   // ^
  212.   {
  213.     0x00, 0x40, 0x40, 0x40, 0x40, 0x40   }
  214.   ,   // _
  215.   {
  216.     0x00, 0x00, 0x01, 0x02, 0x04, 0x00   }
  217.   ,   // '
  218.   {
  219.     0x00, 0x20, 0x54, 0x54, 0x54, 0x78   }
  220.   ,   // a
  221.   {
  222.     0x00, 0x7F, 0x48, 0x44, 0x44, 0x38   }
  223.   ,   // b
  224.   {
  225.     0x00, 0x38, 0x44, 0x44, 0x44, 0x20   }
  226.   ,   // c
  227.   {
  228.     0x00, 0x38, 0x44, 0x44, 0x48, 0x7F   }
  229.   ,   // d
  230.   {
  231.     0x00, 0x38, 0x54, 0x54, 0x54, 0x18   }
  232.   ,   // e
  233.   {
  234.     0x00, 0x08, 0x7E, 0x09, 0x01, 0x02   }
  235.   ,   // f
  236.   {
  237.     0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C   }
  238.   ,   // g
  239.   {
  240.     0x00, 0x7F, 0x08, 0x04, 0x04, 0x78   }
  241.   ,   // h
  242.   {
  243.     0x00, 0x00, 0x44, 0x7D, 0x40, 0x00   }
  244.   ,   // i
  245.   {
  246.     0x00, 0x40, 0x80, 0x84, 0x7D, 0x00   }
  247.   ,   // j
  248.   {
  249.     0x00, 0x7F, 0x10, 0x28, 0x44, 0x00   }
  250.   ,   // k
  251.   {
  252.     0x00, 0x00, 0x41, 0x7F, 0x40, 0x00   }
  253.   ,   // l
  254.   {
  255.     0x00, 0x7C, 0x04, 0x18, 0x04, 0x78   }
  256.   ,   // m
  257.   {
  258.     0x00, 0x7C, 0x08, 0x04, 0x04, 0x78   }
  259.   ,   // n
  260.   {
  261.     0x00, 0x38, 0x44, 0x44, 0x44, 0x38   }
  262.   ,   // o
  263.   {
  264.     0x00, 0xFC, 0x24, 0x24, 0x24, 0x18   }
  265.   ,   // p
  266.   {
  267.     0x00, 0x18, 0x24, 0x24, 0x18, 0xFC   }
  268.   ,   // q
  269.   {
  270.     0x00, 0x7C, 0x08, 0x04, 0x04, 0x08   }
  271.   ,   // r
  272.   {
  273.     0x00, 0x48, 0x54, 0x54, 0x54, 0x20   }
  274.   ,   // s
  275.   {
  276.     0x00, 0x04, 0x3F, 0x44, 0x40, 0x20   }
  277.   ,   // t
  278.   {
  279.     0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C   }
  280.   ,   // u
  281.   {
  282.     0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C   }
  283.   ,   // v
  284.   {
  285.     0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C   }
  286.   ,   // w
  287.   {
  288.     0x00, 0x44, 0x28, 0x10, 0x28, 0x44   }
  289.   ,   // x
  290.   {
  291.     0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C   }
  292.   ,   // y
  293.   {
  294.     0x00, 0x44, 0x64, 0x54, 0x4C, 0x44   }
  295.   ,   // z
  296.   {
  297.     0x14, 0x14, 0x14, 0x14, 0x14, 0x14   }    // horiz lines
  298. };

  299. /********************************************************************
  300. * 函数功能:LCD复位。
  301. * 入口参数:无。
  302. * 返    回:无。
  303. * 备    注:无。
  304. ********************************************************************/

  305. void ClrLcdRes(void)//LCD reset
  306. {
  307.   digitalWrite( LCD_RST, LOW);
  308. }

  309. void SetLcdRes(void)
  310. {
  311.   digitalWrite( LCD_RST, HIGH);
  312. }
  313. void ClrLcdDc(void)
  314. {
  315.   digitalWrite( LCD_DC, LOW);
  316. }
  317. void ClrLcdCe(void)
  318. {
  319.   digitalWrite( LCD_CE, LOW);
  320. }
  321. void SetLcdSi(void)
  322. {
  323.   digitalWrite( SDIN, HIGH);
  324. }
  325. void ClrLcdSck(void)
  326. {
  327.   digitalWrite( SCLK, LOW);
  328. }
  329. void SetLcdSck(void)
  330. {
  331.   digitalWrite( SCLK, HIGH);
  332. }
  333. void SetLcdCe(void)
  334. {
  335.   digitalWrite( LCD_CE, HIGH);
  336. }
  337. void ClrLcdSi(void)
  338. {
  339.   digitalWrite( SDIN, LOW);
  340. }
  341. void  SetLcdDc()
  342. {
  343.   digitalWrite( LCD_DC, HIGH);
  344. }

  345. void LcdReset(void)
  346. {
  347.   ClrLcdRes();  //RES置低
  348.   delayMicroseconds(1);
  349.   SetLcdRes();  //RES置高
  350.   delayMicroseconds(10);
  351. }
  352. /////////////////////////End of function/////////////////////////////


  353. /********************************************************************
  354. * 函数功能:LCD写命令。
  355. * 入口参数:cmd:要写的命令。
  356. * 返    回:无。
  357. * 备    注:无。
  358. ********************************************************************/
  359. void LcdWriteCmd(unsigned char cmd)
  360. {
  361.   unsigned char i;

  362.   ClrLcdDc(); //选择命令
  363.   ClrLcdCe(); //片选
  364.   for(i=0;i<8;i++) //写一个字节的命令
  365.   {
  366.     if(cmd&0x80)
  367.     {
  368.       SetLcdSi();
  369.     }
  370.     else
  371.     {
  372.       ClrLcdSi();
  373.     }
  374.     //产生一个上升沿
  375.     ClrLcdSck();
  376.     cmd<<=1;   //左移一位
  377.     SetLcdSck();
  378.   }
  379.   SetLcdCe();
  380. }
  381. /////////////////////////End of function/////////////////////////////

  382. /********************************************************************
  383. * 函数功能:LCD写数据。
  384. * 入口参数:dat:要写的数据。
  385. * 返    回:无。
  386. * 备    注:无。
  387. ********************************************************************/
  388. void LcdWriteData(unsigned char dat)
  389. {
  390.   unsigned char i;

  391.   SetLcdDc(); //选择数据
  392.   ClrLcdCe(); //片选
  393.   for(i=0;i<8;i++) //写一个字节的数据
  394.   {
  395.     if(dat&0x80)
  396.     {
  397.       SetLcdSi();
  398.     }
  399.     else
  400.     {
  401.       ClrLcdSi();
  402.     }
  403.     //产生一个上升沿
  404.     ClrLcdSck();
  405.     dat<<=1;   //左移一位
  406.     SetLcdSck();
  407.   }
  408.   SetLcdCe();
  409. }
  410. /////////////////////////End of function/////////////////////////////

  411. /********************************************************************
  412. * 函数功能:LCD设置坐标值。
  413. * 入口参数:相应的x、y值。
  414. * 返    回:无。
  415. * 备    注:无。
  416. ********************************************************************/
  417. void LcdSetXy(int x, int y)
  418. {
  419.   LcdWriteCmd(0x80|(x&0x7F)); //X
  420.   LcdWriteCmd(0x40|(y&0x07)); //Y
  421. }
  422. /////////////////////////End of function/////////////////////////////

  423. /********************************************************************
  424. * 函数功能:将LCD缓冲区数据写到LCD中。
  425. * 入口参数:无。
  426. * 返    回:无。
  427. * 备    注:无。
  428. ********************************************************************/
  429. void LcdRefresh(void)
  430. {
  431.   int i;
  432.   LcdSetXy(0,0); //设置到坐标原点
  433.   for(i=0;i<6*84;i++)
  434.   {
  435.     LcdWriteData(((unsigned char *)LcdBuffer)[i]); //将buffer内数据发送到LCD
  436.   }
  437. }
  438. /////////////////////////End of function/////////////////////////////

  439. /********************************************************************
  440. * 函数功能:LCD清屏。
  441. * 入口参数:无。
  442. * 返    回:无。
  443. * 备    注:无。
  444. ********************************************************************/
  445. void LcdCls(void)
  446. {
  447.   int i;
  448.   LcdSetXy(0,0);  //设置回原点
  449.   LcdSetPoint(0,0); //设置为原点
  450.   for(i=0;i<6*84;i++) //全部字节写入0
  451.   {
  452.     LcdWriteData(0);
  453.     ((unsigned char *)LcdBuffer)[i]=0; //清空buffer
  454.   }
  455. }
  456. /////////////////////////End of function/////////////////////////////

  457. /********************************************************************
  458. * 函数功能:LCD初始化
  459. * 入口参数:无。
  460. * 返    回:无。
  461. * 备    注:无。
  462. ********************************************************************/
  463. void LcdInit(void)
  464. {


  465.   LcdReset();
  466.   LcdWriteCmd(0x21);        // 使用扩展命令设置LCD模式
  467.   LcdWriteCmd(0xc8);        // 设置偏置电压
  468.   LcdWriteCmd(0x06);        // 温度校正
  469.   LcdWriteCmd(0x13);        // 1:48
  470.   LcdWriteCmd(0x20);        // 使用基本命令
  471.   LcdCls();                 // 清屏
  472.   LcdWriteCmd(0x0c);        // 设定显示模式,正常显示
  473. }
  474. /////////////////////////End of function/////////////////////////////

  475. /********************************************************************
  476. * 函数功能:设置LCD显示的点。
  477. * 入口参数:坐标x、y。
  478. * 返    回:无。
  479. * 备    注:无。
  480. ********************************************************************/
  481. void LcdSetPoint(int x, int y)
  482. {
  483.   LcdX=x; //设置坐标
  484.   LcdY=y;
  485. }
  486. /////////////////////////End of function/////////////////////////////

  487. /********************************************************************
  488. * 函数功能:画一个点。
  489. * 入口参数:坐标x、y。
  490. * 返    回:无。
  491. * 备    注:该函数调用完后必须调用LcdRefresh()函数刷新LCD才能显示。
  492. ********************************************************************/
  493. void LcdDrawPoint(int x, int y)
  494. {
  495.   if((x>83)||(y>47))return; //无效点,返回
  496.   LcdBuffer[y/8][x]|=(1<<(y%8));  //设置缓冲区中对应的点
  497. }
  498. /////////////////////////End of function/////////////////////////////

  499. /********************************************************************
  500. * 函数功能:擦除一个点。
  501. * 入口参数:坐标x、y。
  502. * 返    回:无。
  503. * 备    注:该函数调用完后必须调用LcdRefresh()函数刷新LCD才能显示。
  504. ********************************************************************/
  505. void LcdErasePoint(int x, int y)
  506. {
  507.   if((x>83)||(y>47))return; //无效点,返回
  508.   LcdBuffer[y/8][x]&=(unsigned char)(~(1<<(y%8)));  //设置缓冲区中对应的点
  509. }
  510. /////////////////////////End of function/////////////////////////////

  511. /********************************************************************
  512. * 函数功能:画一个圆。
  513. * 入口参数:x、y:圆心坐标;r:圆半径。
  514. * 返    回:无。
  515. * 备    注:该函数调用完后必须调用LcdRefresh()函数刷新LCD才能显示。
  516. ********************************************************************/
  517. void LcdDrawCircle(int x, int y, int r)
  518. {
  519.   int Angle;
  520.   float s,c;
  521.   for(Angle=0;Angle<360;Angle++) //从0到360度画一个圆
  522.   {
  523.     //计算正弦和余弦值
  524.     s=r*sin(Angle*PI/180);
  525.     c=r*cos(Angle*PI/180);
  526.     //四舍五入
  527.     if(s<0)s-=0.5;
  528.     else s+=0.5;
  529.     if(c<0)c-=0.5;
  530.     else c+=0.5;
  531.     LcdDrawPoint(x+c,y+s); //画一个点
  532.   }
  533. }
  534. /////////////////////////End of function/////////////////////////////

  535. /********************************************************************
  536. * 函数功能:从点x0、y0画直线到x1、y1。
  537. * 入口参数:起点坐标x0、y0,终点坐标x1、y1。
  538. * 返    回:无。
  539. * 备    注:该函数调用完后必须调用LcdRefresh()刷新LCD。
  540. ********************************************************************/
  541. void LcdDrawLine(int x0, int y0, int x1, int y1)
  542. {
  543.   int x,y,dx,dy,i,dir;
  544.   float d;

  545.   if((x0==x1)&&(y0==y1)) //如果只有一个点,那么就只画一个点
  546.   {
  547.     LcdDrawPoint(x0,y0);
  548.     return;
  549.   }

  550.   dx=abs(x1-x0); //求x、y的距离
  551.   dy=abs(y1-y0);
  552.   x=x0; //起点
  553.   y=y0;
  554.   if(dx>dy)   //如果x距离长,则从x轴方向移动
  555.   {
  556.     //求出运动方向
  557.     if(x1>x0)dir=1;
  558.     else dir=-1;
  559.     for(i=1;i<dx+1;i++)
  560.     {
  561.       LcdDrawPoint(x,y); //绘制对应的点
  562.       x+=dir;  //x改变一个单位
  563.       d=(float)(y1-y0)*i/dx;
  564.       if(d<0)d-=0.5;
  565.       else d+=0.5;
  566.       y=y0+d; //求出对应的y值
  567.     }
  568.   }
  569.   else  //如果y距离长,则从y轴方向移动
  570.   {
  571.     if(y1>y0)dir=1; //求出运动方向
  572.     else dir=-1;
  573.     for(i=1;i<dy+1;i++)
  574.     {
  575.       LcdDrawPoint(x,y); //绘制对应的点
  576.       y+=dir;  //y改变一个单位
  577.       d=(float)(x1-x0)*i/dy;
  578.       if(d<0)d-=0.5;
  579.       else d+=0.5;
  580.       x=x0+d; //求出对应的x值
  581.     }
  582.   }
  583. }
  584. /////////////////////////End of function/////////////////////////////

  585. /********************************************************************
  586. * 函数功能:填充一个矩形,包括边缘
  587. * 入口参数:x0、y0:矩形的一个顶点;x1、y1:矩形的另一个顶点。
  588. * 返    回:无。
  589. * 备    注:该函数调用完后必须调用LcdRefresh()函数刷新LCD才能显示。
  590. ********************************************************************/
  591. void LcdFill(int x0, int y0, int x1, int y1)
  592. {
  593.   int d,i,y;
  594.   if(x0==x1) //只需要填充边沿
  595.   {
  596.     LcdDrawLine(x0,y0,x0,y1);//用直线填充
  597.     return;
  598.   }
  599.   if(y0==y1) //只需要填充边沿
  600.   {
  601.     LcdDrawLine(x0,y0,x1,y0);//用直线填充
  602.     return;
  603.   }
  604.   d=abs(y1-y0);
  605.   if(y1>y0) y=y0; //选择一个小的作为起点
  606.   else y=y1;
  607.   for(i=0;i<d;i++)
  608.   {
  609.     LcdDrawLine(x0,y,x1,y);//用直线填充
  610.     y++; //画下一条线
  611.   }
  612. }
  613. /////////////////////////End of function/////////////////////////////

  614. /********************************************************************
  615. * 函数功能:显示一个英文字符。
  616. * 入口参数:要显示的字符的ASCII码。
  617. * 返    回:无。
  618. * 备    注:显示位置由LcdX和LcdY决定。如果显示范围,多余的部分将无法显示。
  619. * 该函数调用完后必须调用LcdRefresh()函数刷新LCD才能显示。
  620. ********************************************************************/
  621. void LcdPutChar(unsigned char ch)
  622. {
  623.   unsigned char i,j,temp;
  624.   if((LcdX>83)||(LcdY>47))return; //超过范围,不用显示
  625.   ch-=' '; //字库是从空格开始的
  626.   for(i=0;i<6;i++) //每个字符有6个字节
  627.   {
  628.     if(LcdX>83)break;//如果超过范围,则跳过
  629.     temp=Font6x8[ch][i];  //取出一个字节
  630.     for(j=0;j<8;j++)
  631.     {
  632.       if(LcdY>47)break; //如果超过范围,则跳过  
  633.       if(temp&0x01)LcdDrawPoint(LcdX,LcdY); //对应的位为1,画点
  634.       else LcdErasePoint(LcdX,LcdY);   //对应的位为0,擦除
  635.       temp>>=1;
  636.       LcdY++;
  637.     }
  638.     LcdY-=j; //调整回Y值
  639.     LcdX++;  //调整X值
  640.   }
  641. }
  642. /////////////////////////End of function/////////////////////////////

  643. /********************************************************************
  644. * 函数功能:在LCD上显示一个字符串。
  645. * 入口参数:p:字符串指针。
  646. * 返    回:无。
  647. * 备    注:无。
  648. ********************************************************************/
  649. void LcdPrints(unsigned char * p)
  650. {
  651.   while(*p)
  652.   {
  653.     LcdPutChar(*p);
  654.     p++;
  655.   }
  656. }
  657. /////////////////////////End of function/////////////////////////////
  658. void loop()
  659. {
  660.   int bo;
  661.   LcdInit();
  662.   LcdDrawLine(0,24,84,24);
  663.   LcdDrawLine(0,0,0,48);
  664.   LcdRefresh();

  665.   bo=35;
  666.   while(1){
  667.     for(int i=0;i<84;i++)
  668.     {
  669.       int step=720/84;
  670.       float y1=sin(i*PI/bo)*24;
  671.       float y2=sin((i+1)*PI/bo)*24;
  672.       LcdDrawLine(i,24-y1,i+1,24-y2);
  673.       //LcdDrawPoint(i,24-vet );
  674.       //LcdRefresh();
  675.     }

  676.     LcdRefresh();
  677.   }

  678.   LcdCls();
  679. }
复制代码
回复

使用道具 举报

发表于 2012-4-29 11:27:14 | 显示全部楼层
有空可以研究研究!做成库还是很方便的!
回复 支持 反对

使用道具 举报

发表于 2013-4-7 22:01:47 | 显示全部楼层
好东西!留记号备用!
回复 支持 反对

使用道具 举报

发表于 2013-4-7 23:59:56 | 显示全部楼层
能附上效果图就更好了
回复 支持 反对

使用道具 举报

发表于 2013-5-19 17:25:30 | 显示全部楼层

好啊,用得着,能附上效果图就更好了
回复 支持 反对

使用道具 举报

发表于 2013-6-23 21:35:17 | 显示全部楼层
标记一下
回复 支持 反对

使用道具 举报

发表于 2014-3-13 20:08:14 | 显示全部楼层
Marking for remind
回复 支持 反对

使用道具 举报

发表于 2015-9-29 16:07:04 | 显示全部楼层
感觉超声波没有什么作用啊
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-26 01:51 , Processed in 0.052808 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表