430g2553与1602的四位传输

#include "msp430g2553.h"
#include
#define uint unsigned int
#define uchar unsigned char
#define delay_nm() _delay_cycles(10000);//延迟1s
uchar table[]={"hell0"};//输入你想要显示的字符
uchar data;
//void _delay_1us(void);
//void _delay_nus(uint n);
//void _delay_ms(void);
//void _delay_nms(uint n);
//uint busy_1602(void);
void write_com(uchar com);
void write_data(uchar dat);
void LCD_set_xy( uchar x, uint y );
void LCD_write_string(uchar X,uchar Y,uchar s);
void init();//初始化函数
//void LCD_display();
/*LCD数据
///P2.3e P2.4 RW P2.5RS
//p1.4---p1.7接数据位
void main()
{
WDTCTL=WDTPW+WDTHOLD;//关看门狗

DCOCTL=0;
BCSCTL1=CALBC1_1MHZ;
DCOCTL=CALDCO_1MHZ;
BCSCTL2|=SELM_1;//MCLK选择DCOCLK
BCSCTL2|=0X00;//SMCLK选择DCOLCK
P1SEL&=0x00;
P2SEL&=0x00;
P1DIR|=0xff;//选择P1为输出端
P2DIR|=0xff;//P2为输出端
init();
delay_nm();
LCD_write_string(0,0,table);
delay_nm();
while(1);

}

void _delay_1us(void)
{
asm("nop");
}
void _delay_nus(uint n)
{
int i;
for(i=0;i<n;i++)
_delay_1us();
}

void _delay_ms(void)
{
int i;
for(i=0;i<1000;i++);
}
void _delay_nms(uint n)
{
int i;
for(i=0;i<n;i++)
_delay_ms();
}
uint busy_1602(void) //查询忙碌标志信号程序
{
uint busy;
P2OUT&= ~BIT3;
P2OUT&= ~BIT5;
P2OUT|= BIT4;
P2OUT|= BIT3;
busy=P1OUT&0x80;
delay_nm();
P2OUT&= ~BIT3;
return (busy);
}
/*LCD数据*///P2.3e P2.4 RW P2.5RS
void write_com(uchar com)
{
uchar high,low;
high=com&(0xf0);
low =(com<<4)&(0xf0);
//写入高4位
delay_nm();
P2OUT&= ~(BIT5+BIT4);//写指令的时候RS给低
P2OUT|= BIT3;

P1OUT&=~0x0f;
P1OUT=high;//写入高四位
delay_nm();
P2OUT&= ~BIT3;
delay_nm();
P1OUT|=BIT0;

// //写入低4位
P2OUT&= ~(BIT5+BIT4);
P2OUT|= BIT3;
P1OUT&=~0x0f;
P1OUT=low;//写入低四位
delay_nm();
P2OUT&= ~BIT3;
delay_nm();
}
/*LCD数据*///P2.3e P2.4 RW P2.5RS
void write_data(uchar dat)
{
uchar gao,di;
delay_nm();
gao=dat&(0xf0);
di =(dat<<4)&(0xf0);

P2OUT|=BIT5;//写数据的时候RS给高
P2OUT&= ~(BIT3+BIT4);
P2OUT|=BIT3;
P1OUT&=~0x0f;
P1OUT|=gao;//写入高四位
delay_nm();
P2OUT&=~BIT3;
delay_nm();

P2OUT|=BIT5;//写数据的时候RS给高
P2OUT&= ~(BIT3+BIT4);
delay_nm();
P2OUT|=BIT3;
P1OUT&=~0x0f;
P1OUT|=di;//写入第四位
delay_nm();
P2OUT&=~BIT3;
delay_nm();

}
void LCD_set_xy( uchar x, uint y )
{
unsigned char address;
if (y == 0) address = 0x80 + x;
else address = 0xc0 + x;
write_com( address);
}
/*****************************************
*
LCD在任意位置写字符串,列x=0~15,行y=0,1
*
*
**************************************/
void LCD_write_string(uchar X,uchar Y,uchar *s)
{
LCD_set_xy( X, Y ); //写地址
while (*s) //写显示字符
{
write_data( *s );
delay_nm();
s++;

}

}
//P2.3e P2.4 RW P2.5RS
void init()//初始化函数
{
P2OUT&= ~(BIT4+BIT5+BIT3);
P2OUT|=BIT3;
delay_nm();
write_com(0x28); //设置显示,点阵,数据接口等
delay_nm();
write_com(0x28);
delay_nm();
write_com(0x28);
delay_nm();
write_com(0x28);
delay_nm();
write_com(0x01); //数据指针、显示清零
delay_nm();
write_com(0x0f); //开显示,不显示光标,光标不闪烁
delay_nm();
write_com(0x06); //指针自动加一
delay_nm();
write_com(0x08); //从第一格开始显示
}
/*LCD指令*///P2.3e P2.4 RW P2.5RS
//p1.4----p1.7接LCD屏的高4位

void LCD_display()
{
int i;
for(i=0;i<5;i++)//X代表字符的个数
{
write_data(table[i]);
delay_nm();
}
}

1个回答

#define delay_nm() _delay_cycles(10000);//延迟1s
uchar table[]={"hell0"};//输入你想要显示的字符
uchar data;
//void _delay_1us(void);
//void _delay_nus(uint n);
//void _delay_ms(void);
//void _delay_nms(uint n);
//uint busy_1602(void);
void write_com(uchar com);
void write_data(uchar dat);
void LCD_set_xy( uchar x, uint y );
void LCD_write_string(uchar X,uchar Y,uchar s);
void init();//初始化函数
//void LCD_display();
/*LCD数据///P2.3e P2.4 RW P2.5RS
//p1.4---p1.7接数据位
void main()
{
WDTCTL=WDTPW+WDTHOLD;//关看门狗
DCOCTL=0;
BCSCTL1=CALBC1_1MHZ;
DCOCTL=CALDCO_1MHZ;
BCSCTL2|=SELM_1;//MCLK选择DCOCLK
BCSCTL2|=0X00;//SMCLK选择DCOLCK
P1SEL&=0x00;
P2SEL&=0x00;
P1DIR|=0xff;//选择P1为输出端
P2DIR|=0xff;//P2为输出端
init();
delay_nm();
LCD_write_string(0,0,table);
delay_nm();
while(1);
}
void _delay_1us(void)
{
asm("nop");
}
void _delay_nus(uint n)
{
int i;
for(i=0;i<n;i++)
_delay_1us();
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问