国产精品无码一区二区三区A片_无码狠狠躁久久久久久久91_国产精品久久久久久久_国产99九九久久无码熟妇_国产人妻精品久久久久野外_久久夜色精品国产欧美乱极品_91精品国产色综合久久不卡98口_精品人妻系列无码人妻免费视频

技術(shù)熱線: 4007-888-234
設(shè)計開發(fā)

專注差異化嵌入式產(chǎn)品解決方案 給智能產(chǎn)品定制注入靈魂給予生命

開發(fā)工具

提供開發(fā)工具、應(yīng)用測試 完善的開發(fā)代碼案例庫分享

技術(shù)支持

從全面的產(chǎn)品導(dǎo)入到強大技術(shù)支援服務(wù) 全程貼心伴隨服務(wù),創(chuàng)造無限潛能!

新品推廣

提供新的芯片及解決方案,提升客戶產(chǎn)品競爭力

新聞中心

提供最新的單片機資訊,行業(yè)消息以及公司新聞動態(tài)

[MCD

更新時間: 2019-01-05
閱讀量:791

//實驗?zāi)康模菏煜?2864LCD的使用
//12864LCD帶中文字庫
//編程讓12864LCD顯示公司名稱“深圳英銳恩科技”,公司電話“0755巧2543411”,公司web“www.nkfboao.cn”,公司傳真“0755-82543511”
//硬件設(shè)置:
//關(guān)斷所有撥碼開關(guān)。
 #include
 __CONFIG(0x1832);       
//芯片配置字,看門狗關(guān),上電延時開,掉電檢測關(guān),低壓編程關(guān),加密,4M晶體HS振蕩


#define  rs  RA5                    //定義LCD的數(shù)據(jù)/命令控制口
#define  rw  RA4                    //定義LCD的讀/寫控制口
#define  e   RA3                    //定義LCD的使能口
#define  psb RA2                    //定義通信方式控制口
#define  rst RA0                    //定義復(fù)位口
#define  nop()  asm("nop")          //定義nop()函數(shù)

//深圳英銳恩科技
const unsigned char TAB1A[ ]={0xC9,0xEE,0xDB,0xDA,0xC7,0xAC,0xC1,0xFA,0xCA,0xA2,0xB5,0xE7,0xD7,0xD3};
//WWW.PIC16.COM
const unsigned char TAB1B[ ]={' ', ' ', 'W', 'W', 'W', '.', 'e', 'n', 'r', 'o','o', '.', 'C', 'O', 'M', ' '};     
//TEL0755-28187975
const unsigned char TAB1C[ ]={'T', 'E', 'L' ,'0' ,'7', '5' ,'5','-', '8', '2','5', '4' ,'3','4' ,'1','1'};   
//FAX0755-28187976    
const unsigned char TAB1D[ ]={'F', 'A', 'X', '0', '7', '5', '5', '-','8', '2','5', '4', '3', '5', '1', '1'};      
 unsigned int lcd_x;                //定義LCD頁地址寄存器
 unsigned int lcd_y;                //定義LCD列地址寄存器
  bit busy;                         //定義LCD忙標(biāo)志位

void init();                        //申明I/O口設(shè)置函數(shù)
void lcd_init();                    //申明LCD初始化函數(shù)
void clear_p();                     //申明清屏函數(shù)
void han_wr2a();                    //申明顯示公司名稱函數(shù)
void han_wr2b();                    //申明顯示公司web函數(shù)
void han_wr2c();                    //申明顯示公司tel函數(shù)
void han_wr2d();                    //申明顯示公司fax函數(shù)
void wr_zb();                       //申明有關(guān)顯示設(shè)置函數(shù)
void flash();                       //申明設(shè)置LCD顯示閃爍函數(shù)
void qushu(int counts,const unsigned char *ps);       //申明查表獲取顯示數(shù)據(jù)
void send_d(unsigned char x);       //申明送一字節(jié)數(shù)據(jù)顯示函數(shù)
void send_i(unsigned char x);       //申明送一字節(jié)控制命令函數(shù)
void chk_busy();                    //申明檢測LCD是否工作繁忙函數(shù)
void delay();                       //申明延時函數(shù)1,供各命令之間的延時和決定顯示快慢
void delay1();                      //申明延時函數(shù)2,用以決定顯示閃爍快慢

//-------------------------------------------
//主程序
void main()
{
   while(1)
     {
       init();                      //調(diào)用I/O口設(shè)置函數(shù)
       lcd_init();                  //調(diào)用LCD初始化函數(shù)  
       clear_p();                   //調(diào)用清屏函數(shù)
       han_wr2a();                  //調(diào)用顯示公司名稱函數(shù)
       han_wr2b();                  //調(diào)用顯示公司web函數(shù)
       han_wr2c();                  //調(diào)用顯示公司tel函數(shù)
       han_wr2d();                  //申明顯示公司fax函數(shù)
       delay();                     //延長顯示一段時間
       flash();                     //調(diào)用顯示閃爍函數(shù)
       clear_p();                   //調(diào)用清屏函數(shù)
     }
}

//-------------------------------------------
//I/O口設(shè)置函數(shù)
void init()
{
  TRISA=0X00;                       //設(shè)置A口為輸出
  TRISD=0X00;                       //設(shè)置D口為輸出
  ADCON1=0X06;                      //設(shè)置A口為普通I/O口
}

//-------------------------------------------
//LCD初始化函數(shù)
void lcd_init()
{
  rst=0;                            //復(fù)位LCD
  delay();                          //保證復(fù)位所需要的時間
  rst=1;                            //恢復(fù)LCD正常工作
  nop();       
  psb=1;                            //設(shè)置LCD為8位并口通信
  send_i(0x30);                     //基本指令操作
  send_i(0x01);                     //清除顯示
  send_i(0x06);                     //指定在寫入或讀取時,光標(biāo)的移動方向
  send_i(0x0c);                     //開顯示,關(guān)光標(biāo),不閃爍
}

//-------------------------------------------
//顯示公司名稱函數(shù)
void han_wr2a()
{
  send_i(0x81);                     //設(shè)置顯示位置:第一行
  qushu(0xe,TAB1A);                 //調(diào)用取數(shù)函數(shù),共14個數(shù)據(jù),保存在數(shù)組TAB1A里
}

//-------------------------------------------
//顯示公司web函數(shù) 
void han_wr2b()
{
  send_i(0x90);                    //設(shè)置顯示位置:第二行
  qushu(0x10,TAB1B);               //調(diào)用取數(shù)函數(shù),共16個數(shù)據(jù),保存在數(shù)組TAB1B里
} 

//-------------------------------------------
//顯示公司tel函數(shù)
void han_wr2c()
{
  send_i(0x88);                   //設(shè)置顯示位置:第三行
  qushu(0X10,TAB1C);              //調(diào)用取數(shù)函數(shù),共16個數(shù)據(jù),保存在數(shù)組TAB1C里
}

//-------------------------------------------
//顯示公司fax函數(shù)
void han_wr2d()
{
  send_i(0x98);                  //設(shè)置顯示位置:第四行
  qushu(0X10,TAB1D);             //調(diào)用取數(shù)函數(shù),共16個數(shù)據(jù),保存在數(shù)組TAB1D里
}

//有關(guān)顯示設(shè)置函數(shù)
void wr_zb()
{
  send_i(lcd_y);
  send_i(lcd_x);
}

//-------------------------------------------
//顯示閃爍函數(shù)
void flash()
{
  send_i(0x08);                  //關(guān)顯示
  delay1();                      //延長一定時間
  send_i(0x0c);                  //開顯示
  delay1();
  delay1();                      //延長關(guān)顯示兩倍的時間
  send_i(0x08);                  //關(guān)顯示
  delay1();
  send_i(0x0c);                  //開顯示
  delay1();
  delay1();
  send_i(0x08);                  //關(guān)顯示
  delay1();
  send_i(0x0c);                  //開顯示
  delay1();
  delay1();
}

//-------------------------------------------
//清屏函數(shù)
void clear_p()
{
  send_i(0x1);                   //清除所有顯示
  send_i(0x34);                  //擴展指令操作
  send_i(0x30);                  //基本指令操作
}

//------------------------------------------
//查表函數(shù)
void qushu(int counts,const unsigned char *ps)
{
  int i;                         //定義循環(huán)變量
  for(i=counts;i>0;i--)          //循環(huán)counts次
     { 
        send_d(*ps);             //查表取數(shù)并調(diào)用顯示一個字節(jié)數(shù)據(jù)函數(shù)送顯示
        delay();                 //延長一定時間,確保能看到數(shù)據(jù)一個個的顯示出來
        ps++;                    //取下一個數(shù)據(jù)
     }
}

//-------------------------------------------
//顯示一字節(jié)數(shù)據(jù)函數(shù)
void send_d(unsigned char x)
{
   chk_busy();                  //檢測LCD是否工作繁忙
   rs=1;                        //設(shè)置該字節(jié)數(shù)據(jù)是顯示數(shù)據(jù)
   rw=0;                        //設(shè)置該次操作為寫
   PORTD=x;                     //送數(shù)據(jù)口PORTD
   e=1;                         //使能
   nop();
   nop();
   nop();                      
   e=0;                         //禁止
}

//--------------------------------------------
//送一字節(jié)命令代碼函數(shù)
void send_i(unsigned char x)
{
   chk_busy();                  //檢測LCD是否工作繁忙
   rs=0;                        //設(shè)置該字節(jié)數(shù)據(jù)為控制命令
   rw=0;                        //設(shè)置此次操作為寫
   PORTD=x;                     //送數(shù)據(jù)口PORTD
   e=1;                         //使能
   nop();
   nop();
   nop();
   e=0;                         //禁止
}

//-------------------------------------------
//檢測LCD是否工作繁忙
void chk_busy()
{ 
   busy=1;                      //先置位繁忙標(biāo)志位
   TRISD=0XFF;                  //更改通信為輸入
   rs=0;                        //設(shè)置該字節(jié)數(shù)據(jù)為命令代碼
   rw=1;                        //設(shè)置此次操作為讀
   while(busy)                 
      {
         nop();
         nop();
         nop();
         e=1;                   //使能
         nop();
         nop();
         nop();
         if(!RD7) busy=0;       //檢測LCD是否工作繁忙
         nop();
         nop();
         nop();
         e=0;                   //禁止
      }
   e=0;                         //禁止
   TRISD=0X00;                  //恢復(fù)通信為輸出
 }

//-------------------------------------------
//延時函數(shù)
void delay()
{
    int i;
    for(i=0;i<5000;i++)
       {;}
}

//-------------------------------------------
//延時函數(shù)1
void delay1()
{
    int i;
    for(i=0;i<10;i++)
      {
        delay();               //調(diào)用延時函數(shù)
      }
}