整理lcd1602Word格式.docx

上传人:b****3 文档编号:6450504 上传时间:2023-05-06 格式:DOCX 页数:32 大小:21.60KB
下载 相关 举报
整理lcd1602Word格式.docx_第1页
第1页 / 共32页
整理lcd1602Word格式.docx_第2页
第2页 / 共32页
整理lcd1602Word格式.docx_第3页
第3页 / 共32页
整理lcd1602Word格式.docx_第4页
第4页 / 共32页
整理lcd1602Word格式.docx_第5页
第5页 / 共32页
整理lcd1602Word格式.docx_第6页
第6页 / 共32页
整理lcd1602Word格式.docx_第7页
第7页 / 共32页
整理lcd1602Word格式.docx_第8页
第8页 / 共32页
整理lcd1602Word格式.docx_第9页
第9页 / 共32页
整理lcd1602Word格式.docx_第10页
第10页 / 共32页
整理lcd1602Word格式.docx_第11页
第11页 / 共32页
整理lcd1602Word格式.docx_第12页
第12页 / 共32页
整理lcd1602Word格式.docx_第13页
第13页 / 共32页
整理lcd1602Word格式.docx_第14页
第14页 / 共32页
整理lcd1602Word格式.docx_第15页
第15页 / 共32页
整理lcd1602Word格式.docx_第16页
第16页 / 共32页
整理lcd1602Word格式.docx_第17页
第17页 / 共32页
整理lcd1602Word格式.docx_第18页
第18页 / 共32页
整理lcd1602Word格式.docx_第19页
第19页 / 共32页
整理lcd1602Word格式.docx_第20页
第20页 / 共32页
亲,该文档总共32页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

整理lcd1602Word格式.docx

《整理lcd1602Word格式.docx》由会员分享,可在线阅读,更多相关《整理lcd1602Word格式.docx(32页珍藏版)》请在冰点文库上搜索。

整理lcd1602Word格式.docx

D2不接

*PIN10-->

D3不接

*PIN11-->

D4-->

P2.4

*PIN12-->

D5-->

P2.5

*PIN13-->

D6-->

P2.6

*PIN14-->

D7-->

P2.7

*PIN15-->

VCC

*PIN16-->

*调试器:

MSP430FET全系列JTAG仿真器

*调试软件:

CCS5.1.1编译

*****************************************************************/

#include<

intrinsics.h>

msp430g2253.h>

msp430.h>

/*****************************************************

端口定义

****************************************************/

#defineLCD_EN_PORTP1OUT//以下2个要设为同一个口

#defineLCD_EN_DDRP1DIR

#defineLCD_RS_PORTP1OUT//以下2个要设为同一个口

#defineLCD_RS_DDRP1DIR

#defineLCD_DATA_PORTP2OUT//以下3个要设为同一个口

#defineLCD_DATA_DDRP2DIR//一定要用高4位

#defineLCD_RSBIT6

#defineLCD_ENBIT7

#defineLCD_DATABIT7|BIT6|BIT5|BIT4//4位数据线连接模式

/***************************************************

预定义函数

**************************************************/

voidLCD_init(void);

voidLCD_init_first(void);

voidLCD_en_write1(void);

//上升沿使能

