在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            IAR For AVR -- LCD1602

            作者: 時間:2016-12-03 來源:網(wǎng)絡(luò) 收藏
            LCD1602的端口大多一樣,這里不多說,可以找找 長沙太陽人的datasheet。

            下面是程序,定義在程序里很明顯,要注意的是背光是用三極管控制的,但是效果不是很好,反而不如直接接。

            本文引用地址:http://www.biyoush.com/article/201612/325119.htm

            源代碼包括三個文件:LCD1602.C , main.c ,delay.h

            /+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/

            LCD1602.C

            /+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/

            #include
            #include "delay.h"

            /*設(shè)置管腳*/
            #define RS PORTD_Bit3
            #define RW PORTD_Bit4
            #define E PORTD_Bit6

            /*LCD1602控制指令*/
            #define LCD_Set 0x38 // 顯示初始化,16*2顯示,5*7點陣,8位數(shù)據(jù)接口 ;
            #define LCD_Clear 0x01 // 清屏LCD ;
            #define LCD_Display1 0x0f // 顯示功能設(shè)置:開顯示,顯示光標,光標閃爍 ;
            #define LCD_Display2 0x0c // 顯示功能設(shè)置:開顯示,不顯示光標,光標不閃爍 ;
            #define LCD_Mode 0x06 // 設(shè)置光標狀態(tài)默認0x06,為讀一個字符光標加1 ;

            #define LCD_FirstLineAddress_Left 0x80 //設(shè)置初始化數(shù)據(jù)指針,指向 左半屏第一行首位 ;
            #define LCD_SecondLineAddress_Left (0x80+0x40) //設(shè)置初始化數(shù)據(jù)指針,指向 左半屏第二行首位 ;

            #define LCD_FirstLineAddress_Right (0x80+0x10) //設(shè)置初始化數(shù)據(jù)指針,指向 右半屏第一行首位 ;
            #define LCD_SecondLineAddress_Right (0x80+0x40+0x10) //設(shè)置初始化數(shù)據(jù)指針,指向 右半屏第二行首位 ;

            #define LCD_Move_Left 0x18 // 整屏左移
            #define LCD_Move_Right 0x1c // 整屏右移

            /*端口初始化*/
            void Port_Init()
            {
            DDRD_Bit3 = 1; //控制端 RS 定義為輸出
            DDRD_Bit4 = 1; //控制端 RW 定義為輸出
            DDRD_Bit6 = 1; //控制端 E 定義為輸出

            DDRB = 0xFF; //數(shù)據(jù)端定義為輸出

            DDRC_Bit7 = 1; //背光控制端
            PORTC_Bit7 =0; //由三級管控制,低電平導通; 始終打開背光
            }

            /*液晶1602 寫控制指令函數(shù)*/
            void Write_Command(unsigned char Command)
            {
            RS = 0 ; // 進行指令的操作
            RW = 0 ; // 進行寫操作
            PORTB = Command ; // 賦值指令
            E = 1 ; // 使能端拉高
            delay_ms(5); // 等待指令寫完
            E = 0 ; // 使能端拉低
            }

            /*液晶1602 寫數(shù)據(jù)函數(shù)*/
            void Write_Data(unsigned char Data)
            {
            RS = 1 ; // 進行數(shù)據(jù)的操作
            RW = 0 ; // 進行寫操作
            PORTB = Data ; // 賦值數(shù)據(jù)
            E = 1 ; // 使能端拉高
            delay_ms(5); // 等待數(shù)據(jù)寫完
            E = 0 ; // 使能端拉低
            }

            /*液晶1602 使用初始化*/
            void LCD1602_Init()
            {
            E = 0;
            Write_Command(LCD_Set);
            Write_Command(LCD_Clear);
            Write_Command(LCD_Display2);
            Write_Command(LCD_Mode);
            }

            /*液晶1602 清屏*/
            void LCD1602_Clear(void)
            {
            Write_Command(LCD_Clear);
            }

            /*液晶1602 左半屏顯示*/
            void LCD1602_Left_Display(unsigned char *table1 , unsigned char *table2)
            {
            unsigned char i;

            Write_Command(LCD_FirstLineAddress_Left);delay_ms(1); //第一行顯示16個字符
            for(i=0;i<16;i++)
            {
            Write_Data(table1[i]);
            delay_ms(50);
            }

            Write_Command(LCD_SecondLineAddress_Left);delay_ms(1); //第二行顯示16個字符
            for(i=0;i<16;i++)
            {
            Write_Data(table2[i]);
            delay_ms(1);
            }
            }

            /*液晶1602 右半屏顯示*/
            void LCD1602_Right_Display(unsigned char *table1 , unsigned char *table2)
            {
            unsigned char i;

            Write_Command(LCD_FirstLineAddress_Right); //第一行顯示16個字符delay_ms(1);
            for(i=0;i<16;i++)
            {
            Write_Data(table1[i]);
            delay_ms(50);
            }

            Write_Command(LCD_SecondLineAddress_Right); //第二行顯示16個字符delay_ms(1);
            for(i=0;i<16;i++)
            {
            Write_Data(table2[i]);
            delay_ms(1);
            }
            }

            /*液晶1602 左移*/
            void LCD1602_TurnLeft()
            {
            unsigned char i;
            for(i=0;i<16;i++)
            {
            Write_Command(LCD_Move_Left);
            delay_ms(100);
            }
            }

            /*液晶1602 右移*/
            void LCD1602_TurnRight()
            {
            unsigned char i;
            for(i=0;i<16;i++)
            {
            Write_Command(LCD_Move_Right);
            delay_ms(100);
            }
            }

            /+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/

            main.c

            /+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/

            #include
            #include "delay.h"

            unsigned char dou1[]=" I LIKE AVR ! ";
            unsigned char dou2[]="Douzi&Douer AVR!";

            unsigned char dou3[]=" AVR to ARM ! ";
            unsigned char dou4[]=" I Will Win ! ";

            /*調(diào)用函數(shù)聲明*/
            void Port_Init();
            void LCD1602_Init();
            void LCD1602_Clear(void);
            void LCD1602_Left_Display(unsigned char *table1 , unsigned char *table2);
            void LCD1602_Right_Display(unsigned char *table1 , unsigned char *table2);
            void LCD1602_TurnLeft();
            void LCD1602_TurnRight();

            /*主函數(shù)*/

            void main(void)
            {
            Port_Init();
            LCD1602_Init();
            while(1)
            {
            LCD1602_Left_Display(dou1,dou2);
            LCD1602_Right_Display(dou3,dou4);
            LCD1602_TurnLeft();
            delay_s(2);
            LCD1602_TurnRight();
            delay_s(2);
            }
            }

            /+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/

            delay.h

            /+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/

            #ifndef __IAR_DELAY_H
            #define __IAR_DELAY_H

            #include

            #define XTAL 7.3728 //可定義為你所用的晶振頻率(單位Mhz)


            #define delay_us(x) __delay_cycles ( (unsigned long)(x * XTAL) )
            #define delay_ms(x) __delay_cycles ( (unsigned long)(x * XTAL*1000) )
            #define delay_s(x) __delay_cycles ( (unsigned long)(x * XTAL*1000000) )

            #endif



            關(guān)鍵詞: IARAVRLCD160

            評論


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

            關(guān)閉