zoukankan      html  css  js  c++  java
  • MicroBlaze 驱动器12864 v0.0

      1 #include "xparameters.h"
      2 
      3 #include "stdio.h"
      4 
      5 #include "xutil.h"
      6 
      7 #include "xbasic_types.h"
      8 
      9 #include "xstatus.h"
     10 
     11 #include "xgpio.h"
     12 
     13  
     14 
     15 #define CHANNEL 1
     16 
     17 #define SET_RS   XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x1)
     18 
     19 #define CLEAR_RS XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x1)
     20 
     21 #define SET_RW   XGpio_DiscreteSet(&Lcd_Ctr,CHANNEL,0x2)
     22 
     23 #define CLEAR_RW XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x2)
     24 
     25 #define SET_EN   XGpio_DiscreteSet(&Lcd_Ctr,CHANNEL,0x8)
     26 
     27 #define CLEAR_EN XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x8)
     28 
     29 #define SET_PORT_IN  XGpio_SetDataDirection(&Lcd_Data,CHANNEL,0xffffffff)
     30 
     31 #define SET_PORT_OUT XGpio_SetDataDirection(&Lcd_Data,CHANNEL,0x00000000)
     32 
     33  
     34 
     35 unsigned char dis[]={"123456"};
     36 
     37 XGpio Lcd_Data,Lcd_Ctr;
     38 
     39  
     40 
     41 /*延时time us*/
     42 
     43 void delay_us(Xuint16 time)
     44 
     45 {
     46 
     47   Xuint16 i,j;
     48 
     49   for(i=0;i<time;i++)
     50 
     51    for(j=0;j<26;j++);
     52 
     53 }
     54 
     55  void delay_ms(Xuint16 time)
     56 
     57  {
     58 
     59   Xuint16 i,j;
     60 
     61   for(i=0;i<time;i++)
     62 
     63     for(j=0;j<3785;j++);
     64 
     65  }
     66 
     67 /*对液晶12864进行操作的一系列子函数 没什么可说的 按照时序图写就是了
     68 
     69  
     70 
     71 /*******************************************************************/
     72 
     73  
     74 
     75 /*                                                                 */
     76 
     77  
     78 
     79 /*检查LCD忙状态                                                    */
     80 
     81  
     82 
     83 /*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。      */
     84 
     85  
     86 
     87  
     88 
     89  
     90 
     91 /*******************************************************************/
     92 
     93  
     94 
     95 /*                                                                 */
     96 
     97  
     98 
     99 /*写指令数据到LCD                                                  */
    100 
    101  
    102 
    103 /*RS=L,RW=L,E=高脉冲,D0-D7=指令码。                             */
    104 
    105 /*******************************************************************/
    106 
    107  
    108 
    109 Xint8 lcd_busy()
    110 
    111  
    112 
    113  {                         
    114 
    115   Xuint8 result;
    116 
    117  
    118 
    119  
    120 
    121     SET_PORT_IN;
    122 
    123      CLEAR_EN;
    124 
    125     CLEAR_RS;
    126 
    127      SET_RW;
    128 
    129      
    130 
    131      delay_us(2);
    132 
    133      SET_EN;
    134 
    135     delay_us(2);
    136 
    137      
    138 
    139      result=XGpio_DiscreteRead (&Lcd_Data,CHANNEL);
    140 
    141      xil_printf("the value of result is %x\r\n",result);
    142 
    143     CLEAR_EN;
    144 
    145      result=result&0x80;
    146 
    147      SET_PORT_OUT;
    148 
    149  
    150 
    151     return result;
    152 
    153  
    154 
    155  }
    156 
    157 /*******************************************************************/
    158 
    159  
    160 
    161  
    162 
    163 void lcd_wcmd(Xuint8 cmd)
    164 
    165  
    166 
    167 {                         
    168 
    169  
    170 
    171    while(lcd_busy());
    172 
    173    //  delay(50);
    174 
    175    CLEAR_EN;
    176 
    177    CLEAR_RS;// XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x1);
    178 
    179     //asm("nop");
    180 
    181   CLEAR_RW;//  XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x2);
    182 
    183    // asm("nop");
    184 
    185     //XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x8);
    186 
    187  
    188 
    189     delay_us(2);
    190 
    191     SET_EN;
    192 
    193     //XGpio_SetDataDirection(&Lcd_Data,CHANNEL,0x0);
    194 
    195     XGpio_DiscreteWrite(&Lcd_Data,CHANNEL,cmd);
    196 
    197     delay_us(2);
    198 
    199     CLEAR_EN;//XGpio_DiscreteSet(&Lcd_Ctr,CHANNEL,0x8);
    200 
    201  
    202 
    203     //delay(2);
    204 
    205  
    206 
    207     //XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x8); 
    208 
    209    xil_printf("cmd done: %x \r\n",cmd);
    210 
    211 }
    212 
    213  
    214 
    215 /*******************************************************************/
    216 
    217  
    218 
    219 /*                                                                 */
    220 
    221  
    222 
    223 /*写显示数据到LCD                                                  */
    224 
    225  
    226 
    227 /*RS=H,RW=L,E=高脉冲,D0-D7=数据。                               */
    228 
    229  
    230 
    231 /*                                                                 */
    232 
    233  
    234 
    235 /*******************************************************************/
    236 
    237  
    238 
    239 void lcd_wdat(Xuint8 dat)
    240 
    241  
    242 
    243 {                         
    244 
    245  
    246 
    247   while(lcd_busy());
    248 
    249   //  delay(50);
    250 
    251    CLEAR_EN;
    252 
    253     SET_RS;
    254 
    255     CLEAR_RW;
    256 
    257     delay_us(2);
    258 
    259     SET_EN;
    260 
    261    
    262 
    263    
    264 
    265     // XGpio_DiscreteSet(&Lcd_Ctr,CHANNEL,0x1);
    266 
    267      //asm("nop");
    268 
    269     //XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x2);
    270 
    271      // asm("nop");
    272 
    273     //XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x8);
    274 
    275    //  delay(2);
    276 
    277     //XGpio_SetDataDirection(&Lcd_Data,CHANNEL,0x0);
    278 
    279     XGpio_DiscreteWrite(&Lcd_Data,CHANNEL,dat);
    280 
    281  
    282 
    283    
    284 
    285  
    286 
    287    // XGpio_DiscreteSet(&Lcd_Ctr,CHANNEL,0x8);
    288 
    289  
    290 
    291     delay_us(2);
    292 
    293  
    294 
    295     //XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x8);
    296 
    297      CLEAR_EN;
    298 
    299     xil_printf("data done: %x \r\n",dat);
    300 
    301  }
    302 
    303  
    304 
    305 /******************************************************************
    306 
    307 设置在液晶中显疚?
    308 
    309 ********************************************************************/
    310 
    311 void lcd_pos(Xuint8 X,Xuint8 Y)
    312 
    313  
    314 
    315 {                         
    316 
    317  
    318 
    319    Xuint8  pos;
    320 
    321  
    322 
    323    if (X==0)
    324 
    325  
    326 
    327      {X=0x80;}
    328 
    329  
    330 
    331    else if (X==1)
    332 
    333  
    334 
    335      {X=0x90;}
    336 
    337  
    338 
    339    else if (X==2)
    340 
    341  
    342 
    343      {X=0x88;}
    344 
    345  
    346 
    347    else if (X==3)
    348 
    349  
    350 
    351      {X=0x98;}
    352 
    353  
    354 
    355    pos = X+Y ; 
    356 
    357  
    358 
    359    lcd_wcmd(pos);     //显示地址
    360 
    361  
    362 
    363 }
    364 
    365  
    366 
    367 /*******************************************************************
    368 
    369  
    370 
    371 在液晶中输出一串字符
    372 
    373  
    374 
    375 ********************************************************************
    376 
    377  
    378 
    379 */
    380 
    381  
    382 
    383 void print_string(Xuint8 x,Xuint8 y,Xuint8 * str)
    384 
    385  
    386 
    387 {
    388 
    389  
    390 
    391 Xuint8 lcd_temp;
    392 
    393  
    394 
    395 lcd_pos(x,y);
    396 
    397  
    398 
    399 lcd_temp=*str;
    400 
    401  
    402 
    403 while(lcd_temp != 0x00)
    404 
    405  
    406 
    407 {
    408 
    409  
    410 
    411 lcd_wdat(lcd_temp);
    412 
    413  
    414 
    415 lcd_temp=*(++str);
    416 
    417  
    418 
    419 }
    420 
    421  
    422 
    423 }
    424 
    425  
    426 
    427 /*******************************************************************/
    428 
    429  
    430 
    431 /*                                                                 */
    432 
    433  
    434 
    435 /*  LCD初始化设定                                                  */
    436 
    437  
    438 
    439 /*                                                                 */
    440 
    441  
    442 
    443 /*******************************************************************/
    444 
    445  
    446 
    447 void lcd_init()
    448 
    449  
    450 
    451 {    delay_ms(40);
    452 
    453     lcd_wcmd(0x30);      //扩充指令操作
    454 
    455  
    456 
    457     delay_ms(5);
    458 
    459  
    460 
    461     lcd_wcmd(0x30);      //基本指令操作
    462 
    463  
    464 
    465     delay_ms(5);
    466 
    467  
    468 
    469     lcd_wcmd(0x0f);      //显示开,关?
    470 
    471     delay_ms(5);
    472 
    473  
    474 
    475     lcd_wcmd(0x01);      //清除LCD的允灸谌?
    476 
    477     delay_ms(10);
    478 
    479      xil_printf("lcd initialization done!\n\r");
    480 
    481  
    482 
    483 }
    484 
    485  
    486 
    487  void MicroBlaze_Initialize(){
    488 
    489  XGpio_Initialize(&Lcd_Data,XPAR_LCD_DATA_DEVICE_ID);
    490 
    491  
    492 
    493  XGpio_SetDataDirection(&Lcd_Data,CHANNEL,0x0);
    494 
    495  XGpio_Initialize(&Lcd_Ctr,XPAR_LCD_CTR_DEVICE_ID);
    496 
    497  XGpio_SetDataDirection(&Lcd_Ctr,CHANNEL,0x0);
    498 
    499   }
    500 
    501 //********************************************上述为对液晶的操作
    502 
    503 int main(void){
    504 
    505   unsigned char i=0;
    506 
    507   xil_printf("now begin\r\n");
    508 
    509   MicroBlaze_Initialize();
    510 
    511  lcd_init();
    512 
    513   lcd_pos(1,1);
    514 
    515   while(dis[i]!='0')
    516 
    517   {
    518 
    519    lcd_wdat(dis[i]);
    520 
    521     ++i;
    522 
    523   }
    524 
    525  xil_printf("print done\r\n");
    526 
    527  
    528 
    529   while(1);  
    530 
    531  
    532 
    533  return 0;
    534 
    535  
    536 
    537  
    538 
    539  }
    540 
    541  
    542 
    543  /**************************************************************************
    OPTIMISM, PASSION & HARDWORK
  • 相关阅读:
    Zookeeper基本使用(转)
    mongon命令(转)
    openstack之cinder
    raw格式转换成qcow2格式
    calico网络
    route命令使用
    guestfish修改镜像内容
    基于etcd插件的CoreDNS动态域名添加
    dns记录类型(转)
    C语言 格式化输出--%m.n
  • 原文地址:https://www.cnblogs.com/hiramlee0534/p/5731192.html
Copyright © 2011-2022 走看看