中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > PIC16F91x系列單片機驅(qū)動1602液晶屏程序

        PIC16F91x系列單片機驅(qū)動1602液晶屏程序

        作者: 時間:2016-11-29 來源:網(wǎng)絡(luò) 收藏
        IO口需要如下這樣配置,不用段式LCD功能,也必須配置COMCON0和LCDCON,
        /*-----------1602端口初始化-------------*/
        void Port_1602_Init(void)
        {
        PORTA=0x00;
        CMCON0=0xff;
        ANSEL = 0x00;
        TRISA=0X00;
        PORTC=0x00;
        TRISC=0x00;
        LCDCON=0x00;
        }
        完整程序如下:
        main.c如下:
        #include
        #include "Display.h"
        #include "main.h"
        #define uchar unsigned char
        #define uint unsigned int
        __CONFIG(WDTDIS & HS & PWRTDIS & BORDIS);//設(shè)置配置位
        /************************定義顯示字符*****************************************/
        uchar Wel[] = {"Welcome To"};
        uchar tab[] = {"Bei Jing"};
        /*******************************************************************************
        * 函 數(shù) 名: Delay_US(uint8 delay)
        * 函數(shù)功能: 微秒延時--12us
        * 入口參數(shù): delay
        * 返 回: 無
        *******************************************************************************/
        void Delay_US(uint delay)
        {
        for(;delay;)
        {
        delay--;
        }
        }
        /*******************************************************************************
        * 函 數(shù) 名: Delay_MS(uint16 delay)
        * 函數(shù)功能: 毫秒延時--1ms
        * 入口參數(shù): delay
        * 返 回: 無
        *******************************************************************************/
        void Delay_Ms(uint delay)
        {
        uint i;
        for(i=0;i
        Delay_US(83);
        }
        /*******************************************************************************
        * 函 數(shù) 名: Delay_Sec(uint16 delay)
        * 函數(shù)功能: 毫秒延時--1ms
        * 入口參數(shù): delay
        * 返 回: 無
        *******************************************************************************/
        void Delay_Sec(uint delay)
        {
        uint i,j;
        for(i=0;i<20*delay;i++)
        {
        for(j=0;j<4536;j++);
        }
        }
        /******************************************************************************
        * 函 數(shù) 名: main()
        * 函數(shù)功能: LCD顯示字符
        * 入口參數(shù): 無
        * 返 回: 無
        *******************************************************************************/
        void main()
        {
        Port_1602_Init();
        INIT_1602();
        Display_1602_string(3,0,10,Wel);
        Display_1602_string(4,1,8,tab);
        while(1)
        {
        }
        }
        main.h如下:
        #ifndef __MAIN_H__
        #define __MAIN_H__
        #define uchar unsigned char
        #define uint unsigned int
        #define LCD_RS RA0
        #define LCD_RW RA1
        #define LCD_EN RA2
        void Delay_US(uint delay); //12微秒延時
        void Delay_Ms(uint delay); //1毫秒延時
        void Delay_Sec(uint delay); //1秒延時
        #endif
        Display.c如下:
        #include
        #include "Display.h"
        #include "main.h"
        /*******************************************************************************
        * 函 數(shù) 名: uchar Chk_1602_busy(void)
        * 函數(shù)功能: 讀液晶忙通道數(shù)據(jù)
        * 入口參數(shù): 無
        * 返 回: 無
        *******************************************************************************/
        uchar Chk_1602_busy(void)
        {
        uint gR_data;
        uint gwait_time=0xff; //設(shè)置忙超時數(shù)
        LCD_RS=0; //表示狀態(tài)
        LCD_RW=1; //選擇讀
        LCD_EN=1;
        TRISC = 0xFF; //接收口設(shè)為輸入口
        Delay_US(30);
        gR_data=PORTC;
        while(TESTBIT(gR_data,7)) //表示busy
        {
        --gwait_time;
        if(!gwait_time)
        { LCD_EN=0;TRISC = 0x00; return 0; }
        }
        LCD_EN=0;
        TRISC = 0x00; //恢復(fù)為輸出口
        return 1;
        }
        /******************************************************************************
        * 函 數(shù) 名: void Write_1602_command(uchar gcmd,uchar gvalue)
        * 函數(shù)功能: 寫指令
        * 入口參數(shù): gcmd--指令 gvalue--是否查忙
        * 返 回: 無
        *******************************************************************************/
        void Write_1602_command(uchar gcmd,uchar gvalue)
        {
        if(gvalue) //寫命令時大部分情況下是在LCD空閑模式下寫
        {
        if(Chk_1602_busy())
        {
        LCD_RS=0; //選擇指令
        LCD_RW=0; //選擇寫
        PORTC=gcmd; //賦指令
        LCD_EN=1; //使能
        Delay_US(30);
        LCD_EN=0;
        }
        }
        else
        {
        LCD_RS=0; //選擇指令
        LCD_RW=0; //選擇寫
        PORTC=gcmd; //賦指令
        LCD_EN=1; //使能
        Delay_US(30);
        LCD_EN=0;
        }
        }

        上一頁 1 2 下一頁

        評論


        技術(shù)專區(qū)

        關(guān)閉