下面是参考别人资料写的一个程序,烧进去后,液晶没任何反映. 用的是12232-9液晶,跪求高手指点,小弟不胜感激 //===========================================================================// //mcumsp430f449//
//p20rs// //p21r/w// //p22e// //p30-p37db// //===========================================================================// #include "msp430x44x.h" /*************************/
unsigned char busy,hang,lie;
/********************************/ //定义字符串数组*/ /********************************/ char STR2[]="http://www.qfmcu.com"; char STR3[]="http://www.mcubbs.net";
/**************************定义函数原型********************************/ void Delayus(unsigned long n);/*延时函数*/ void BUSYLOOP();//*判忙函数*// void Write_command(unsigned char CMD);//*发控制字函数*// void Write_data(unsigned char dat);//*发数据函数*// void CHUSHIHUA();//*初始化函数*// void CLEAR();//*清屏*// void Display(unsigned char *ptr,unsigned char ddram);//**显字符串函数**//
/*********************************************延时 **************************************/
void Delayus(unsigned long n) {unsigned long i,j; for(i=0;i<n;i++) for(j=0;j<9;j++); } //*********************判忙函数************************// void BUSYLOOP() { P2DIR=0xff; P2OUT&=~0x01; P2OUT|=0x02; P3DIR=0X00; P2OUT|=0x04; while((P3IN&0x80)==0x80); P2OUT&=~0x04; P3DIR=0Xff; } //*********************写控制字函数****************************// void Write_command(unsigned char CMD) {
BUSYLOOP(); _NOP(); P2DIR=0xff; P3DIR=0xff; P2OUT&=~0x01; P2OUT&=~0x02; P2OUT|=0x04; P3OUT=CMD; Delayus(10); _NOP(); P2OUT&=~0x04; _NOP(); }
//*********************写数据函数****************************// void Write_data(unsigned char dispdata) {BUSYLOOP(); //Delayus(1000); _NOP(); P2DIR=0xff; P3DIR=0xff; P2OUT|=0x01; P2OUT&=~0x02; P2OUT|=0x04; P3OUT=dispdata; Delayus(5); _NOP(); P2OUT&=~0x04; _NOP(); }
/***************************清屏*************************************/ void CLEAR() { P2OUT&=~0x01;//RS=0; P2OUT&=~0x02;//RW=0; P2OUT|=0x04;//E=1; P3OUT=0x01; Delayus(10); P2OUT&=~0x04;//E=0; }
//*************************液晶初始化********************************// void CHUSHIHUA() { Delayus(40000); Write_command(0x30); Delayus(1500); Write_command(0x30); Delayus(400); Write_command(0x0C); Delayus(1500); Write_command(0x01); Delayus(15000); Write_command(0x06); }
/*======================================================= 显示字符串 =======================================================*/ void Display(unsigned char *ptr,unsigned char ddram) { int i1,x; i1=0; if(ddram<0x88) {hang=0;}//定位行地址:第一行 else if(ddram<0x90) {hang=2;}//定位行地址:第三行 else if(ddram<0x98) {hang=1;}//定位行地址:第二行 else {hang=3;}//定位行地址:第四行
lie=0x0f&ddram;//定位列地址 if(lie>0x07) {lie=lie-0x08;} x=lie*2; Write_command(ddram);//定位显示起始地址 while((ptr[i1])!='\0') { Write_data(ptr[i1]);//输出单个字符 i1++; x++; if(x==0x10) {x=0; hang++; } switch(hang) { case 0:Write_command(0x80); break; case 1:Write_command(0x90); break; case 2:Write_command(0x88); break; case 3:Write_command(0x98); } if(hang>3) { Write_command(0x80); hang=0; } }
}
/**************************主函数开始***********************************/ main() {WDTCTL=WDTPW+WDTHOLD;//停止看门狗
P3DIR=0xff; P3OUT=0x00; P4DIR=0x0f; P4OUT=0x00; //////////////////////////////// CLEAR(); CHUSHIHUA();//初始化函数// Display((unsigned char *)STR2,0x80);//上面一行显示一个预定字符串 Display((unsigned char *)STR3,0x88); Delayus(200); Write_command(0x9C);//将光标移到0x9C Write_command(0x0f);//光标处反白闪烁
//write_command(0x08,0);//进入睡眠状态 //delayus(200); //write_command(0x0C,0);//唤醒
while(1) {;} } /*************************主函数结束*************************************/
请高手指点下看哪有问题? 单片机为msp430f449
|