日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 單片機 > 單片機
[導讀] //編譯器:ICC-AVRv6.31A//目標芯片:M16//時鐘:8.0000MHz/*-------------------------------------------------------------LCD引腳定義1---GND2---VCC3---VO4---RS5---RW6---EN7到14--D0-D715--背景燈

//編譯器:ICC-AVRv6.31A
//目標芯片:M16
//時鐘:8.0000MHz
/*-------------------------------------------------------------

LCD引腳定義
1---GND
2---VCC
3---VO
4---RS
5---RW
6---EN
7到14--D0-D7
15--背景燈+
16--背景燈-
-----------------------------------------------------------------*/
#include
#include

/*---------------------------------------------------------------
下面是AVR與LCD連接信息
PA2->RS
PA3->EN
地->RW
PA4->D4
PA5->D5
PA6->D6
PA7->D7
要使用本驅動,改變下面配置信息即可
-----------------------------------------------------------------*/
#defineLCD_EN_PORTPORTA//以下2個要設為同一個口
#defineLCD_EN_DDRDDRA
#defineLCD_RS_PORTPORTA//以下2個要設為同一個口
#defineLCD_RS_DDRDDRA
#defineLCD_DATA_PORTPORTA//以下3個要設為同一個口
#defineLCD_DATA_DDRDDRA//一定要用高4位
#defineLCD_DATA_PINPINA
#defineLCD_RS(1<函數(shù)說明
------------------------------------------------------------------------------*/
voidLCD_init(void);
voidLCD_en_write(void);
voidLCD_write_command(unsignedcharcommand);
voidLCD_write_data(unsignedchardata);
voidLCD_set_xy(unsignedcharx,unsignedchary);
voidLCD_write_string(unsignedcharX,unsignedcharY,unsignedchar*s);
voidLCD_write_char(unsignedcharX,unsignedcharY,unsignedchardata);
voiddelay_nus(unsignedintn);
voiddelay_nms(unsignedintn);
==============================================================================

#include"LCD.h"

voidLCD_init(void)//液晶初始化
{
LCD_DATA_DDR|=LCD_DATA;//數(shù)據(jù)口方向為輸出
LCD_EN_DDR|=LCD_EN;//設置EN方向為輸出
LCD_RS_DDR|=LCD_RS;//設置RS方向為輸出
LCD_write_command(0x28);
LCD_en_write();
delay_nus(40);
LCD_write_command(0x28);//4位顯示
LCD_write_command(0x0c);//顯示開
LCD_write_command(0x01);//清屏
delay_nms(2);
}

voidLCD_en_write(void)//液晶使能
{
LCD_EN_PORT|=LCD_EN;
delay_nus(1);
LCD_EN_PORT&=~LCD_EN;
}

voidLCD_write_command(unsignedcharcommand)//寫指令
{
delay_nus(16);
LCD_RS_PORT&=~LCD_RS;//RS=0
LCD_DATA_PORT&=0X0f;//清高四位
LCD_DATA_PORT|=command&0xf0;//寫高四位
LCD_en_write();
command=command<<4;//低四位移到高四位
LCD_DATA_PORT&=0x0f;//清高四位
LCD_DATA_PORT|=command&0xf0;//寫低四位
LCD_en_write();

}

voidLCD_write_data(unsignedchardata)//寫數(shù)據(jù)
{
delay_nus(16);
LCD_RS_PORT|=LCD_RS;//RS=1
LCD_DATA_PORT&=0X0f;//清高四位
LCD_DATA_PORT|=data&0xf0;//寫高四位
LCD_en_write();
data=data<<4;//低四位移到高四位
LCD_DATA_PORT&=0X0f;//清高四位
LCD_DATA_PORT|=data&0xf0;//寫低四位
LCD_en_write();
}


voidLCD_set_xy(unsignedcharx,unsignedchary)//寫地址函數(shù)
{
unsignedcharaddress;
if(y==0)address=0x80+x;
elseaddress=0xc0+x;
LCD_write_command(address);
}

voidLCD_write_string(unsignedcharX,unsignedcharY,unsignedchar*s)//列x=0~15,行y=0,1
{
LCD_set_xy(X,Y);//寫地址
while(*s)//寫顯示字符
{
LCD_write_data(*s);
s++;
}

}

voidLCD_write_char(unsignedcharX,unsignedcharY,unsignedchardata)//列x=0~15,行y=0,1
{
LCD_set_xy(X,Y);//寫地址
LCD_write_data(data);

}
=======================================================================

voiddelay_1us(void)//1us延時函數(shù)
{
asm("nop");
}

voiddelay_nus(unsignedintn)//Nus延時函數(shù)
{
unsignedinti=0;
for(i=0;i}

voiddelay_1ms(void)//1ms延時函數(shù)
{
unsignedinti;
for(i=0;i<1140;i++);
}

voiddelay_nms(unsignedintn)//Nms延時函數(shù)
{
unsignedinti=0;
for(i=0;i}

=========================================================================
#include"LCD.h"


voidinit_devICes(void)
{
CLI();//dISAbleallinterrupts
LCD_init();
MCUCR=0x00;
GICR=0x00;
TIMSK=0x00;//timerinterruptsources
SEI();//re-enableinterrupts
}

voidmain(void)
{
init_devices();
LCD_write_string(1,0,"Hi!!");
for(;;)
{
LCD_write_string(0,1,"archeng504");
LCD_write_char(6,0,'8');
}

}


補充:一個自定義圖案的程序。
1602中還可以自定義8個字符圖案
圖案規(guī)格5*8
下面是一個向上的箭頭↑
000|00100//0x04
|
000|01110//0x0e
|
000|10101//0x15
|
000|00100//0x04
|
000|00100//0x04
|
000|00100//0x04
|
000|00100//0x04
|
000|00000//0x00

unsignedchardata[8]={0x04,0x0e,0x15,0x04,0x04,0x04,0x04,0x00};//↑
unsignedchardata1[8]={0x04,0x04,0x04,0x04,0x15,0x0e,0x04,0x00};//↓

voidmy_signs(unsignedcharascii,unsignedchar*z)//0x00
{
unsignedcharaddress=0,i,temp=0;//ascii為與要定義的圖案對應的ascii碼值(0x00到
temp=(ascii&0x07)<<3;//0x007間任選)
for(i=0;i<8;i++)
{
address=0x40+temp+i;
LCD_write_command(address);
delay_nus(1);
LCD_write_data(*(z++));
delay_nus(1);
}
}

//建立圖案
voidLCD_init(void)//液晶初始化
{
LCD_DATA_DDR|=LCD_DATA;//數(shù)據(jù)為輸出
LCD_EN_DDR|=LCD_EN;//設置RS.EN方向
LCD_RS_DDR|=LCD_RS;
LCD_write_command(0x28);//4位顯示
LCD_en_write();
delay_nms(15);
LCD_write_command(0x28);//4位顯示
LCD_write_command(0x0c);//顯示開
my_signs(0x00,data);//↑//建立圖案
my_signs(0x01,data1);//↓
LCD_write_command(0x01);//清屏
}

顯示自定義圖案
LCD_write_char(9,0,0x00);//↑
LCD_write_char(9,0,0x01);//↓

本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關閉