#include<msp430g2553.H>
#include<intrinsics.h>
#define uchar unsigned char
#define uint unsigned int
#define RS_1 P2OUT |= 0X01
#define RS_0 P2OUT &= ~0X01
#define RW_1 P2OUT |= 0X02
#define RW_0 P2OUT &= ~0X02
#define E_1 P2OUT |= 0X04
#define E_0 P2OUT &= ~0X04
#define data_port P1OUT
#define com_port P1OUT
//延时程序 ms//
void delay_ms(uchar n)
{
uint i,j;
for(i=n;i>0;i++)
for(j=1140;j>0;j--);
}
//写地址//
void write_com(uchar com)
{
RS_0;
RW_0;
P1OUT |= com;
E_1;
delay_ms(10);
E_0;
}
//读数据//
void write_data(uchar data)
{
RS_1;
RW_0;
P1OUT |= data;
E_1;
delay_ms(10);
E_0;
}
//初始化//
void init()
{
RW_1;
delay_ms(5);
write_com(0x28);
delay_ms(1);
write_com(0x0c);
delay_ms(1);
write_com(0x06);
delay_ms(1);
write_com(0x01);
}
//主程序//
void main(void)
{
uint m=1;
WDTCTL=WDTPW+WDTHOLD;
BCSCTL1=CALBC1_1MHZ;
DCOCTL=CALDCO_1MHZ;
BCSCTL2=SELM_1+DIVM_0;
P1SEL &= 0X00;
P2SEL &= 0X00;
P1DIR = 0XFF;
P2DIR = 0XFF;
P1OUT &= 0X00;
P2OUT &= 0X00;
init();
while(1)
{
write_com(0x80+0x01);
delay_ms(1);
write_data(m);
delay_ms(200);
}
}
此帖出自
小平头技术问答
一周热门 更多>