找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2838|回复: 3
打印 上一主题 下一主题
收起左侧

lcd多级菜单仿真加源程序 取模软件

[复制链接]
跳转到指定楼层
楼主
51单片机做的lcd多级菜单:


取模软件:


部分源程序(完整版请下载本帖51黑论坛附件):
  1. #include <reg52.h>
  2. #include <absacc.h>
  3. #include <intrins.h>
  4. #include <string.h>

  5. #include "lcd.h"
  6. #include "font.h"

  7. sbit LCD_WR =P3^5;  //Data Write into T6963C,L有效
  8. sbit LCD_RD =P3^6;  //Data Read from T6963C,L有效
  9. sbit LCD_CE =P3^4;  //使能信号,L有效
  10. sbit LCD_CD =P3^7;  //当wr=L,LCD_CD=H:写命令,LCD_CD=L:写数据;当rd=L,LCD_CD=H:读状态,LCD_CD=L:读数据
  11. sbit LCD_RST=P3^3;  //Lcm reset,低有效
  12. sbit LCD_FS =P3^2;  //字体选择,H:6*8点阵;L:8*8点阵

  13. sbit bf0 = P1^0;
  14. sbit bf1 = P1^1;
  15. sbit bf3 = P1^3;

  16. uchar code HexTable[]="0123456789ABCEDF";

  17. uchar code Num_Tab[]=
  18. {
  19.         /* 48 0x30 '0' */
  20.         0x00, /* 00000000 */
  21.         0x00, /* 00000000 */
  22.         0x38, /* 00   000 */
  23.         0x44, /* 0 000 00 */
  24.         0x4c, /* 0 00  00 */
  25.         0x54, /* 0 0 0 00 */
  26.         0x64, /* 0  00 00 */
  27.         0x44, /* 0 000 00 */
  28.         0x38, /* 00   000 */
  29.         0x00, /* 00000000 */
  30.         0x00, /* 00000000 */

  31.         /* 49 0x31 '1' */
  32.         0x00, /* 00000000 */
  33.         0x00, /* 00000000 */
  34.         0x08, /* 0000 000 */
  35.         0x18, /* 000  000 */
  36.         0x08, /* 0000 000 */
  37.         0x08, /* 0000 000 */
  38.         0x08, /* 0000 000 */
  39.         0x08, /* 0000 000 */
  40.         0x1c, /* 000   00 */
  41.         0x00, /* 00000000 */
  42.         0x00, /* 00000000 */

  43.         /* 50 0x32 '2' */
  44.         0x00, /* 00000000 */
  45.         0x00, /* 00000000 */
  46.         0x38, /* 00   000 */
  47.         0x44, /* 0 000 00 */
  48.         0x04, /* 00000 00 */
  49.         0x08, /* 0000 000 */
  50.         0x10, /* 000 0000 */
  51.         0x20, /* 00 00000 */
  52.         0x7c, /* 0     00 */
  53.         0x00, /* 00000000 */
  54.         0x00, /* 00000000 */

  55.         /* 51 0x33 '3' */
  56.         0x00, /* 00000000 */
  57.         0x00, /* 00000000 */
  58.         0x38, /* 00   000 */
  59.         0x44, /* 0 000 00 */
  60.         0x04, /* 00000 00 */
  61.         0x18, /* 000  000 */
  62.         0x04, /* 00000 00 */
  63.         0x44, /* 0 000 00 */
  64.         0x38, /* 00   000 */
  65.         0x00, /* 00000000 */
  66.         0x00, /* 00000000 */

  67.         /* 52 0x34 '4' */
  68.         0x00, /* 00000000 */
  69.         0x00, /* 00000000 */
  70.         0x08, /* 0000 000 */
  71.         0x18, /* 000  000 */
  72.         0x28, /* 00 0 000 */
  73.         0x48, /* 0 00 000 */
  74.         0x7c, /* 0     00 */
  75.         0x08, /* 0000 000 */
  76.         0x1c, /* 000   00 */
  77.         0x00, /* 00000000 */
  78.         0x00, /* 00000000 */

  79.         /* 53 0x35 '5' */
  80.         0x00, /* 00000000 */
  81.         0x00, /* 00000000 */
  82.         0x7c, /* 0     00 */
  83.         0x40, /* 0 000000 */
  84.         0x78, /* 0    000 */
  85.         0x04, /* 00000 00 */
  86.         0x04, /* 00000 00 */
  87.         0x44, /* 0 000 00 */
  88.         0x38, /* 00   000 */
  89.         0x00, /* 00000000 */
  90.         0x00, /* 00000000 */

  91.         /* 54 0x36 '6' */
  92.         0x00, /* 00000000 */
  93.         0x00, /* 00000000 */
  94.         0x38, /* 00   000 */
  95.         0x40, /* 0 000000 */
  96.         0x78, /* 0    000 */
  97.         0x44, /* 0 000 00 */
  98.         0x44, /* 0 000 00 */
  99.         0x44, /* 0 000 00 */
  100.         0x38, /* 00   000 */
  101.         0x00, /* 00000000 */
  102.         0x00, /* 00000000 */

  103.         /* 55 0x37 '7' */
  104.         0x00, /* 00000000 */
  105.         0x00, /* 00000000 */
  106.         0x7c, /* 0     00 */
  107.         0x04, /* 00000 00 */
  108.         0x04, /* 00000 00 */
  109.         0x08, /* 0000 000 */
  110.         0x10, /* 000 0000 */
  111.         0x10, /* 000 0000 */
  112.         0x10, /* 000 0000 */
  113.         0x00, /* 00000000 */
  114.         0x00, /* 00000000 */

  115.         /* 56 0x38 '8' */
  116.         0x00, /* 00000000 */
  117.         0x00, /* 00000000 */
  118.         0x38, /* 00   000 */
  119.         0x44, /* 0 000 00 */
  120.         0x44, /* 0 000 00 */
  121.         0x38, /* 00   000 */
  122.         0x44, /* 0 000 00 */
  123.         0x44, /* 0 000 00 */
  124.         0x38, /* 00   000 */
  125.         0x00, /* 00000000 */
  126.         0x00, /* 00000000 */

  127.         /* 57 0x39 '9' */
  128.         0x00, /* 00000000 */
  129.         0x00, /* 00000000 */
  130.         0x38, /* 00   000 */
  131.         0x44, /* 0 000 00 */
  132.         0x44, /* 0 000 00 */
  133.         0x44, /* 0 000 00 */
  134.         0x3c, /* 00    00 */
  135.         0x04, /* 00000 00 */
  136.         0x38, /* 00   000 */
  137.         0x00, /* 00000000 */
  138.         0x00, /* 00000000 */

  139. };
  140. //6x10的方块
  141. uchar code BlockTab[]={
  142.         /* 57 0x39 '9' */
  143.         0x00, /* 00000000 */
  144.         0x00, /* 00000000 */
  145.         0x7C, /* 0     00 */
  146.         0x7C, /* 0     00 */
  147.         0x7C, /* 0     00 */
  148.         0x7C, /* 0     00 */
  149.         0x7C, /* 0     00 */
  150.         0x7C, /* 0     00 */
  151.         0x7C, /* 0     00 */
  152.         0x00, /* 00000000 */
  153.         0x00, /* 00000000 */
  154.         //empty block
  155.         0x00, /* 00000000 */
  156.         0x00, /* 00000000 */
  157.         0x00, /* 00000000 */
  158.         0x00, /* 00000000 */
  159.         0x00, /* 00000000 */
  160.         0x00, /* 00000000 */
  161.         0x00, /* 00000000 */
  162.         0x00, /* 00000000 */
  163.         0x00, /* 00000000 */
  164.         0x00, /* 00000000 */
  165.         0x00, /* 00000000 */
  166. };






  167. void LCD_Busy (uchar autowr)    //测状态
  168. {
  169.           LCD_CE = 0;
  170.           LCD_DATA_BUS=0xff;
  171.           LCD_CD=1;
  172.           LCD_WR=1;
  173.           LCD_RD=0;
  174.           if(autowr)
  175.             {
  176.                     while(bf3==0)
  177.                             ;
  178.             }
  179.           else
  180.             {
  181.                     while((bf0==0)||(bf1==0))
  182.                             ;
  183.              }
  184.           LCD_RD=1;
  185. }
  186. uchar LCD_BusyStatus ()    //测状态
  187. {
  188.         uchar dat;
  189.           LCD_CE = 0;
  190.         LCD_CD=1;
  191.         LCD_RD=1;
  192.         LCD_WR=1;
  193.           LCD_DATA_BUS=0xff;
  194.         LCD_RD=0;
  195.         dat=LCD_DATA_BUS;
  196.         LCD_RD=1;
  197.           return dat;
  198. }

  199. /* 数据,指令读写判别 */
  200. void LCD_CheckBusy1(void)  
  201. {
  202.         while ((LCD_BusyStatus()&3)!=3) {}
  203. }
  204. /* 数据自动读判别 */
  205. /*
  206. void LCD_CheckBusy2(void)
  207. {                               
  208.         while ((LCD_BusyStatus()&4)!=4) {}
  209. }
  210. */
  211. /* 数据自动写判别 */
  212. /*
  213. void LCD_CheckBusy3(void)
  214. {
  215.         while ((LCD_BusyStatus()&8)!=8) {}
  216. }
  217. */
  218. /*------------写命令或数据到LCD--------------*/
  219. void LCD_Write1 (uchar dat,uchar comm)       //写一个数据和一个命令
  220. {
  221.           LCD_Data(dat);
  222.           LCD_Comm(comm);
  223. }
  224. void LCD_Write2 (uchar datl,uchar dath,uchar comm)  //写两个数据和一个命令
  225. {
  226.           LCD_Data(datl);
  227.           LCD_Data(dath);
  228.           LCD_Comm(comm);
  229. }
  230. void LCD_WriteInt (uint dat,uchar comm)       //写一个16进制数据和一个命令
  231. {
  232.           uchar datl,dath;
  233.           datl=dat;
  234.           dath=dat>>8;
  235.           LCD_Data(datl);
  236.           LCD_Data(dath);
  237.           LCD_Comm(comm);
  238. }
  239. void LCD_AutoWrite (uchar dat)               //自动写数据
  240. {
  241.           LCD_CE = 0;
  242.           LCD_Busy (1);
  243.           LCD_CD=0;
  244.           LCD_RD=1;
  245.           LCD_DATA_BUS=dat;
  246.           LCD_WR=0;
  247.           LCD_WR=1;
  248. }
  249. /*        读数据        */
  250. uchar LCD_Read(void)
  251. {
  252.         uchar dat;
  253.           LCD_CE = 0;
  254.         LCD_CheckBusy1();
  255.         LCD_CD=0;
  256.         LCD_DATA_BUS = 0xff;
  257.         LCD_RD=0;
  258.         dat=LCD_DATA_BUS;
  259.         LCD_RD=1;
  260.         LCD_CD=1;
  261.         return dat;
  262. }
  263. /*        自动读数据        */
  264. /*
  265. uchar LCD_AutoRead(void)
  266. {
  267.         uchar dat;
  268.           LCD_CE = 0;
  269.         LCD_CheckBusy2();
  270.         LCD_CD=0;
  271.         LCD_DATA_BUS = 0xff;
  272.         LCD_RD=0;
  273.         dat=LCD_DATA_BUS;
  274.         LCD_RD=1;
  275.         LCD_CD=1;
  276.         return dat;
  277. }
  278. */
  279. void LCD_Comm (uchar comm)       //写命令
  280. {
  281.           LCD_CE = 0;
  282.           LCD_Busy (0);
  283.           LCD_CD=1;
  284.           LCD_RD=1;
  285.           LCD_DATA_BUS=comm;
  286.           LCD_WR=0;
  287.           LCD_WR=1;
  288. }
  289. void LCD_Data (uchar dat)       //写数据
  290. {
  291.           LCD_CE = 0;
  292.           LCD_Busy (0);
  293.           LCD_CD=0;
  294.           LCD_RD=1;
  295.           LCD_DATA_BUS=dat;
  296.           LCD_WR=0;
  297.           LCD_WR=1;
  298. }

  299. /*------------------初始化-----------------*/
  300. void LCD_Init (void)
  301. {
  302.           //LCD_RST=0;
  303.           //;
  304.           //LCD_RST=1;
  305.           //LCD_FS=0;
  306.           //LCD_CE=0;
  307.          
  308.           //LCD_CE = 0;
  309.           LCD_WR=1;
  310.           LCD_RD=1;
  311.           LCD_WriteInt(LCD_TEXT_HOME_ADDR,0x40);         //文本显示区首地址
  312.           LCD_WriteInt(LCD_GRAPH_HOME_ADDR,0x42); //图形显示区首地址
  313.           LCD_Write2(LCD_WIDTH,0x00,0x41);        //文本显示区宽度
  314.           LCD_Write2(LCD_WIDTH,0x00,0x43);        //图形显示区宽度
  315.           LCD_Comm(0x81);                                //逻辑"异或"
  316.           LCD_Write2(0x02,0x00,0x22);             //CGRAM偏置地址设置
  317.           LCD_Comm(0x9c);                                //启用文本显示,启用图形显示
  318.           //LCD_Comm(0x98);                                //启用文本显示,启用图形显示
  319.          
  320.           LCD_Cls();
  321. }

  322. /********************************************************/
  323. /* 清屏                                                        */
  324. /********************************************************/
  325. void LCD_Cls(void)
  326. {
  327.         uint  i;

  328.           //LCD_CE = 0;
  329.         //LCD_Write2(0x00,0x00,LC_ADD_POS);// 置地址指针为从零开始
  330.           LCD_WriteInt(LCD_TEXT_HOME_ADDR,LC_ADD_POS);
  331.         LCD_Comm(LC_AUT_WR);                // 自动写
  332.         for(i=0;i< 144*LCD_WIDTH;i++)        // 清一屏
  333.         {
  334.                 LCD_Data(0x00);                // 写数据0x00
  335.         }
  336.         LCD_Comm(LC_AUT_OVR);                // 自动写结束
  337.         LCD_Write2(0x00,0x00,LC_ADD_POS);// 重置地址指针
  338. }

  339. void LCD_ClsBlock(uchar x1,uchar y1,uchar x2,uchar y2)
  340. {
  341.         uint addr;
  342.         uchar h,w;
  343.           uchar i,j;
  344.        
  345.         //x坐标要8字节对齐
  346.         x1 =(x1 / 8) * 8;
  347.         x2 =(x2 / 8) * 8;
  348.        
  349.         h = y2 - y1;
  350.         w = (x2 - x1)/8;
  351.        
  352.         addr = LCD_GRAPH_HOME_ADDR + LCD_WIDTH * y1 + x1/8;
  353.        
  354.           for(j=0;j<h;j++)
  355.           {
  356.                   LCD_WriteInt(addr,0x24);
  357.                 LCD_Comm(0xb0);
  358.                     for(i=0;i<w;i++)
  359.                     {
  360.                          LCD_AutoWrite(0x00);
  361.                     }
  362.                 LCD_Comm(0xb2);
  363.                 addr += LCD_WIDTH;
  364.           }
  365. }


  366. /*        设定图形x,y值*/
  367. /*
  368. void LCD_GraphSetAddr(uchar x,uchar y)
  369. {
  370.         uint xy;
  371.         xy=y;
  372.         xy=xy*16+x+256;
  373.           //LCD_CE = 0;
  374.         LCD_Write2(xy&0xff,xy/256,0x24);
  375. }
  376. */
  377. /*        设定文本x,y值        */
  378. /*
  379. void LCD_TextSetAddr(uchar x,uchar y)
  380. {
  381.           //LCD_CE = 0;
  382.         LCD_Write2(y*16+x,0,0x24);
  383. }
  384. */
  385. /*        清除一点*/
  386. /*
  387. void LCD_ClrPixel(uchar x,uchar y)
  388. {
  389.         uchar b;
  390.         uint addr = LCD_GRAPH_HOME_ADDR + y * LCD_WIDTH + x / 8;

  391.         b = 7 - (x % 8);
  392.        
  393.         LCD_WriteInt(addr,0x24);
  394.         LCD_Comm(0xf0|b);
  395. }
  396. */
  397. /*        点亮一点        */

  398. void LCD_Putpixel(uchar x,uchar y)
  399. {
  400.         uchar b;
  401.         uint addr = LCD_GRAPH_HOME_ADDR + y * LCD_WIDTH + x / 8;

  402.         b = 7 - (x % 8);
  403.        
  404.         LCD_WriteInt(addr,0x24);
  405.         LCD_Comm(0xf8|b);
  406. }

  407. /*        x,y处显示光标        */
  408. /*
  409. void LCD_ShowCursor(uchar x,uchar y)
  410. {
  411.           //LCD_CE = 0;
  412.         LCD_Comm(0x97);        //光标开
  413.         LCD_Write2(x,y,0x21);
  414. }
  415. */
  416. /*        取消光标        */
  417. /*
  418. void LCD_HideCursor(void)  
  419. {       
  420.           //LCD_CE = 0;
  421.         LCD_Comm(0x9c);       
  422. }
  423. */
  424. void LCD_PutImg(uchar x,uchar y,uchar w,uchar h,uchar *img)
  425. {
  426.         uint data addr;
  427.           uchar data i,j;
  428.           uchar data c;
  429.        
  430.         addr = LCD_GRAPH_HOME_ADDR + LCD_WIDTH * y + (x >> 3);
  431.        
  432.           //LCD_CE = 0;
  433.           for(j=0;j<h;j++)
  434.           {
  435.                   LCD_WriteInt(addr,0x24);
  436.                 LCD_Comm(0xb0);
  437.                     for(i=0;i<w;i++)
  438.                     {
  439.                             c = img[j*w+i] ;
  440.                          LCD_AutoWrite(c);
  441.                                   
  442.                           //LCD_WriteInt(addr +i,0x24);        //+ LCD_WIDTH *j
  443.                               //LCD_Write1(c,0xc0);
  444.                     }
  445.                 LCD_Comm(0xb2);
  446.                 addr += LCD_WIDTH;
  447.           }
  448. }
  449. /*
  450. void LCD_PrintNumStr(uchar x,uchar y,uchar *s)
  451. {
  452.         x =(x / 8) * 8;

  453.         while(*s)
  454.         {
  455.                 LCD_PutImg(x,y,1,11,Num_Tab + (*s - '0') * 11);
  456.                
  457.                 x = x + 8;
  458.                
  459.                 s++;
  460.         }
  461. }


  462. void LCD_PrintBlackBlock(uchar x,uchar y,bool not_empty)
  463. {
  464.         x =(x / 8) * 8;
  465.         LCD_PutImg(x,y,1,11,BlockTab + (not_empty?0:1) * 11);
  466. }
  467. */
  468. void LCD_ReverseRect(uchar x,uchar y,uchar w,uchar h)
  469. {
  470.         uint data addr;
  471.           uchar data i,j;
  472.           uchar data c;
  473.        
  474.         x =(x / 8) * 8;
  475.         addr = LCD_GRAPH_HOME_ADDR + LCD_WIDTH * y + x/8;
  476.        
  477.           for(j=0;j<h;j++)
  478.           {
  479.                     for(i=0;i<w;i++)
  480.                     {
  481.                           LCD_WriteInt(addr +i,0x24);       
  482.                           LCD_Comm(LC_NOC_RD);
  483.                           c = LCD_Read();
  484.                           c = ~c;

  485.                               LCD_Write1(c,LC_NOC_WR);
  486.                     }
  487.                 addr += LCD_WIDTH;
  488.           }
  489. }
  490. /*
  491. void LCD_PrintWord(uchar x,uchar y,uint16 n,uchar start)
  492. {
  493.         uchar buf[4];
  494.         int i;
  495.        
  496.         if(start > 3) start = 0;
  497.        
  498.         for(i = 0; i < 4; i++)
  499.         {
  500.                 buf[i] = n % 10;   
  501.                 n /= 10;
  502.         }
  503.         x =(x / 8) * 8;
  504.        
  505.         for(i = 3-start; i >= 0; i--)
  506.         {
  507.                 LCD_PutImg(x,y,1,11,Num_Tab + buf[i] * 11);
  508.                
  509.                 x = x + 8;
  510.         }
  511. }
  512. void LCD_PrintHex(uchar x,uchar y,uchar hex)
  513. {
  514.         uchar c1,c2;
  515.         //低4位
  516.         c1 = hex & 0x0f;        //lo
  517.         //高4位
  518.         c2 = (hex >> 4) & 0x0f; //hi

  519.         LCD_PutImg(x,y,1,11,Num_Tab + c2 * 11);
  520.         LCD_PutImg(x+8,y,1,11,Num_Tab + c1 * 11);
  521. }

  522. void LCD_GrapPutchar(uchar x,uchar y,uchar num)
  523. {
  524.         uchar i,j;
  525.         uchar dot;
  526.         num = (num- '0')*9;
  527.           //LCD_CE = 0;
  528.         for(i=0; i< 12;i++)
  529.         {
  530.                 dot = Num_Tab[num + i];
  531.                 for(j = 0; j < 7; j++)
  532.                 {
  533.                         if( dot & 0x80)
  534.                                 LCD_Putpixel(x+j,y);
  535.                         else
  536.                                 LCD_ClrPixel(x+j,y);
  537.                                
  538.                         dot <<= 1;
  539.                 }
  540.                 y++;
  541.         }
  542. }

  543. void LCD_GrapPrint(uchar x,uchar y,uchar code *s)
  544. {
  545.         while(*s)
  546.         {
  547.                 LCD_GrapPutchar(x,y,*s);
  548.                 x += 8;
  549.                 s++;
  550.         }
  551. }
  552. */
  553. /*--------------显示字符------------------*/
  554. /*
  555. void LCD_TextPutchar(uchar x,uchar y,uchar c)
  556. {
  557.           //LCD_CE = 0;
  558.           LCD_WriteInt(LCD_TEXT_HOME_ADDR + LCD_WIDTH * y + x,0x24);
  559.           LCD_Comm(0xb0);
  560.         LCD_AutoWrite(c - 0x20);
  561.           LCD_Comm(0xb2);
  562. }

  563. void LCD_TextPrint(uchar x,uchar y,char *s)
  564. {
  565.           //LCD_CE = 0;
  566.           LCD_WriteInt(LCD_TEXT_HOME_ADDR + LCD_WIDTH * y + x,0x24);
  567.           LCD_Comm(0xb0);
  568.           while(*s)
  569.           {
  570.                 LCD_AutoWrite(*s - 0x20);
  571.                 s++;
  572.         }
  573.           LCD_Comm(0xb2);
  574. }
  575. void LCD_TextPrintWord(uchar x,uchar y,uint16 n,uchar start)
  576. {
  577.         uchar buf[4];
  578.         int i;
  579.        
  580.         if(start > 3) start = 0;
  581.        
  582.         for(i = 0; i < 4; i++)
  583.         {
  584.                 buf[i] = n % 10;   
  585.                 n /= 10;
  586.         }
  587.        
  588.         for(i = 3-start; i >= 0; i--)
  589.         {
  590.                 LCD_TextPutchar(x,y,'0' + buf[i]);
  591.                 x ++;
  592.         }
  593. }

  594. void LCD_TextPrintHex(uchar x,uchar y,uchar hex)
  595. {
  596.         uchar c1,c2;
  597.         //低4位
  598.         c1 = hex & 0x0f;        //lo
  599.         //高4位
  600.         c2 = (hex >> 4) & 0x0f; //hi
  601.        
  602.         LCD_TextPutchar(x,y,HexTable[c2]);
  603.         LCD_TextPutchar(x+1,y,HexTable[c1]);
  604. }
  605. */
  606. /************************************************/
  607. /*画线。任意方向的斜线,直线数学方程 aX+bY=1        */
  608. /************************************************/
  609. /*
  610. void LCD_Linexy(uchar x0,uchar y0,uchar xt,uchar yt)
  611. {
  612.         register uchar t;
  613.         int xerr=0,yerr=0,delta_x,delta_y,distance;
  614.         int incx,incy,uRow,uCol;

  615.         delta_x = xt-x0;                                //计算坐标增量
  616.         delta_y = yt-y0;
  617.         uRow = x0;
  618.         uCol = y0;
  619.         if(delta_x>0) incx=1;                                //设置单步方向
  620.         else if( delta_x==0 ) incx=0;                        //垂直线
  621.         else {incx=-1;delta_x=-delta_x;}

  622.         if(delta_y>0) incy=1;
  623.         else if( delta_y==0 ) incy=0;                        //水平线
  624.         else {incy=-1;delta_y=-delta_y;}

  625.         if( delta_x > delta_y )        distance=delta_x;        //选取基本增量坐标轴
  626.         else distance=delta_y;

  627.           //LCD_CE = 0;
  628.         for( t=0;t <= distance+1; t++ )
  629.         {                                        //画线输出
  630.                 LCD_Putpixel(uRow,uCol);                        //画点
  631.                 xerr +=        delta_x        ;
  632.                 yerr +=        delta_y        ;
  633.                
  634.                 if( xerr > distance )
  635.                        {
  636.                         xerr-=distance;
  637.                         uRow+=incx;
  638.                 }
  639.                 if( yerr > distance )
  640.                        {
  641.                         yerr-=distance;
  642.                         uCol+=incy;
  643.                 }
  644.         }
  645. }
  646. */

  647. void LCD_LineH(uchar y)
  648. {
  649.         char i;
  650.        
  651.           //LCD_CE = 0;
  652.           LCD_WriteInt(LCD_GRAPH_HOME_ADDR + LCD_WIDTH * y ,0x24);
  653.         LCD_Comm(0xb0);
  654.         for(i=0;i<LCD_WIDTH;i++)
  655.                 LCD_AutoWrite(0xff);
  656.         LCD_Comm(0xb2);
  657. }
  658. void LCD_LineV(uchar x,uchar y1,uchar y2)
  659. {
  660.         int i;
  661.           //LCD_CE = 0;
  662.         for(i = y1; i < y2; i++)
  663.         {
  664.                 LCD_Putpixel(x,i);               
  665.         }
  666.        
  667. }


  668. void LCD_LineXX(uchar x1,uchar x2,uchar y)
  669. {
  670.         int i;
  671.         for(i = x1; i < x2; i++)
  672.         {
  673.                 LCD_Putpixel(i,y);               
  674.         }
  675. }
  676. /*
  677. void LCD_Rectange(uchar x1,uchar y1,uchar x2,uchar y2)
  678. {
  679.         LCD_LineXX(x1,x2,y1);
  680.         LCD_LineXX(x1,x2,y2);
  681.         LCD_LineV(x1,y1,y2);
  682.         LCD_LineV(x2,y1,y2);
  683. }

  684. */

  685. FNT_GB12 code *GetHzk12(uchar c1,uchar c2)
  686. {
  687.         int i = 0;

  688.         while(HZK12[i].Index[0] != 0)
  689.         {
  690.                 if(c1 == HZK12[i].Index[0] && c2 == HZK12[i].Index[1])
  691.                         return &HZK12[i];
  692.                 i ++;
  693.         }
  694.         return NULL;
  695. }


  696. FNT_GB16 code *GetHzk16(uchar c1,uchar c2)
  697. {
  698.         int i = 0;

  699.         while(HZK16[i].Index[0] != 0)
  700.         {
  701.                 if(c1 == HZK16[i].Index[0] && c2 == HZK16[i].Index[1])
  702.                         return &HZK16[i];
  703.                 i ++;
  704.         }
  705.         return NULL;
  706. }

  707. void LCD_PrintHz12(uchar x,uchar y,uchar *s)
  708. {
  709.         uchar c1,c2;
  710.         //x坐标必需是8位对齐
  711.         x =(x / 8) * 8;
  712.         while(*s)
  713.         {
  714.                 c1 = *s++;
  715.                 if(c1 == ' ')
  716.                         x += 8;
  717.                 else if( c1 > 0x80)
  718.                 {
  719.                         //汉字
  720.                         c2 = *s++;
  721.                         LCD_PutImg(x,y+2,2,12,GetHzk12(c1,c2)->Msk);
  722.                         x += 16;       
  723.                 }
  724.                 else        //ASCII
  725.                 {
  726.                         LCD_PutImg(x,y,1,16,ASC8x16[c1]);        //-
  727.                         x += 8;
  728.                 }
  729.         }
  730. }


  731. void LCD_PrintHz16(uchar x,uchar y,uchar *s)
  732. {
  733.         uchar c1,c2;
  734.         //x坐标必需是8位对齐
  735.         x =(x / 8) * 8;
  736.         while(*s)
  737.         {
  738.                 c1 = *s++;
  739.                 if(c1 == ' ')
  740.                 {
  741.                         x += 8;
  742.                 }
  743.                 else if( c1 > 0x80)
  744.                 {
  745.                         //汉字
  746.                         c2=*s++;
  747.                         LCD_PutImg(x,y,2,16,GetHzk16(c1,c2)->Msk);
  748.                         x += 16;       
  749.                 }
  750.                 else        //ASCII
  751.                 {
  752.                         LCD_PutImg(x,y+2,1,16,ASC8x16[c1]);        //-
  753.                         x += 8;
  754.                 }
  755.         }
  756. }

  757. //显示6x8的数字
  758. void LCD_Print6X8(uchar x, uchar y,uchar *s)
  759. {
  760.         //x坐标必需是8位对齐
  761.         x =(x / 8) * 8;
  762.         while(*s)
  763.         {
  764.                 LCD_PutImg(x,y,1,8,font6x8[*s - 32]);        //-
  765.                 x += 8;

  766.                 s ++;
  767.         }
  768. }

  769. //显示24x32的数字
  770. void LCD_Print24X32(uchar x, uchar y,uchar *s)
  771. {
  772.         //x坐标必需是8位对齐
  773.         x =(x / 8) * 8;
  774.         while(*s)
  775.         {
  776.                 if( *s >= '0' && *s <= '9')        //显示
  777.                 {
  778.                         LCD_PutImg(x,y,3,32,Font24X32[*s-'0']);
  779.                         x += 24;
  780.                 }
  781.                 else if( *s == ' ')
  782.                 {
  783.                         x += 8;
  784.                 }
  785.                 else
  786.                 {
  787.                         LCD_PutImg(x,y+16,1,16,ASC8x16[*s]);        //-
  788.                         x += 8;
  789.                 }
  790.                 s ++;
  791.         }
  792. }
复制代码


51CTO下载-51单片机lcd多级菜单.rar

773.48 KB, 下载次数: 68, 下载积分: 黑币 -5

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:118639 发表于 2016-5-5 17:14 | 只看该作者
感谢分享,下载学习一下
回复

使用道具 举报

板凳
ID:164596 发表于 2017-2-14 14:45 | 只看该作者
感谢,学习一下.
回复

使用道具 举报

地板
ID:183197 发表于 2017-8-16 07:52 | 只看该作者
仿真 是怎么仿真的?
谢谢

回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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