voidLCD_en_write2(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_1ms(void);

voiddelay_nus(unsignedintn);

voiddelay_nms(unsignedintn);

unsignedcharLCDBuf1[]={"

Hello!

LCD1602"

};

//第一行要显示的内容

unsignedcharLCDBuf2[]={"

MSP430G2553"

//第二行要显示的内容

/********************************************

主函数

*******************************************/

voidmain()

{

WDTCTL=WDTPW+WDTHOLD;

//关闭看门狗

LCD_init_first();

LCD_init();

delay_nms(100);

LCD_write_string(0,0,LCDBuf1);

delay_nms(10);

LCD_write_string(0,1,LCDBuf2);

}

LCD液晶操作函数

voidLCD_init_first(void)//LCD1602液晶初始化函数(热启动)

delay_nms(500);

LCD_DATA_DDR|=LCD_DATA;

//数据口方向为输出

LCD_EN_DDR|=LCD_EN;

//设置EN方向为输出

LCD_RS_DDR|=LCD_RS;

//设置RS方向为输出

delay_nms(50);

LCD_write_command(0x30);

delay_nms(5);

/*****************************************

*

*LCD1602液晶初始化函数

****************************************/

voidLCD_init(void)

LCD_write_command(0x28);

//4位数据接口

LCD_en_write2();

LCD_write_command(0x01);

//清屏

LCD_write_command(0x0c);

//显示开,关光标,不闪烁

LCD_write_command(0x06);

//设定输入方式,增量不移位

*液晶使能上升沿

voidLCD_en_write1(void)

LCD_EN_PORT&

=~LCD_EN;

delay_nus(10);

LCD_EN_PORT|=LCD_EN;

*液晶使能下降沿

voidLCD_en_write2(void)

*写指令函数

voidLCD_write_command(unsignedcharcommand)

delay_nus(16);

P2SEL=0x00;

LCD_RS_PORT&

=~LCD_RS;

//RS=0

LCD_en_write1();

LCD_DATA_PORT&

=0X0f;

//清高四位

LCD_DATA_PORT|=command&

0xf0;

//写高四位

command=command<

<

4;

//低四位移到高四位

=0x0f;

//写低四位

*写数据函数

voidLCD_write_data(unsignedchardata)

LCD_RS_PORT|=LCD_RS;

//RS=1

//E上升沿

LCD_DATA_PORT|=data&

data=data<

*写地址函数

voidLCD_set_xy(unsignedcharx,unsignedchary)

unsignedcharaddress;

if(y==0)address=0x80+x;

elseaddress=0xc0+x;

LCD_write_command(address);

*LCD在任意位置写字符串,列x=0~15,行y=0,1

voidLCD_write_string(unsignedcharX,unsignedcharY,unsignedchar*s)

LCD_set_xy(X,Y);

//写地址

while(*s)//写显示字符

{

LCD_write_data(*s);

s++;

}

*LCD在任意位置写字符,列x=0~15,行y=0,1

voidLCD_write_char(unsignedcharX,unsignedcharY,unsignedchardata)

LCD_write_data(data);

*1us延时函数

voiddelay_1us(void)

asm("

nop"

);

*Nus延时函数

voiddelay_nus(unsignedintn)

unsignedinti;

for(i=0;

i<

n;

i++)

delay_1us();

*1ms延时函数

voiddelay_1ms(void)

1140;

i++);

*Nms延时函数

voiddelay_nms(unsignedintn)

unsignedinti=0;

delay_1ms();

msp430g2553制作的简易电子钟

芯片用的是g2553,LCD1602显示,整分的时候显示温度。

直接放代码了哈。

/******************************************************************

FileName:

Launchpadg2553LCD1602液晶测试程序

Frequency:

1.000000MHz

Time:

2011/08/1318:

16

ModifyTime:

2012/04/29

Author:

Fuwei

******************************************************************/

#include"

msp430g2553.h"

#defineucharunsignedchar

#defineuintunsignedint

externvoidInitialize_LCD();

externvoidLCD_ShowString(ucharx,uchary,char*str);

externvoidLCD_ShowChar(ucharx,uchary,charc);

charhour=20,minute=6,second=0;

charhour1,hour0,minute1,minute0,second1,second0;

longtemp;

longIntDegC;

charTemp2,Temp1,Temp0;

intmain(void)

//Stopwatchdogtimertopreventtimeoutreset

WDTCTL=WDTPW+WDTHOLD;

//液晶显示端口初始化

P2DIR|=0x07;

TACTL=TASSEL_1+MC_2+TAIE;

//ACLK,contmode,interrupt

_EINT();

for(;

;

ADC10CTL1=INCH_10+ADC10SC;

//TempSensorADC10CLK

ADC10CTL0=SREF_1+ADC10SHT_3+REFON+ADC10ON;

__delay_cycles(5);

//WaitforReftosettle

ADC10CTL0|=ENC+ADC10SC;

//Sampandconvertstart

__delay_cycles(100);

//Waitforconversion

ADC10CTL0&

=~ENC;

//DisableADCconversion

=~(REFON+ADC10ON);

//RefandADC10off

//oC=((A10/1024)*1500mV)-986mV)*1/3.55mV=A10*423/1024-278

temp=ADC10MEM;

IntDegC=((temp-673)*4230)/1024;

Temp2=IntDegC%1000/100;

Temp1=IntDegC%100/10;

Temp0=IntDegC%10;

__delay_cycles(1000000);

//delay1second

//Timer_A3InterruptVector(TA0IV)handler

#pragmavector=TIMER0_A1_VECTOR

__interruptvoidTimer_A(void)

switch(TA0IV)

case2:

break;

case4:

case10:

second+=2;

if((hour>

=23)&

&

(minute>

=59)&

(second>

=59))

hour=0;

if((minute>

minute=0;

hour++;

if(second>

=59)

second=0;

minute++;

Initialize_LCD();

LCD_ShowString(0,0,"

Temperature:

"

LCD_ShowString(8,1,"

.'

C"

LCD_ShowChar(6,1,Temp2+'

0'

LCD_ShowChar(7,1,Temp1+'

LCD_ShowChar(9,1,Temp0+'

else

second1=second/10;

second0=second%10;

minute1=minute/10;

minute0=minute%10;

hour1=hour/10;

hour0=hour%10;

Time:

LCD_ShowString(4,1,"

:

:

LCD_ShowChar(2,1,hour1+'

LCD_ShowChar(3,1,hour0+'

LCD_ShowChar(5,1,minute1+'

LCD_ShowChar(6,1,minute0+'

LCD_ShowChar(8,1,second1+'

LCD_ShowChar(9,1,second0+'

}

MSP430G2553一个数码管实现按键加1功能

#include<

msp430g2553.h>

unsignedinti=0,j;

unsignedcharseg[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

voidmain(void)

P2DIR|=0xff;

P2SEL&

=~(0xC0);

P1DIR&

=~BIT3;

P1REN|=BIT3;

P1IE|=BIT3;

//设置P1.3可以中断

P1IES=BIT3;

//设置P1.3为下降沿中断

_BIS_SR(LPM0_bits+GIE);

//进入低功耗睡眠,打开总中断开关

unsignedcharp1keyj(void)//判键子程序

unsignedcharx;

x=(~P1IN&

0X08);

//P1.3接有按键

return(x);

//有按键返回非全0

#pragmavector=PORT1_VECTOR//中断服务程序:

__interruptvoidp1int(void)

if(p1keyj())

P2OUT=seg[i++];

for(j=8000;

j>

0;

j--)

if(i>

9)

i=0;

单通道AD转换并通过1602显示的程序

/**********************************************

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2